双相机显示与mask合并

This commit is contained in:
XinJiang1 2024-12-23 18:12:44 +08:00
parent f56b876119
commit 703b1430f6
11 changed files with 1980 additions and 4983 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -5,7 +5,7 @@
// Debug Options
#define GlobalDebug 0 // 全局是否允许打印Debug信息打印会拖慢处理时间
#define DebugDetection 0 // 注意开启这个编译选项会导致图片存储, 处理时间会很慢
#define DebugDetectionTime 0 // 是否打印处理时间
#define DebugDetectionTime 1 // 是否打印处理时间
#define DebugLowerMacCOM 0 // 是否打印和下位机通讯的相关信息
camera::camera() {}
@ -192,6 +192,15 @@ MIL_INT ProcessingFunction0(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
//艳丽检测mask
high_sat_detect(MimFlipDedtination, detection_result0, params);
//Onnx检测mask
// MbufCopy(ModifiedBufferId0,MilImage_Onnx0);
// cv::Mat image = ImageUtils::mil2Mat(MilImage_Onnx0);
// cv::Mat Img_Onnx;
// std::vector<Detection> result = runner.predict(image);
// Img_Onnx = runner.postProcess(result, image);
// std::vector<std::vector<uint8_t>> mask_Onnx1 = generateMaskFromImage2(Img_Onnx, widthBlocks, heightBlocks, sizeThreshold);
// Update the current Img MIl id
{
QMutexLocker locker(&gMaskMutex0);
@ -200,7 +209,12 @@ MIL_INT ProcessingFunction0(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
auto [mask_tmp, newTail] = generateMaskWithTail(detection_result0, tail_0, widthBlocks, heightBlocks, sizeThreshold, rowRange, skipLeftCols, skipRightCols);
tail_0 = newTail;
mask_0 = mask_tmp;
vector<vector<uint8_t>> merged_mask;
merged_mask = ImageUtils::mergeMasks(mask_tmp, mask_tmp); // merge the result of onnx and high sat
mask_0 = merged_mask;
detection_ready.release();
MbufFree(detection_result0);
@ -264,6 +278,7 @@ MIL_INT ProcessingFunction1(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
//艳丽检测mask
high_sat_detect(MimResizedestination, detection_result1, params);
#if(GlobalDebug && DebugDetectionTime)
timer2.printElapsedTime("Algorithm Spent: ");
#endif
@ -717,9 +732,7 @@ bool iniColor()
bool iniOnnx()
{
std::string modelPath = (getConfigDirectory() + "/dimo_11.14.onnx").toStdString();
// std::string imagePath = "C:/Users/admin/Desktop/config/463_12.5_M2.bmp";
// cv::Mat image = cv::imread(imagePath);
std::string modelPath = (getConfigDirectory() + "/dimo_369_640.onnx").toStdString();
runner.load(modelPath);

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 15.0.0, 2024-12-22T17:14:30. -->
<!-- Written by QtCreator 15.0.0, 2024-12-23T16:03:42. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>

View File

@ -18,12 +18,13 @@
/
/
/
/
[CAMERA_NAME]
no name
[CONFIG_FILE]
50CF
ODYSSEY
Sun Dec 22 20:52:23 2024
Mon Dec 23 11:31:47 2024
[INFO_FILE_REV]
0010.0019.0000
RADIENT/eVCL/DUAL
@ -65,7 +66,7 @@ VDC_IN_CH1
VDC_IN_CH2 0x0
VDC_IN_CH3 0x0
VDC_IN_CH_C 0x0
VDC_DIGITIZER 0x0
VDC_DIGITIZER 0x1
VDC_PSG_MODE_1_CHECK 0x1
VDC_PSG_MODE_2_CHECKS 0x0
VDC_PSG_MODE_3_CHECKS 0x0
@ -112,11 +113,11 @@ VDT_STD_CL
VDT_STD_DIGITAL 0x0
VDT_NOVERT 0x1
VDT_HSYNC 0x0
VDT_HBPORCH 0x0
VDT_HBPORCH 0x10
VDT_HFPORCH 0x0
VDT_HACTIVE 0x1000
VDT_HTOTAL 0x1000
VDT_HSYNC_FREQ 0x4c4b
VDT_HTOTAL 0x1010
VDT_HSYNC_FREQ 0x4bff
VDT_VSYNC 0x0
VDT_VBPORCH 0x0
VDT_VFPORCH 0x0
@ -1559,11 +1560,11 @@ DEF_INFO_XSIZE_DIVISOR
DEF_INFO_YSIZE_DIVISOR 0x1
DEF_ADD_HACTIVE_MULTIPLEX 0x0
DEF_ADD_VACTIVE_MULTIPLEX 0x0
DEF_HTOTAL_ENTRY 0x1000
DEF_HTOTAL_ENTRY 0x1010
DEF_HACTIVE_ENTRY 0x1000
DEF_VTOTAL_ENTRY 0x200
DEF_VACTIVE_ENTRY 0x200
DEF_CL_NEW_HCROPPING 0x0
DEF_CL_NEW_HCROPPING 0x10
DEF_CL_NEW_VCROPPING 0x0
DEF_NTSC 0x0
DEF_PAL 0x0
@ -1577,20 +1578,20 @@ DEF_VINTRL_ODD_EVEN
DEF_VSVAL_EQUA_ZERO 0x1
DEF_VEVAL_EQUA_VTOTAL 0x1
DEF_DIGITIZER_MASTER 0x0
DEF_CASE_HVBLANK_ZERO 0x1
DEF_ADD_3MAX_TOTAL_HVBLANK_ZERO 0x3
DEF_CASE_HVBLANK_ZERO 0x0
DEF_ADD_3MAX_TOTAL_HVBLANK_ZERO 0x0
DEF_ADD_HTOTAL_EQUA_HEVAL 0x0
DEF_HOR_COUNT_MAX_BITWISE 0xffff
DEF_VERT_COUNT_MAX_BITWISE 0xffff
DEF_DIG_HTOTAL 0x1002
DEF_DIG_HTOTAL 0x100f
DEF_DIG_VTOTAL 0x1ff
DEF_TEST_MODE_HFP_MIN 0x0
DEF_TEST_MODE_HSY_HBP_MIN_CL 0x0
DEF_TEST_MODE_VFP_MIN 0x0
DEF_TEST_MODE_VBP_MIN 0x0
DEF_TEST_MODE_VS_VBP_MIN_ANA_DIG_CL 0x0
DEF_HSVAL_EQUA_ZERO 0x1
DEF_HEVAL_EQUA_HTOTAL 0x0
DEF_HSVAL_EQUA_ZERO 0x0
DEF_HEVAL_EQUA_HTOTAL 0x1
DEF_HTOTAL_OVERFLOW 0x0
DEF_HACTIVE_OVERFLOW 0x0
DEF_VTOTAL_OVERFLOW 0x0
@ -1613,8 +1614,8 @@ DEF_TIMER0_PIPE_DELAY1
DEF_TIMER1_PIPE_DELAY1 0x0
DEF_TMR0_CLKTMR1_CNT 0x0
DEF_TMR1_CLKTMR0_CNT 0x0
DEF_TIMER01_CLK_HS_FREQ 0x4c41
DEF_TIMER01_CLK_HS_PERIOD 0xc81b
DEF_TIMER01_CLK_HS_FREQ 0x4c03
DEF_TIMER01_CLK_HS_PERIOD 0xc8be
DEF_TIMER0_CLK_HS_PERIOD_DLY1_CNT 0x0
DEF_TIMER0_CLK_HS_PERIOD_DLY2_CNT 0x0
DEF_TIMER0_CLK_HS_PERIOD_T1_CNT 0x0
@ -1923,13 +1924,13 @@ INFO_MASK_T2CTLH
INFO_MASK_T3CTLL 0x0
INFO_MASK_T3CTLH 0x0
DIG_HCNT 0x1
DIG_HTOTAL 0x1002
DIG_HTOTAL 0x100f
DIG_HSCNT 0x0
DIG_HECNT 0x1
DIG_HSSYNC 0x0
DIG_HESYNC 0x0
DIG_HSVAL 0x0
DIG_HEVAL 0xfff
DIG_HSVAL 0x10
DIG_HEVAL 0x100f
DIG_HSCLM 0x0
DIG_HECLM 0x0
DIG_HCTL 0x1e0
@ -2349,5 +2350,5 @@ DIG_IOCTL1H
DIG_IOCTL0_L not_modified
DIG_ENCTL not_modified
[EOF]
00007FF72205AAA8 0x400bb
00007FF72205AA90 0x2b19a5ff
00007FF72205AAA8 0x400c2
00007FF72205AA90 0x48b9cbd0

View File

@ -11,6 +11,8 @@
#include <QtCore/QVariant>
#include <QtWidgets/QApplication>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QFrame>
#include <QtWidgets/QGridLayout>
#include <QtWidgets/QGroupBox>
#include <QtWidgets/QHBoxLayout>
@ -33,10 +35,10 @@ public:
QVBoxLayout *verticalLayout;
QGroupBox *groupBox_5;
QGridLayout *gridLayout;
QPushButton *pushButton_2;
QPushButton *btn_goto_sort;
QPushButton *btn_0to3;
QPushButton *pushButtonStart;
QPushButton *pushButton_2;
QGroupBox *groupBox;
QHBoxLayout *horizontalLayout_2;
QLabel *label;
@ -48,14 +50,25 @@ public:
QVBoxLayout *verticalLayout_3;
QLabel *lab_info;
QPushButton *btn_start;
QPushButton *btn_take_photos;
QPushButton *btn_stop;
QSpacerItem *verticalSpacer;
QGroupBox *groupBox_6;
QFrame *frame_6;
QVBoxLayout *verticalLayout_2;
QLabel *label_3;
QLabel *camera_0_img;
QFrame *frame;
QHBoxLayout *horizontalLayout_4;
QLabel *label_2;
QSpacerItem *horizontalSpacer;
QCheckBox *img_1_mirror;
QCheckBox *img_1_overlay;
QLabel *camera_1_img;
QFrame *frame_2;
QHBoxLayout *horizontalLayout_5;
QLabel *label_4;
QSpacerItem *horizontalSpacer_2;
QCheckBox *img_0_mirror;
QCheckBox *img_0_overlay;
QLabel *camera_0_img;
QWidget *tab_3;
QLabel *label_title_3;
QGroupBox *groupBox_4;
@ -82,11 +95,12 @@ public:
{
if (Widget->objectName().isEmpty())
Widget->setObjectName("Widget");
Widget->resize(800, 600);
Widget->resize(1920, 1080);
horizontalLayout = new QHBoxLayout(Widget);
horizontalLayout->setObjectName("horizontalLayout");
tabWidget = new QTabWidget(Widget);
tabWidget->setObjectName("tabWidget");
tabWidget->setEnabled(true);
tab = new QWidget();
tab->setObjectName("tab");
verticalLayout = new QVBoxLayout(tab);
@ -95,11 +109,6 @@ public:
groupBox_5->setObjectName("groupBox_5");
gridLayout = new QGridLayout(groupBox_5);
gridLayout->setObjectName("gridLayout");
pushButton_2 = new QPushButton(groupBox_5);
pushButton_2->setObjectName("pushButton_2");
gridLayout->addWidget(pushButton_2, 1, 1, 1, 1);
btn_goto_sort = new QPushButton(groupBox_5);
btn_goto_sort->setObjectName("btn_goto_sort");
@ -115,6 +124,11 @@ public:
gridLayout->addWidget(pushButtonStart, 1, 0, 1, 1);
pushButton_2 = new QPushButton(groupBox_5);
pushButton_2->setObjectName("pushButton_2");
gridLayout->addWidget(pushButton_2, 1, 1, 1, 1);
verticalLayout->addWidget(groupBox_5);
@ -174,6 +188,7 @@ public:
verticalLayout_3->setContentsMargins(9, 9, 9, -1);
lab_info = new QLabel(groupBox_7);
lab_info->setObjectName("lab_info");
lab_info->setEnabled(true);
QFont font;
font.setPointSize(28);
lab_info->setFont(font);
@ -182,13 +197,19 @@ public:
btn_start = new QPushButton(groupBox_7);
btn_start->setObjectName("btn_start");
btn_start->setMinimumSize(QSize(70, 70));
btn_start->setMinimumSize(QSize(70, 200));
verticalLayout_3->addWidget(btn_start);
btn_take_photos = new QPushButton(groupBox_7);
btn_take_photos->setObjectName("btn_take_photos");
btn_take_photos->setMinimumSize(QSize(70, 200));
verticalLayout_3->addWidget(btn_take_photos);
btn_stop = new QPushButton(groupBox_7);
btn_stop->setObjectName("btn_stop");
btn_stop->setMinimumSize(QSize(70, 70));
btn_stop->setMinimumSize(QSize(70, 200));
verticalLayout_3->addWidget(btn_stop);
@ -199,35 +220,47 @@ public:
horizontalLayout_3->addWidget(groupBox_7);
groupBox_6 = new QGroupBox(tab_2);
groupBox_6->setObjectName("groupBox_6");
verticalLayout_2 = new QVBoxLayout(groupBox_6);
frame_6 = new QFrame(tab_2);
frame_6->setObjectName("frame_6");
verticalLayout_2 = new QVBoxLayout(frame_6);
verticalLayout_2->setObjectName("verticalLayout_2");
label_3 = new QLabel(groupBox_6);
label_3->setObjectName("label_3");
frame = new QFrame(frame_6);
frame->setObjectName("frame");
frame->setFrameShape(QFrame::Shape::StyledPanel);
frame->setFrameShadow(QFrame::Shadow::Raised);
horizontalLayout_4 = new QHBoxLayout(frame);
horizontalLayout_4->setObjectName("horizontalLayout_4");
label_2 = new QLabel(frame);
label_2->setObjectName("label_2");
label_2->setStyleSheet(QString::fromUtf8("font: 18pt \"Microsoft YaHei UI\";"));
verticalLayout_2->addWidget(label_3);
horizontalLayout_4->addWidget(label_2);
camera_0_img = new QLabel(groupBox_6);
camera_0_img->setObjectName("camera_0_img");
horizontalSpacer = new QSpacerItem(864, 20, QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Minimum);
horizontalLayout_4->addItem(horizontalSpacer);
img_1_mirror = new QCheckBox(frame);
img_1_mirror->setObjectName("img_1_mirror");
img_1_mirror->setStyleSheet(QString::fromUtf8("font: 12pt \"Microsoft YaHei UI\";"));
horizontalLayout_4->addWidget(img_1_mirror);
img_1_overlay = new QCheckBox(frame);
img_1_overlay->setObjectName("img_1_overlay");
img_1_overlay->setEnabled(false);
img_1_overlay->setStyleSheet(QString::fromUtf8("font: 12pt \"Microsoft YaHei UI\";"));
horizontalLayout_4->addWidget(img_1_overlay);
verticalLayout_2->addWidget(frame);
camera_1_img = new QLabel(frame_6);
camera_1_img->setObjectName("camera_1_img");
QSizePolicy sizePolicy(QSizePolicy::Policy::Ignored, QSizePolicy::Policy::Ignored);
sizePolicy.setHorizontalStretch(0);
sizePolicy.setVerticalStretch(0);
sizePolicy.setHeightForWidth(camera_0_img->sizePolicy().hasHeightForWidth());
camera_0_img->setSizePolicy(sizePolicy);
camera_0_img->setStyleSheet(QString::fromUtf8("background-color: rgb(129, 129, 129);\n"
"border: 4px solid black;"));
camera_0_img->setLineWidth(1);
verticalLayout_2->addWidget(camera_0_img);
label_2 = new QLabel(groupBox_6);
label_2->setObjectName("label_2");
verticalLayout_2->addWidget(label_2);
camera_1_img = new QLabel(groupBox_6);
camera_1_img->setObjectName("camera_1_img");
sizePolicy.setHeightForWidth(camera_1_img->sizePolicy().hasHeightForWidth());
camera_1_img->setSizePolicy(sizePolicy);
camera_1_img->setStyleSheet(QString::fromUtf8("background-color: rgb(129, 129, 129);\n"
@ -236,12 +269,55 @@ public:
verticalLayout_2->addWidget(camera_1_img);
frame_2 = new QFrame(frame_6);
frame_2->setObjectName("frame_2");
frame_2->setFrameShape(QFrame::Shape::StyledPanel);
frame_2->setFrameShadow(QFrame::Shadow::Raised);
horizontalLayout_5 = new QHBoxLayout(frame_2);
horizontalLayout_5->setObjectName("horizontalLayout_5");
label_4 = new QLabel(frame_2);
label_4->setObjectName("label_4");
label_4->setStyleSheet(QString::fromUtf8("font: 18pt \"Microsoft YaHei UI\";"));
horizontalLayout_5->addWidget(label_4);
horizontalSpacer_2 = new QSpacerItem(840, 20, QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Minimum);
horizontalLayout_5->addItem(horizontalSpacer_2);
img_0_mirror = new QCheckBox(frame_2);
img_0_mirror->setObjectName("img_0_mirror");
img_0_mirror->setStyleSheet(QString::fromUtf8("font: 12pt \"Microsoft YaHei UI\";"));
img_0_mirror->setChecked(true);
horizontalLayout_5->addWidget(img_0_mirror);
img_0_overlay = new QCheckBox(frame_2);
img_0_overlay->setObjectName("img_0_overlay");
img_0_overlay->setEnabled(false);
img_0_overlay->setStyleSheet(QString::fromUtf8("font: 12pt \"Microsoft YaHei UI\";"));
horizontalLayout_5->addWidget(img_0_overlay);
verticalLayout_2->addWidget(frame_2);
camera_0_img = new QLabel(frame_6);
camera_0_img->setObjectName("camera_0_img");
sizePolicy.setHeightForWidth(camera_0_img->sizePolicy().hasHeightForWidth());
camera_0_img->setSizePolicy(sizePolicy);
camera_0_img->setStyleSheet(QString::fromUtf8("background-color: rgb(129, 129, 129);\n"
"border: 4px solid black;"));
camera_0_img->setLineWidth(1);
verticalLayout_2->addWidget(camera_0_img);
verticalLayout_2->setStretch(1, 5);
verticalLayout_2->setStretch(3, 5);
horizontalLayout_3->addWidget(groupBox_6);
horizontalLayout_3->addWidget(frame_6);
horizontalLayout_3->setStretch(0, 3);
horizontalLayout_3->setStretch(0, 4);
horizontalLayout_3->setStretch(1, 10);
tabWidget->addTab(tab_2, QString());
tab_3 = new QWidget();
@ -326,10 +402,10 @@ public:
{
Widget->setWindowTitle(QCoreApplication::translate("Widget", "Widget", nullptr));
groupBox_5->setTitle(QCoreApplication::translate("Widget", "GroupBox", nullptr));
pushButton_2->setText(QCoreApplication::translate("Widget", "\344\277\235\345\255\230\345\233\276\347\211\207", nullptr));
btn_goto_sort->setText(QCoreApplication::translate("Widget", "\345\201\234\346\255\242", nullptr));
btn_0to3->setText(QCoreApplication::translate("Widget", "\345\226\267\351\230\200\346\265\213\350\257\225", nullptr));
pushButtonStart->setText(QCoreApplication::translate("Widget", "\345\274\200\345\247\213", nullptr));
pushButton_2->setText(QCoreApplication::translate("Widget", "\344\277\235\345\255\230\345\233\276\347\211\207", nullptr));
groupBox->setTitle(QCoreApplication::translate("Widget", "\350\277\236\346\216\245\347\212\266\346\200\201\357\274\232", nullptr));
label->setText(QCoreApplication::translate("Widget", "\344\270\213\344\275\215\346\234\272", nullptr));
lab_lowermachine_isconnect->setText(QString());
@ -338,12 +414,16 @@ public:
groupBox_7->setTitle(QCoreApplication::translate("Widget", "\346\216\247\345\210\266\345\217\212\347\212\266\346\200\201", nullptr));
lab_info->setText(QCoreApplication::translate("Widget", "\347\212\266\346\200\201", nullptr));
btn_start->setText(QCoreApplication::translate("Widget", "\345\274\200\345\247\213\345\210\206\351\200\211", nullptr));
btn_take_photos->setText(QCoreApplication::translate("Widget", "\346\212\223\345\217\226\345\233\276\347\211\207", nullptr));
btn_stop->setText(QCoreApplication::translate("Widget", "\345\201\234\346\255\242\345\210\206\351\200\211", nullptr));
groupBox_6->setTitle(QCoreApplication::translate("Widget", "\347\233\270\346\234\272\346\230\276\347\244\272", 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));
camera_0_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));
img_1_mirror->setText(QCoreApplication::translate("Widget", "\345\233\276\347\211\207\351\225\234\345\203\217", nullptr));
img_1_overlay->setText(QCoreApplication::translate("Widget", "\350\257\206\345\210\253\347\273\223\346\236\234", nullptr));
camera_1_img->setText(QString());
label_4->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));
img_0_mirror->setText(QCoreApplication::translate("Widget", "\345\233\276\347\211\207\351\225\234\345\203\217", nullptr));
img_0_overlay->setText(QCoreApplication::translate("Widget", "\350\257\206\345\210\253\347\273\223\346\236\234", nullptr));
camera_0_img->setText(QString());
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));

View File

@ -32,6 +32,7 @@ Widget::Widget(QWidget *parent)
ui->camera_0_img->setScaledContents(false);
ui->camera_1_img->setScaledContents(false);
iniOnnx();
iniColor();
iniLowMac();
iniCamera();
@ -70,81 +71,105 @@ Widget::~Widget()
void Widget::refreshImage()
{
// refresh Image 1 and image 0
refreshSingleImage(0, false);
refreshSingleImage(1, false);
refreshSingleImage(0, this->ui->img_0_overlay->isChecked(), this->ui->img_0_mirror->isChecked());
refreshSingleImage(1, this->ui->img_1_overlay->isChecked(), this->ui->img_1_mirror->isChecked());
// refresh buttons
this->ui->btn_start->setEnabled(!this->isCamRunning);
this->ui->btn_stop->setEnabled(this->isCamRunning);
this->ui->btn_take_photos->setEnabled(this->isCamRunning);
// refresh info
this->ui->lab_info->setText(this->isCamRunning? "运行": "停止");
}
void Widget::refreshSingleImage(int camera_id, bool overlay_result)
QString info;
if(this->isCamRunning)
{
// 更新当前的图片0
MIL_ID current_id = 0;
if (camera_id == 0)
{ // 获取当前图片
if(SaveImg_Flag==1)
{
QMutexLocker locker(&gDispPicMutex0);
current_id = gDispCurrentPicId0;
}
if (current_id == 0)
return;
cv::Mat img = ImageUtils::mil2Mat(current_id);
//进行结果的转化叠加
if (overlay_result)
{
MIL_ID mask_id = 0;
{
QMutexLocker locker(&gMaskMutex0);
mask_id = gMask0;
}
cv::Mat mask = ImageUtils::mil2Mat(mask_id);
img = ImageUtils::overlayResultOnInput(img,mask,0.5);
}
//刷新显示
QPixmap pixmap0 = ImageUtils::mat2QPixmap(img);
if (!pixmap0.isNull())
{
pixmap0 = pixmap0.scaled(ui->camera_0_img->width(), ui->camera_0_img->height());
ui->camera_0_img->setPixmap(pixmap0);
}
}
// 更新当前的图片1
else if (camera_id == 1)
{
{
QMutexLocker locker(&gDispPicMutex1);
current_id = gDispCurrentPicId1;
}
if (current_id == 0)
return;
cv::Mat img = ImageUtils::mil2Mat(current_id);
//进行结果的转化叠加
if (overlay_result)
{
MIL_ID mask_id = 0;
{
QMutexLocker locker(&gMaskMutex1);
mask_id = gMask1;
}
cv::Mat mask = ImageUtils::mil2Mat(mask_id);
img = ImageUtils::overlayResultOnInput(img,mask,0.5);
}
//刷新显示
QPixmap pixmap1 = ImageUtils::mat2QPixmap(img);
if (!pixmap1.isNull())
{
pixmap1 = pixmap1.scaled(ui->camera_1_img->width(), ui->camera_1_img->height());
ui->camera_1_img->setPixmap(pixmap1);
}
info = "存图中!!";
}
else
{
qWarning() << "The given Camera ID is wrong!";
info = "运行";
};
}else {
info = "停止";
};
this->ui->lab_info->setText(info);
}
void Widget::refreshSingleImage(int camera_id, bool overlay_result, bool mirror)
{
// 验证摄像头ID的有效性
if (camera_id < 0 || camera_id >= 2) { // 假设只有两个摄像头
qWarning() << "Invalid Camera ID:" << camera_id;
return;
}
// 定义每个摄像头对应的变量数组
QMutex* dispPicMutexes[2] = { &gDispPicMutex0, &gDispPicMutex1 };
MIL_ID dispCurrentPicIds[2] = { gDispCurrentPicId0, gDispCurrentPicId1 };
QMutex* maskMutexes[2] = { &gMaskMutex0, &gMaskMutex1 };
MIL_ID maskIds[2] = { gMask0, gMask1 };
QLabel* cameraLabels[2] = { ui->camera_0_img, ui->camera_1_img };
// 获取当前摄像头的数据
QMutex* currentDispMutex = dispPicMutexes[camera_id];
MIL_ID current_id;
{
QMutexLocker locker(currentDispMutex);
current_id = dispCurrentPicIds[camera_id];
}
if (current_id == 0)
return;
// 将MIL图像转换为OpenCV Mat
cv::Mat img = ImageUtils::mil2Mat(current_id);
if (img.empty()) {
qWarning() << "Failed to convert MIL image to Mat for Camera ID:" << camera_id;
return;
}
// 如果需要叠加结果,处理掩码
if (overlay_result)
{
QMutex* currentMaskMutex = maskMutexes[camera_id];
MIL_ID mask_id;
{
QMutexLocker locker(currentMaskMutex);
mask_id = maskIds[camera_id];
}
if (mask_id != 0) {
cv::Mat mask = ImageUtils::mil2Mat(mask_id);
if (!mask.empty()) {
img = ImageUtils::overlayResultOnInput(img, mask, 0.5);
}
else {
qWarning() << "Failed to convert MIL mask to Mat for Camera ID:" << camera_id;
}
}
}
// 如果需要镜像处理
if (mirror)
{
cv::flip(img, img, 1); // 水平翻转
}
// 将OpenCV Mat转换为QPixmap
QPixmap pixmap = ImageUtils::mat2QPixmap(img);
if (pixmap.isNull()) {
qWarning() << "Failed to convert Mat to QPixmap for Camera ID:" << camera_id;
return;
}
// 高质量缩放图像
QSize labelSize = cameraLabels[camera_id]->size();
QPixmap scaledPixmap = pixmap.scaled(labelSize);
// 更新UI标签
cameraLabels[camera_id]->setPixmap(scaledPixmap);
}
@ -197,3 +222,15 @@ void Widget::on_btn_start_clicked()
Start_camera();
}
void Widget::on_btn_take_photos_pressed()
{
SaveImg_Flag = true;
}
void Widget::on_btn_take_photos_released()
{
SaveImg_Flag = false;
}

View File

@ -27,7 +27,7 @@ public slots:
private slots:
void refreshSingleImage(int camera_id, bool overlay_result = true);
void refreshSingleImage(int camera_id, bool overlay_result = true, bool mirror = false);
void on_pushButton_2_clicked();
@ -37,6 +37,10 @@ private slots:
void on_btn_start_clicked();
void on_btn_take_photos_pressed();
void on_btn_take_photos_released();
private:
Ui::Widget *ui;

165
widget.ui
View File

@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>800</width>
<height>600</height>
<width>1920</width>
<height>1080</height>
</rect>
</property>
<property name="windowTitle">
@ -16,6 +16,9 @@
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="enabled">
<bool>true</bool>
</property>
<property name="currentIndex">
<number>1</number>
</property>
@ -30,13 +33,6 @@
<string>GroupBox</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="1">
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>保存图片</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="btn_goto_sort">
<property name="text">
@ -58,6 +54,13 @@
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="pushButton_2">
<property name="text">
<string>保存图片</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@ -218,7 +221,7 @@
<attribute name="title">
<string>Tab 2</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout_3" stretch="3,10">
<layout class="QHBoxLayout" name="horizontalLayout_3" stretch="4,10">
<item>
<widget class="QGroupBox" name="groupBox_7">
<property name="title">
@ -239,6 +242,9 @@
</property>
<item>
<widget class="QLabel" name="lab_info">
<property name="enabled">
<bool>true</bool>
</property>
<property name="font">
<font>
<pointsize>28</pointsize>
@ -254,7 +260,7 @@
<property name="minimumSize">
<size>
<width>70</width>
<height>70</height>
<height>200</height>
</size>
</property>
<property name="text">
@ -262,12 +268,25 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_take_photos">
<property name="minimumSize">
<size>
<width>70</width>
<height>200</height>
</size>
</property>
<property name="text">
<string>抓取图片</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_stop">
<property name="minimumSize">
<size>
<width>70</width>
<height>70</height>
<height>200</height>
</size>
</property>
<property name="text">
@ -292,20 +311,68 @@
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_6">
<property name="title">
<string>相机显示</string>
</property>
<widget class="QFrame" name="frame_6">
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,5,0,5">
<item>
<widget class="QLabel" name="label_3">
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::Shape::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Shadow::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label_2">
<property name="styleSheet">
<string notr="true">font: 18pt &quot;Microsoft YaHei UI&quot;;</string>
</property>
<property name="text">
<string>相机0低侧/出风口侧)</string>
<string>相机1高侧/气罐侧)</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="camera_0_img">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>864</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="img_1_mirror">
<property name="styleSheet">
<string notr="true">font: 12pt &quot;Microsoft YaHei UI&quot;;</string>
</property>
<property name="text">
<string>图片镜像</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="img_1_overlay">
<property name="enabled">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">font: 12pt &quot;Microsoft YaHei UI&quot;;</string>
</property>
<property name="text">
<string>识别结果</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="camera_1_img">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Ignored">
<horstretch>0</horstretch>
@ -325,14 +392,68 @@ border: 4px solid black;</string>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<widget class="QFrame" name="frame_2">
<property name="frameShape">
<enum>QFrame::Shape::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Shadow::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="label_4">
<property name="styleSheet">
<string notr="true">font: 18pt &quot;Microsoft YaHei UI&quot;;</string>
</property>
<property name="text">
<string>相机1高侧/气罐侧)</string>
<string>相机0低侧/出风口侧)</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="camera_1_img">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>840</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QCheckBox" name="img_0_mirror">
<property name="styleSheet">
<string notr="true">font: 12pt &quot;Microsoft YaHei UI&quot;;</string>
</property>
<property name="text">
<string>图片镜像</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="img_0_overlay">
<property name="enabled">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true">font: 12pt &quot;Microsoft YaHei UI&quot;;</string>
</property>
<property name="text">
<string>识别结果</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="camera_0_img">
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Ignored">
<horstretch>0</horstretch>