diff --git a/camera.cpp b/camera.cpp index 57271bf..5556134 100644 --- a/camera.cpp +++ b/camera.cpp @@ -163,7 +163,7 @@ MIL_INT ProcessingFunction0(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr) //拷贝存图图像 MbufCopy(ModifiedBufferId0,MilImage0); //Mil保存路径 - QString MilImgPath = QString("C:/Users/Pc/Desktop/cotton_double2/Img1/%1.bmp").arg(FuncCount0); + QString MilImgPath = QString("C:/Users/Administrator/Desktop/1/%1.bmp").arg(FuncCount0); MIL_STRING MilImagePath = MilImgPath.toStdWString(); MbufExport(MilImagePath,M_BMP,MilImage0); qDebug()<<"回调1成功存储照片:"<(mat.step), QImage::Format_Grayscale8).copy(); } - else if(mat.channels() == 3){ + else if(mat.channels() == 3) + { // 彩色图像 (OpenCV 默认是 BGR,需要转换为 RGB) cv::Mat rgb; cv::cvtColor(mat, rgb, cv::COLOR_BGR2RGB); img = QImage(rgb.data, rgb.cols, rgb.rows, static_cast(rgb.step), QImage::Format_RGB888).copy(); } - else if(mat.channels() == 4){ + else if(mat.channels() == 4) + { // 如果需要处理带有透明通道的图像 (BGRA 转 RGBA) cv::Mat rgba; cv::cvtColor(mat, rgba, cv::COLOR_BGRA2RGBA); img = QImage(rgba.data, rgba.cols, rgba.rows, static_cast(rgba.step), QImage::Format_RGBA8888).copy(); } - else{ + else + { // 不支持的图像格式 std::cout << "Unsupported Mat format with channels:" << mat.channels(); return QPixmap(); diff --git a/ui_widget.h b/ui_widget.h index 6d8adb4..84095b2 100644 --- a/ui_widget.h +++ b/ui_widget.h @@ -37,10 +37,10 @@ public: QLabel *lab_info; QPushButton *pushButton; QPushButton *btn_stop; - QLabel *camera_0_img; QLabel *camera_1_img; QLabel *label_2; QLabel *label_3; + QLabel *camera_0_img; QWidget *tab_3; QLabel *label_title_3; QGroupBox *groupBox_4; @@ -130,11 +130,6 @@ public: btn_stop = new QPushButton(tab_2); btn_stop->setObjectName("btn_stop"); btn_stop->setGeometry(QRect(20, 190, 101, 41)); - camera_0_img = new QLabel(tab_2); - camera_0_img->setObjectName("camera_0_img"); - 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_1_img = new QLabel(tab_2); camera_1_img->setObjectName("camera_1_img"); camera_1_img->setGeometry(QRect(160, 290, 591, 191)); @@ -147,6 +142,12 @@ public: label_3 = new QLabel(tab_2); label_3->setObjectName("label_3"); label_3->setGeometry(QRect(160, 20, 141, 16)); + camera_0_img = new QLabel(tab_2); + camera_0_img->setObjectName("camera_0_img"); + camera_0_img->setGeometry(QRect(160, 50, 591, 191)); + camera_0_img->setStyleSheet(QString::fromUtf8("background-color: rgb(129, 129, 129);\n" +"border: 4px solid black;")); + camera_0_img->setLineWidth(1); tabWidget->addTab(tab_2, QString()); tab_3 = new QWidget(); tab_3->setObjectName("tab_3"); @@ -238,10 +239,10 @@ public: lab_info->setText(QCoreApplication::translate("Widget", "\345\207\206\345\244\207\344\270\255", nullptr)); pushButton->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_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)); + 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)); diff --git a/widget.cpp b/widget.cpp index d89ab0e..0b325aa 100644 --- a/widget.cpp +++ b/widget.cpp @@ -27,6 +27,7 @@ Widget::Widget(QWidget *parent) { ui->setupUi(this); ui->camera_0_img->setScaledContents(true); + ui->camera_1_img->setScaledContents(true); iniColor(); @@ -88,28 +89,26 @@ void Widget::refreshSingleImage(int camera_id, bool overlay_result) { QMutexLocker locker(&gDispPicMutex1); current_id = gDispCurrentPicId1; - - if (current_id == 0) - return; - cv::Mat img = ImageUtils::mil2Mat(current_id); - //进行结果的转化叠加 - if (overlay_result) + } + if (current_id == 0) + return; + cv::Mat img = ImageUtils::mil2Mat(current_id); + //进行结果的转化叠加 + if (overlay_result) + { + MIL_ID mask_id = 0; { - 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()) - { - ui->camera_1_img->setPixmap(pixmap1); - + 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()) + { + ui->camera_1_img->setPixmap(pixmap1); } } else diff --git a/widget.ui b/widget.ui index 70e0e6b..b71c174 100644 --- a/widget.ui +++ b/widget.ui @@ -300,23 +300,6 @@ 停止分选 - - - - 160 - 40 - 591 - 191 - - - - background-color: rgb(129, 129, 129); -border: 4px solid black; - - - - - @@ -363,6 +346,26 @@ border: 4px solid black; 相机0(低侧/出风口侧) + + + + 160 + 50 + 591 + 191 + + + + background-color: rgb(129, 129, 129); +border: 4px solid black; + + + 1 + + + + +