完善了两个相机的展示程序
This commit is contained in:
parent
643a663953
commit
ebede0bf96
11
camera.cpp
11
camera.cpp
@ -4,7 +4,7 @@
|
||||
#include <QTimer>
|
||||
|
||||
// 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)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 15.0.0, 2024-12-18T13:21:37. -->
|
||||
<!-- Written by QtCreator 15.0.0, 2024-12-18T17:01:05. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
|
||||
10
globals.cpp
10
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;
|
||||
|
||||
10
globals.h
10
globals.h
@ -5,10 +5,12 @@
|
||||
#include <MIL.h>
|
||||
#include <QMutex>
|
||||
|
||||
// 全局互斥锁,保护 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
|
||||
|
||||
27
ui_widget.h
27
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));
|
||||
|
||||
54
widget.cpp
54
widget.cpp
@ -47,22 +47,50 @@ Widget::~Widget()
|
||||
|
||||
void Widget::refreshImage()
|
||||
{
|
||||
MIL_ID current_id = 0;
|
||||
refreshSingleImage(0);
|
||||
refreshSingleImage(1);
|
||||
}
|
||||
|
||||
// 获取当前的 MIL_ID
|
||||
void Widget::refreshSingleImage(int camera_id)
|
||||
{
|
||||
QMutexLocker locker(&gPicMutex0);
|
||||
current_id = gCurrentPicId0;
|
||||
// 更新当前的图片0
|
||||
MIL_ID current_id = 0;
|
||||
if (camera_id == 0)
|
||||
{
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
// 更新当前的图片1
|
||||
else if (camera_id == 1)
|
||||
{
|
||||
{
|
||||
QMutexLocker locker(&gDispPicMutex0);
|
||||
current_id = gDispCurrentPicId0;
|
||||
}
|
||||
|
||||
if (current_id == 0)
|
||||
return;
|
||||
|
||||
// 获取 QPixmap 并设置到 QLabel
|
||||
QPixmap pixmap = ImageUtils::mat2QPixmap(ImageUtils::mil2Mat(current_id));
|
||||
if (!pixmap.isNull())
|
||||
QPixmap pixmap1 = ImageUtils::mat2QPixmap(ImageUtils::mil2Mat(current_id));
|
||||
if (!pixmap1.isNull())
|
||||
{
|
||||
ui->camera_0_img->setPixmap(pixmap);
|
||||
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();
|
||||
|
||||
2
widget.h
2
widget.h
@ -26,6 +26,8 @@ public slots:
|
||||
|
||||
private slots:
|
||||
|
||||
void refreshSingleImage(int camera_id);
|
||||
|
||||
void on_pushButton_clicked();
|
||||
|
||||
void on_pushButton_2_clicked();
|
||||
|
||||
37
widget.ui
37
widget.ui
@ -300,27 +300,28 @@
|
||||
<string>停止分选</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="camera_1_img">
|
||||
<widget class="QLabel" name="camera_0_img">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>160</x>
|
||||
<y>20</y>
|
||||
<y>40</y>
|
||||
<width>591</width>
|
||||
<height>191</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">background-color: rgb(129, 129, 129);</string>
|
||||
<string notr="true">background-color: rgb(129, 129, 129);
|
||||
border: 4px solid black;</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="camera_0_img">
|
||||
<widget class="QLabel" name="camera_1_img">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>160</x>
|
||||
<y>240</y>
|
||||
<y>290</y>
|
||||
<width>591</width>
|
||||
<height>191</height>
|
||||
</rect>
|
||||
@ -336,6 +337,32 @@ border: 4px solid black;</string>
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>160</x>
|
||||
<y>270</y>
|
||||
<width>141</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>相机1(高侧/气罐侧)</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>160</x>
|
||||
<y>20</y>
|
||||
<width>141</width>
|
||||
<height>16</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>相机0(低侧/出风口侧)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_3">
|
||||
<attribute name="title">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user