From ebede0bf968411f0ef4b31d52b5b14a5a368ea3c Mon Sep 17 00:00:00 2001
From: zhenye
Date: Wed, 18 Dec 2024 17:32:40 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E4=BA=86=E4=B8=A4=E4=B8=AA?=
=?UTF-8?q?=E7=9B=B8=E6=9C=BA=E7=9A=84=E5=B1=95=E7=A4=BA=E7=A8=8B=E5=BA=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
camera.cpp | 11 ++++++--
cotton_double2.pro.user | 2 +-
globals.cpp | 10 ++++---
globals.h | 10 ++++---
ui_widget.h | 27 ++++++++++++------
widget.cpp | 62 +++++++++++++++++++++++++++++++----------
widget.h | 2 ++
widget.ui | 37 ++++++++++++++++++++----
8 files changed, 121 insertions(+), 40 deletions(-)
diff --git a/camera.cpp b/camera.cpp
index 6223475..6ff72b4 100644
--- a/camera.cpp
+++ b/camera.cpp
@@ -4,7 +4,7 @@
#include
// Debug Options
-#define GlobalDebug 1 // 全局是否允许打印Debug信息(打印会拖慢处理时间)
+#define GlobalDebug 0 // 全局是否允许打印Debug信息(打印会拖慢处理时间)
#define DebugDetection 0 // 注意开启这个编译选项会导致图片存储, 处理时间会很慢
#define DebugDetectionTime 0 // 是否打印处理时间
#define DebugLowerMacCOM 0 // 是否打印和下位机通讯的相关信息
@@ -148,6 +148,11 @@ MIL_INT ProcessingFunction0(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
#endif
MdigGetHookInfo(HookId, M_MODIFIED_BUFFER + M_BUFFER_ID, &ModifiedBufferId0);
+ {
+ QMutexLocker locker(&gDispPicMutex0);
+ gDispCurrentPicId0 = ModifiedBufferId0;
+ }
+
if(SaveImg_Flag)
{
//拷贝存图图像
@@ -247,8 +252,8 @@ MIL_INT ProcessingFunction1(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
// Update the current Img MIl id
{
- QMutexLocker locker(&gPicMutex0);
- gCurrentPicId0 = ModifiedBufferId0;
+ QMutexLocker locker(&gDispPicMutex1);
+ gDispCurrentPicId1 = ModifiedBufferId1;
}
if(SaveImg_Flag)
diff --git a/cotton_double2.pro.user b/cotton_double2.pro.user
index cf6fbae..c4db3ed 100644
--- a/cotton_double2.pro.user
+++ b/cotton_double2.pro.user
@@ -1,6 +1,6 @@
-
+
EnvironmentId
diff --git a/globals.cpp b/globals.cpp
index 5be4788..0a38724 100644
--- a/globals.cpp
+++ b/globals.cpp
@@ -1,8 +1,10 @@
// globals.cpp
#include "globals.h"
-// 初始化全局互斥锁
-QMutex gPicMutex0;
+// 图片显示0
+QMutex gDispPicMutex0;
+MIL_ID gDispCurrentPicId0 = 0;
-// 初始化全局 MIL_ID
-MIL_ID gCurrentPicId0 = 0;
+// 图片显示1
+QMutex gDispPicMutex1;
+MIL_ID gDispCurrentPicId1 = 0;
diff --git a/globals.h b/globals.h
index e804c03..2de9eab 100644
--- a/globals.h
+++ b/globals.h
@@ -5,10 +5,12 @@
#include
#include
-// 全局互斥锁,保护 current_pic_id 的访问
-extern QMutex gPicMutex0;
+// 图片显示0
+extern QMutex gDispPicMutex0;
+extern MIL_ID gDispCurrentPicId0;
-// 全局变量,用于存储当前的 MIL_ID
-extern MIL_ID gCurrentPicId0;
+// 图片显示1
+extern QMutex gDispPicMutex1;
+extern MIL_ID gDispCurrentPicId1;
#endif // GLOBALS_H
diff --git a/ui_widget.h b/ui_widget.h
index bc0d231..d7bfc47 100644
--- a/ui_widget.h
+++ b/ui_widget.h
@@ -37,8 +37,10 @@ public:
QLabel *lab_info;
QPushButton *btn_start;
QPushButton *btn_stop;
- QLabel *camera_1_img;
QLabel *camera_0_img;
+ QLabel *camera_1_img;
+ QLabel *label_2;
+ QLabel *label_3;
QWidget *tab_3;
QLabel *label_title_3;
QGroupBox *groupBox_4;
@@ -128,16 +130,23 @@ public:
btn_stop = new QPushButton(tab_2);
btn_stop->setObjectName("btn_stop");
btn_stop->setGeometry(QRect(20, 190, 101, 41));
- camera_1_img = new QLabel(tab_2);
- camera_1_img->setObjectName("camera_1_img");
- camera_1_img->setGeometry(QRect(160, 20, 591, 191));
- camera_1_img->setStyleSheet(QString::fromUtf8("background-color: rgb(129, 129, 129);"));
camera_0_img = new QLabel(tab_2);
camera_0_img->setObjectName("camera_0_img");
- camera_0_img->setGeometry(QRect(160, 240, 591, 191));
+ camera_0_img->setGeometry(QRect(160, 40, 591, 191));
camera_0_img->setStyleSheet(QString::fromUtf8("background-color: rgb(129, 129, 129);\n"
"border: 4px solid black;"));
- camera_0_img->setLineWidth(1);
+ camera_1_img = new QLabel(tab_2);
+ camera_1_img->setObjectName("camera_1_img");
+ camera_1_img->setGeometry(QRect(160, 290, 591, 191));
+ camera_1_img->setStyleSheet(QString::fromUtf8("background-color: rgb(129, 129, 129);\n"
+"border: 4px solid black;"));
+ camera_1_img->setLineWidth(1);
+ label_2 = new QLabel(tab_2);
+ label_2->setObjectName("label_2");
+ label_2->setGeometry(QRect(160, 270, 141, 16));
+ label_3 = new QLabel(tab_2);
+ label_3->setObjectName("label_3");
+ label_3->setGeometry(QRect(160, 20, 141, 16));
tabWidget->addTab(tab_2, QString());
tab_3 = new QWidget();
tab_3->setObjectName("tab_3");
@@ -229,8 +238,10 @@ public:
lab_info->setText(QCoreApplication::translate("Widget", "\345\207\206\345\244\207\344\270\255", nullptr));
btn_start->setText(QCoreApplication::translate("Widget", "\345\274\200\345\247\213\345\210\206\351\200\211", nullptr));
btn_stop->setText(QCoreApplication::translate("Widget", "\345\201\234\346\255\242\345\210\206\351\200\211", nullptr));
- camera_1_img->setText(QString());
camera_0_img->setText(QString());
+ camera_1_img->setText(QString());
+ label_2->setText(QCoreApplication::translate("Widget", "\347\233\270\346\234\2721\357\274\210\351\253\230\344\276\247/\346\260\224\347\275\220\344\276\247\357\274\211", nullptr));
+ label_3->setText(QCoreApplication::translate("Widget", "\347\233\270\346\234\2720\357\274\210\344\275\216\344\276\247/\345\207\272\351\243\216\345\217\243\344\276\247\357\274\211", nullptr));
tabWidget->setTabText(tabWidget->indexOf(tab_2), QCoreApplication::translate("Widget", "Tab 2", nullptr));
label_title_3->setText(QCoreApplication::translate("Widget", "\345\217\202\346\225\260\350\256\276\347\275\256\347\225\214\351\235\242", nullptr));
groupBox_4->setTitle(QCoreApplication::translate("Widget", "\344\270\213\344\275\215\346\234\272\345\217\202\346\225\260", nullptr));
diff --git a/widget.cpp b/widget.cpp
index 9bb6fa8..5bbcce3 100644
--- a/widget.cpp
+++ b/widget.cpp
@@ -47,22 +47,50 @@ Widget::~Widget()
void Widget::refreshImage()
{
+ refreshSingleImage(0);
+ refreshSingleImage(1);
+}
+
+void Widget::refreshSingleImage(int camera_id)
+{
+ // 更新当前的图片0
MIL_ID current_id = 0;
-
- // 获取当前的 MIL_ID
+ if (camera_id == 0)
{
- QMutexLocker locker(&gPicMutex0);
- current_id = gCurrentPicId0;
+ {
+ QMutexLocker locker(&gDispPicMutex0);
+ current_id = gDispCurrentPicId0;
+ }
+ if (current_id == 0)
+ return;
+ // 获取 QPixmap 并设置到 QLabel
+ QPixmap pixmap0 = ImageUtils::mat2QPixmap(ImageUtils::mil2Mat(current_id));
+ if (!pixmap0.isNull())
+ {
+ ui->camera_0_img->setPixmap(pixmap0);
+ }
+
}
-
- if (current_id == 0)
- return;
-
- // 获取 QPixmap 并设置到 QLabel
- QPixmap pixmap = ImageUtils::mat2QPixmap(ImageUtils::mil2Mat(current_id));
- if (!pixmap.isNull())
+ // 更新当前的图片1
+ else if (camera_id == 1)
{
- ui->camera_0_img->setPixmap(pixmap);
+ {
+ QMutexLocker locker(&gDispPicMutex0);
+ current_id = gDispCurrentPicId0;
+ }
+
+ if (current_id == 0)
+ return;
+ // 获取 QPixmap 并设置到 QLabel
+ QPixmap pixmap1 = ImageUtils::mat2QPixmap(ImageUtils::mil2Mat(current_id));
+ if (!pixmap1.isNull())
+ {
+ ui->camera_1_img->setPixmap(pixmap1);
+ }
+ }
+ else
+ {
+ qWarning() << "The given Camera ID is wrong!";
}
}
@@ -80,10 +108,14 @@ void Widget::on_pushButton_2_clicked()
void Widget::on_btn_goto_sort_clicked()
{
- // 获取当前的 MIL_ID
+ // 回复当前的
{
- QMutexLocker locker(&gPicMutex0);
- gCurrentPicId0 = 0;
+ QMutexLocker locker(&gDispPicMutex0);
+ gDispCurrentPicId0 = 0;
+ }
+ {
+ QMutexLocker locker(&gDispPicMutex1);
+ gDispCurrentPicId1 = 0;
}
DestoryCamera();
DestoryLowMac();
diff --git a/widget.h b/widget.h
index 3a9842f..f552fcb 100644
--- a/widget.h
+++ b/widget.h
@@ -26,6 +26,8 @@ public slots:
private slots:
+ void refreshSingleImage(int camera_id);
+
void on_pushButton_clicked();
void on_pushButton_2_clicked();
diff --git a/widget.ui b/widget.ui
index 5a77719..16d1d69 100644
--- a/widget.ui
+++ b/widget.ui
@@ -300,27 +300,28 @@
停止分选
-
+
160
- 20
+ 40
591
191
- background-color: rgb(129, 129, 129);
+ background-color: rgb(129, 129, 129);
+border: 4px solid black;
-
+
160
- 240
+ 290
591
191
@@ -336,6 +337,32 @@ border: 4px solid black;
+
+
+
+ 160
+ 270
+ 141
+ 16
+
+
+
+ 相机1(高侧/气罐侧)
+
+
+
+
+
+ 160
+ 20
+ 141
+ 16
+
+
+
+ 相机0(低侧/出风口侧)
+
+