From cba4629927c674e71d76a00050d024a985a5f61e Mon Sep 17 00:00:00 2001 From: XinJiang1 <1170701029@qq.com> Date: Thu, 9 Jan 2025 16:04:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86=E7=9B=B8=E6=9C=BA?= =?UTF-8?q?=E7=9A=84=E5=B7=A6=E5=8F=B3=E5=B1=8F=E8=94=BD=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile.Debug | 1 - Makefile.Release | 1 - camera.cpp | 82 ++--- camera.h | 7 +- cotton_double2.pro.user | 2 +- dist/config/color_range_config.txt | 36 ++- release/config/color_range_config.txt | 4 + ui_widget.h | 166 ++++++++-- widget.cpp | 26 +- widget.ui | 443 +++++++++++++++++--------- 10 files changed, 531 insertions(+), 237 deletions(-) diff --git a/Makefile.Debug b/Makefile.Debug index 2d04af5..190b24c 100644 --- a/Makefile.Debug +++ b/Makefile.Debug @@ -4349,7 +4349,6 @@ debug\widget.obj: widget.cpp widget.h \ ..\..\..\..\Qt\6.7.3\msvc2022_64\include\QtCore\QDateTime \ ..\..\..\..\Qt\6.7.3\msvc2022_64\include\QtWidgets\QTabBar \ detection_worker.h \ - ..\..\..\..\Qt\6.7.3\msvc2022_64\include\QtCore\Qstring \ ..\..\..\..\Qt\6.7.3\msvc2022_64\include\QtCore\QTextStream \ ..\..\..\..\Qt\6.7.3\msvc2022_64\include\QtWidgets\QMessageBox \ ..\..\..\..\Qt\6.7.3\msvc2022_64\include\QtWidgets\qmessagebox.h \ diff --git a/Makefile.Release b/Makefile.Release index 62badee..5e1e75e 100644 --- a/Makefile.Release +++ b/Makefile.Release @@ -4348,7 +4348,6 @@ release\widget.obj: widget.cpp widget.h \ ..\..\..\..\Qt\6.7.3\msvc2022_64\include\QtCore\QDateTime \ ..\..\..\..\Qt\6.7.3\msvc2022_64\include\QtWidgets\QTabBar \ detection_worker.h \ - ..\..\..\..\Qt\6.7.3\msvc2022_64\include\QtCore\Qstring \ ..\..\..\..\Qt\6.7.3\msvc2022_64\include\QtCore\QTextStream \ ..\..\..\..\Qt\6.7.3\msvc2022_64\include\QtWidgets\QMessageBox \ ..\..\..\..\Qt\6.7.3\msvc2022_64\include\QtWidgets\qmessagebox.h \ diff --git a/camera.cpp b/camera.cpp index 7eb7999..21b306e 100644 --- a/camera.cpp +++ b/camera.cpp @@ -230,7 +230,9 @@ MIL_INT ProcessingFunction0(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr) #endif // 任务在指定时间内完成,可以继续使用 detection_result1 \ // 将 Matrox 的检测结果转换为 二维vector - matrox_mask = generateMaskFromMatImage(matrox_mat, widthBlocks, heightBlocks, sizeThreshold); + matrox_mask = generateMaskFromMatImage(matrox_mat, widthBlocks, heightBlocks, sizeThreshold, + params["screen_left_" + std::to_string(camera_id)], + params["screen_right_" + std::to_string(camera_id)]); } else { @@ -272,7 +274,9 @@ MIL_INT ProcessingFunction0(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr) timer_detection_time.restart(); #endif // 将深度学习的检测结果转换为 OpenCV Mat - dl_mask = generateMaskFromMatImage(dl_data.image, widthBlocks, heightBlocks, sizeThreshold); + dl_mask = generateMaskFromMatImage(dl_data.image, widthBlocks, heightBlocks, sizeThreshold, + params["screen_left_" + std::to_string(camera_id)], + params["screen_right_" + std::to_string(camera_id)]); merged_mask = ImageUtils::mergeMasks(dl_mask, matrox_mask); } else @@ -400,7 +404,9 @@ MIL_INT ProcessingFunction1(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr) #endif // 任务在20ms内完成,可以继续使用 detection_result1 \ // 将 Matrox 的检测结果转换为 二维vector - matrox_mask = generateMaskFromMatImage(matrox_mat, widthBlocks, heightBlocks, sizeThreshold); + matrox_mask = generateMaskFromMatImage(matrox_mat, widthBlocks, heightBlocks, sizeThreshold, + params["screen_left_" + std::to_string(camera_id)], + params["screen_right_" + std::to_string(camera_id)]); #if(GlobalDebug && DebugDetectionTime) timer_detection_time.printElapsedTime("CallBack2: High sat detection to mask"); timer_detection_time.restart(); @@ -446,7 +452,9 @@ MIL_INT ProcessingFunction1(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr) timer_detection_time.restart(); #endif // 将深度学习的检测结果转换为 OpenCV Mat - dl_mask = generateMaskFromMatImage(dl_data.image, widthBlocks, heightBlocks, sizeThreshold); + dl_mask = generateMaskFromMatImage(dl_data.image, widthBlocks, heightBlocks, sizeThreshold, + params["screen_left_" + std::to_string(camera_id)], + params["screen_right_" + std::to_string(camera_id)]); merged_mask = ImageUtils::mergeMasks(dl_mask, matrox_mask); } else @@ -712,48 +720,46 @@ std::vector> generateMaskFromImage(const MIL_ID& inputImage } -std::vector> generateMaskFromMatImage(const cv::Mat& image, int widthBlocks, int heightBlocks, int thresholds= 10) { +std::vector> generateMaskFromMatImage( + const cv::Mat& image, + int outputWidth, + int outputHeight, + int thresholds, + int skipLeftCols, + int skipRightCols) { - // 确保图像是二值化的-* + // Ensure the image is binary cv::threshold(image, image, 128, 255, cv::THRESH_BINARY); - // 获取图像的宽度和高度 int imageWidth = image.cols; int imageHeight = image.rows; - // 计算每个块的宽度和高度 - int blockWidth = imageWidth / widthBlocks; - int blockHeight = imageHeight / heightBlocks; - - // 创建掩膜矩阵 - std::vector> mask(heightBlocks, std::vector(widthBlocks, false)); - - // 遍历每个块并统计白色像素点的数量 - for (int i = 0; i < heightBlocks; ++i) - { - for (int j = 0; j < widthBlocks; ++j) - { - // 计算块的起始和结束位置 - int x_start = j * blockWidth; - int y_start = i * blockHeight; - int x_end = (j == widthBlocks - 1) ? imageWidth : (j + 1) * blockWidth; - int y_end = (i == heightBlocks - 1) ? imageHeight : (i + 1) * blockHeight; - - // 提取当前块 - cv::Mat block = image(cv::Rect(x_start, y_start, x_end - x_start, y_end - y_start)); - - // 统计块中白色像素的数量 - int whitePixelCount = cv::countNonZero(block); - - // 如果白色像素数大于阈值,将该块标记为 true - if (whitePixelCount > thresholds) - { - mask[i][j] = true; - } - - } + // Adjust image width by excluding skipLeftCols and skipRightCols + int effectiveWidth = imageWidth - skipLeftCols - skipRightCols; + if (effectiveWidth <= 0) { + throw std::invalid_argument("Invalid column skip values. Effective width is less than or equal to zero."); } + int blockWidth = effectiveWidth / outputWidth; + int blockHeight = imageHeight / outputHeight; + + vector> mask(outputHeight, vector(outputWidth, 0)); + + for (int i = 0; i < outputHeight; ++i) { + for (int j = 0; j < outputWidth; ++j) { + int x_start = skipLeftCols + j * blockWidth; + int y_start = i * blockHeight; + int x_end = (j == outputWidth - 1) ? (imageWidth - skipRightCols) : (skipLeftCols + (j + 1) * blockWidth); + int y_end = (i == outputHeight - 1) ? imageHeight : (i + 1) * blockHeight; + + cv::Mat block = image(cv::Rect(x_start, y_start, x_end - x_start, y_end - y_start)); + + int whitePixelCount = cv::countNonZero(block); + if (whitePixelCount > sizeThreshold) { + mask[i][j] = 1; + } + } + } return mask; } diff --git a/camera.h b/camera.h index 78b1a93..e27c8b9 100644 --- a/camera.h +++ b/camera.h @@ -30,7 +30,12 @@ extern MIL_ID MilApplication; extern MIL_ID MilSystem; std::vector> generateMaskFromImage(const MIL_ID& inputImage, int widthBlocks, int heightBlocks, int thresholds); -std::vector> generateMaskFromMatImage(const cv::Mat& image, int widthBlocks, int heightBlocks, int thresholds); +std::vector> generateMaskFromMatImage(const cv::Mat& image, + int widthBlocks, + int heightBlocks, + int thresholds = 10, + int skipLeftCols = 0, + int skipRightCols = 0); void PadColumns(std::vector>& data, int pad_left, int pad_right, uint8_t fill_value ); diff --git a/cotton_double2.pro.user b/cotton_double2.pro.user index 41a920c..79f8c93 100644 --- a/cotton_double2.pro.user +++ b/cotton_double2.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/dist/config/color_range_config.txt b/dist/config/color_range_config.txt index c8b8df9..005a063 100644 --- a/dist/config/color_range_config.txt +++ b/dist/config/color_range_config.txt @@ -12,17 +12,17 @@ blue_a_max = 22 blue_b_min = -48 blue_b_max = -8 -orange_L_min = 67 -orange_L_max = 93 -orange_a_min = -8 -orange_a_max = 8 -orange_b_min = 36 -orange_b_max = 58 +orange_L_min = 63 +orange_L_max = 78 +orange_a_min = 7 +orange_a_max = 14 +orange_b_min = 23 +orange_b_max = 47 black_L_min = 0 -black_L_max = 30 -black_a_min = -5 -black_a_max = 3 +black_L_max = 8 +black_a_min = -4 +black_a_max = 2 black_b_min = -3 black_b_max = 4 @@ -34,9 +34,9 @@ red_b_min = -80 red_b_max = 37 purple_L_min = 38 -purple_L_max = 60 +purple_L_max = 54 purple_a_min = 10 -purple_a_max = 25 +purple_a_max = 20 purple_b_min = -45 purple_b_max = 1 @@ -51,12 +51,16 @@ expansionRaidus = 1 file_delay = 1180 lab_denoising = 1 lowmac_dp = 350 -lowmac_sg = 60 -lowmac_sm = 1800 -lowmac_td = 2 -lowmac_ts = 13 +lowmac_sg = 70 +lowmac_sm = 1200 +lowmac_td = 7 +lowmac_ts = 10 machine_num = 0 -max_valves_together = 20 +max_valves_together = 18 saturation_denoising = 1 saturation_threshold = 165 +screen_left_0 = 0 +screen_left_1 = 0 +screen_right_0 = 10 +screen_right_1 = 0 sizeThreshold = 4 diff --git a/release/config/color_range_config.txt b/release/config/color_range_config.txt index 8ac9eef..005a063 100644 --- a/release/config/color_range_config.txt +++ b/release/config/color_range_config.txt @@ -59,4 +59,8 @@ machine_num = 0 max_valves_together = 18 saturation_denoising = 1 saturation_threshold = 165 +screen_left_0 = 0 +screen_left_1 = 0 +screen_right_0 = 10 +screen_right_1 = 0 sizeThreshold = 4 diff --git a/ui_widget.h b/ui_widget.h index 663e645..61901ed 100644 --- a/ui_widget.h +++ b/ui_widget.h @@ -75,10 +75,10 @@ public: QCheckBox *img_0_mirror; QLabel *camera_0_img; QWidget *tab_3; - QVBoxLayout *verticalLayout_11; + QVBoxLayout *verticalLayout_15; QLabel *label_title_3; QSpacerItem *verticalSpacer_9; - QHBoxLayout *horizontalLayout_24; + QHBoxLayout *horizontalLayout_44; QGroupBox *groupBox_4; QVBoxLayout *verticalLayout_4; QFrame *frame_3; @@ -99,7 +99,24 @@ public: QLabel *label_encoder_2; QSpinBox *spinbox_valve; QPushButton *btn_set_lower; + QFrame *frame_12; + QVBoxLayout *verticalLayout_14; + QFrame *frame_10; QVBoxLayout *verticalLayout_9; + QLabel *label_22; + QHBoxLayout *horizontalLayout_43; + QLabel *label_24; + QSpinBox *spb_screen_left_0; + QLabel *label_25; + QSpinBox *spb_screen_right_0; + QLabel *label_23; + QHBoxLayout *horizontalLayout_24; + QLabel *label_26; + QSpinBox *spb_screen_left_1; + QLabel *label_27; + QSpinBox *spb_screen_right_1; + QFrame *frame_11; + QVBoxLayout *verticalLayout_11; QLabel *label_title_4; QGroupBox *groupBox_2; QHBoxLayout *horizontalLayout_25; @@ -698,9 +715,9 @@ public: tabWidget->addTab(tab_2, QString()); tab_3 = new QWidget(); tab_3->setObjectName("tab_3"); - verticalLayout_11 = new QVBoxLayout(tab_3); - verticalLayout_11->setObjectName("verticalLayout_11"); - verticalLayout_11->setContentsMargins(-1, -1, -1, 50); + verticalLayout_15 = new QVBoxLayout(tab_3); + verticalLayout_15->setObjectName("verticalLayout_15"); + verticalLayout_15->setContentsMargins(-1, -1, -1, 40); label_title_3 = new QLabel(tab_3); label_title_3->setObjectName("label_title_3"); QFont font1; @@ -711,15 +728,14 @@ public: label_title_3->setFont(font1); label_title_3->setStyleSheet(QString::fromUtf8("font: 700 48pt \"Microsoft YaHei UI\";")); - verticalLayout_11->addWidget(label_title_3); + verticalLayout_15->addWidget(label_title_3); verticalSpacer_9 = new QSpacerItem(20, 61, QSizePolicy::Policy::Minimum, QSizePolicy::Policy::Expanding); - verticalLayout_11->addItem(verticalSpacer_9); + verticalLayout_15->addItem(verticalSpacer_9); - horizontalLayout_24 = new QHBoxLayout(); - horizontalLayout_24->setSpacing(50); - horizontalLayout_24->setObjectName("horizontalLayout_24"); + horizontalLayout_44 = new QHBoxLayout(); + horizontalLayout_44->setObjectName("horizontalLayout_44"); groupBox_4 = new QGroupBox(tab_3); groupBox_4->setObjectName("groupBox_4"); groupBox_4->setMaximumSize(QSize(900, 16777215)); @@ -843,18 +859,113 @@ public: verticalLayout_4->addWidget(btn_set_lower); - horizontalLayout_24->addWidget(groupBox_4); + horizontalLayout_44->addWidget(groupBox_4); - verticalLayout_9 = new QVBoxLayout(); + frame_12 = new QFrame(tab_3); + frame_12->setObjectName("frame_12"); + frame_12->setFrameShape(QFrame::Shape::StyledPanel); + frame_12->setFrameShadow(QFrame::Shadow::Raised); + verticalLayout_14 = new QVBoxLayout(frame_12); + verticalLayout_14->setObjectName("verticalLayout_14"); + frame_10 = new QFrame(frame_12); + frame_10->setObjectName("frame_10"); + frame_10->setFrameShape(QFrame::Shape::StyledPanel); + frame_10->setFrameShadow(QFrame::Shadow::Raised); + verticalLayout_9 = new QVBoxLayout(frame_10); verticalLayout_9->setObjectName("verticalLayout_9"); - label_title_4 = new QLabel(tab_3); + label_22 = new QLabel(frame_10); + label_22->setObjectName("label_22"); + label_22->setStyleSheet(QString::fromUtf8("font: 700 40pt \"Microsoft YaHei UI\";\n" +"border-color: rgb(0, 0, 0);")); + + verticalLayout_9->addWidget(label_22); + + horizontalLayout_43 = new QHBoxLayout(); + horizontalLayout_43->setObjectName("horizontalLayout_43"); + label_24 = new QLabel(frame_10); + label_24->setObjectName("label_24"); + label_24->setStyleSheet(QString::fromUtf8("font: 700 40pt \"Microsoft YaHei UI\";")); + + horizontalLayout_43->addWidget(label_24); + + spb_screen_left_0 = new QSpinBox(frame_10); + spb_screen_left_0->setObjectName("spb_screen_left_0"); + spb_screen_left_0->setMinimumSize(QSize(100, 61)); + spb_screen_left_0->setStyleSheet(QString::fromUtf8("font: 20pt \"Microsoft YaHei UI\";")); + + horizontalLayout_43->addWidget(spb_screen_left_0); + + label_25 = new QLabel(frame_10); + label_25->setObjectName("label_25"); + label_25->setStyleSheet(QString::fromUtf8("font: 700 40pt \"Microsoft YaHei UI\";")); + + horizontalLayout_43->addWidget(label_25); + + spb_screen_right_0 = new QSpinBox(frame_10); + spb_screen_right_0->setObjectName("spb_screen_right_0"); + spb_screen_right_0->setMinimumSize(QSize(100, 61)); + spb_screen_right_0->setStyleSheet(QString::fromUtf8("font: 20pt \"Microsoft YaHei UI\";")); + + horizontalLayout_43->addWidget(spb_screen_right_0); + + + verticalLayout_9->addLayout(horizontalLayout_43); + + label_23 = new QLabel(frame_10); + label_23->setObjectName("label_23"); + label_23->setStyleSheet(QString::fromUtf8("font: 700 40pt \"Microsoft YaHei UI\";\n" +"border-color: rgb(0, 0, 0);")); + + verticalLayout_9->addWidget(label_23); + + horizontalLayout_24 = new QHBoxLayout(); + horizontalLayout_24->setObjectName("horizontalLayout_24"); + label_26 = new QLabel(frame_10); + label_26->setObjectName("label_26"); + label_26->setStyleSheet(QString::fromUtf8("font: 700 40pt \"Microsoft YaHei UI\";")); + + horizontalLayout_24->addWidget(label_26); + + spb_screen_left_1 = new QSpinBox(frame_10); + spb_screen_left_1->setObjectName("spb_screen_left_1"); + spb_screen_left_1->setMinimumSize(QSize(100, 61)); + spb_screen_left_1->setStyleSheet(QString::fromUtf8("font: 20pt \"Microsoft YaHei UI\";")); + + horizontalLayout_24->addWidget(spb_screen_left_1); + + label_27 = new QLabel(frame_10); + label_27->setObjectName("label_27"); + label_27->setStyleSheet(QString::fromUtf8("font: 700 40pt \"Microsoft YaHei UI\";")); + + horizontalLayout_24->addWidget(label_27); + + spb_screen_right_1 = new QSpinBox(frame_10); + spb_screen_right_1->setObjectName("spb_screen_right_1"); + spb_screen_right_1->setMinimumSize(QSize(100, 61)); + spb_screen_right_1->setStyleSheet(QString::fromUtf8("font: 20pt \"Microsoft YaHei UI\";")); + + horizontalLayout_24->addWidget(spb_screen_right_1); + + + verticalLayout_9->addLayout(horizontalLayout_24); + + + verticalLayout_14->addWidget(frame_10); + + frame_11 = new QFrame(frame_12); + frame_11->setObjectName("frame_11"); + frame_11->setFrameShape(QFrame::Shape::StyledPanel); + frame_11->setFrameShadow(QFrame::Shadow::Raised); + verticalLayout_11 = new QVBoxLayout(frame_11); + verticalLayout_11->setObjectName("verticalLayout_11"); + label_title_4 = new QLabel(frame_11); label_title_4->setObjectName("label_title_4"); label_title_4->setMaximumSize(QSize(500, 16777215)); label_title_4->setStyleSheet(QString::fromUtf8("font: 20pt \"Microsoft YaHei UI\";")); - verticalLayout_9->addWidget(label_title_4); + verticalLayout_11->addWidget(label_title_4); - groupBox_2 = new QGroupBox(tab_3); + groupBox_2 = new QGroupBox(frame_11); groupBox_2->setObjectName("groupBox_2"); groupBox_2->setEnabled(false); groupBox_2->setMaximumSize(QSize(1000, 16777215)); @@ -887,9 +998,9 @@ public: horizontalLayout_25->addWidget(btn_stop_single); - verticalLayout_9->addWidget(groupBox_2); + verticalLayout_11->addWidget(groupBox_2); - groupBox_3 = new QGroupBox(tab_3); + groupBox_3 = new QGroupBox(frame_11); groupBox_3->setObjectName("groupBox_3"); groupBox_3->setEnabled(false); groupBox_3->setMaximumSize(QSize(1000, 16777215)); @@ -910,17 +1021,20 @@ public: horizontalLayout_26->addWidget(btn_stop_test); - verticalLayout_9->addWidget(groupBox_3); + verticalLayout_11->addWidget(groupBox_3); - horizontalLayout_24->addLayout(verticalLayout_9); + verticalLayout_14->addWidget(frame_11); - verticalLayout_11->addLayout(horizontalLayout_24); + horizontalLayout_44->addWidget(frame_12); + + + verticalLayout_15->addLayout(horizontalLayout_44); verticalSpacer_10 = new QSpacerItem(20, 60, QSizePolicy::Policy::Minimum, QSizePolicy::Policy::Expanding); - verticalLayout_11->addItem(verticalSpacer_10); + verticalLayout_15->addItem(verticalSpacer_10); horizontalLayout_19 = new QHBoxLayout(); horizontalLayout_19->setSpacing(40); @@ -965,7 +1079,7 @@ public: horizontalLayout_19->addWidget(btn_tab3_backtab2_4); - verticalLayout_11->addLayout(horizontalLayout_19); + verticalLayout_15->addLayout(horizontalLayout_19); tabWidget->addTab(tab_3, QString()); tab_color = new QWidget(); @@ -2018,7 +2132,7 @@ public: retranslateUi(Widget); - tabWidget->setCurrentIndex(1); + tabWidget->setCurrentIndex(2); QMetaObject::connectSlotsByName(Widget); @@ -2062,6 +2176,12 @@ public: label_encoder->setText(QCoreApplication::translate("Widget", "\347\233\270\346\234\272\350\241\214\351\242\221", nullptr)); label_encoder_2->setText(QCoreApplication::translate("Widget", "\345\226\267\351\230\200\351\242\221\347\216\207", nullptr)); btn_set_lower->setText(QCoreApplication::translate("Widget", "\344\277\235\345\255\230\345\217\202\346\225\260", nullptr)); + label_22->setText(QCoreApplication::translate("Widget", "\347\233\270\346\234\2720", nullptr)); + label_24->setText(QCoreApplication::translate("Widget", "\345\261\217\350\224\275\345\267\246", nullptr)); + label_25->setText(QCoreApplication::translate("Widget", "\345\261\217\350\224\275\345\217\263", nullptr)); + label_23->setText(QCoreApplication::translate("Widget", "\347\233\270\346\234\2721", nullptr)); + label_26->setText(QCoreApplication::translate("Widget", "\345\261\217\350\224\275\345\267\246", nullptr)); + label_27->setText(QCoreApplication::translate("Widget", "\345\261\217\350\224\275\345\217\263", nullptr)); label_title_4->setText(QCoreApplication::translate("Widget", "\345\226\267\351\230\200\346\265\213\350\257\225", nullptr)); groupBox_2->setTitle(QCoreApplication::translate("Widget", "\346\211\213\345\212\250\345\226\267\351\230\200\346\265\213\350\257\225", nullptr)); label_explosure_2->setText(QCoreApplication::translate("Widget", "\351\200\232\351\201\223", nullptr)); diff --git a/widget.cpp b/widget.cpp index 9ed49bc..816229a 100644 --- a/widget.cpp +++ b/widget.cpp @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include @@ -64,7 +64,6 @@ Widget::Widget(QWidget *parent) iniOnnx(); // iniColor(); loadConfig(getConfigDirectory()+"/color_range_config.txt"); // 读取配置文件 - check_lower_machine(); iniCamera(); // 更新界面 @@ -96,11 +95,10 @@ Widget::Widget(QWidget *parent) // 启动PLC定时器,每秒检查一次 QTimer* timer_lower = new QTimer(this); connect(timer_lower, &QTimer::timeout, this, &Widget::check_lower_machine); - timer_lower->start(10000); // 每10秒检查一次FPGA的状态 + check_lower_machine(); // 先尝试一次连接 + timer_lower->start(10000); // 每10秒检查一次FPGA的状态 ui->tabWidget->setCurrentIndex(1); - // on_btn_start_clicked(); - // 显示启动倒计时 showStartupCountdown(); } @@ -124,7 +122,7 @@ void Widget::check_lower_machine(){ } else { - this->ui->lab_plc->setStyleSheet( + this->ui->lab_fpga->setStyleSheet( "QLabel{" "background-color: red;" "color: white;" @@ -499,7 +497,6 @@ void Widget::on_btn_stop_clicked() { stop_grab(); DestoryLowMac(); - this->isCamRunning = false; // 恢复显示的图片 { @@ -570,12 +567,15 @@ void Widget::on_btn_quit_clicked() void Widget::on_btn_set_lower_clicked() { - // 硬编码参数值 lowmac_sm = ui->spinbox_maintime->value(); params["lowmac_sm"]=lowmac_sm; params["machine_num"] = ui->spinbox_machine_code->value(); params["max_valves_together"] = ui->spinbox_max_valves_together->value(); + params["screen_left_0"] = ui->spb_screen_left_0->value(); + params["screen_right_0"] = ui->spb_screen_right_0->value(); + params["screen_left_1"] = ui->spb_screen_left_1->value(); + params["screen_right_1"] = ui->spb_screen_right_1->value(); saveConfig(getConfigDirectory()+"/color_range_config.txt", params, colors); // 两个过去的参量不支持读取配置文件 @@ -586,7 +586,6 @@ void Widget::on_btn_set_lower_clicked() QMutexLocker locker(&plc_mutex); plc_connector = std::make_unique(params["machine_num"]); } - // 可选:立即更新 PLC 连接状态 heart_beat(); } @@ -596,6 +595,10 @@ void Widget::update_main_settings() ui->spinbox_machine_code->setValue(params["machine_num"]); ui->spinbox_maintime->setValue(params["lowmac_sm"]); ui->spinbox_max_valves_together->setValue(params["max_valves_together"]); + ui->spb_screen_left_0->setValue(params["screen_left_0"]); + ui->spb_screen_left_1->setValue(params["screen_left_1"]); + ui->spb_screen_right_0->setValue(params["screen_right_0"]); + ui->spb_screen_right_1->setValue(params["screen_right_1"]); } void Widget::on_btn_set_valve_clicked() @@ -822,6 +825,10 @@ void Widget::initDefaultConfig() {"lowmac_sm", lowmac_sm}, {"machine_num", params["machine_num"]}, {"max_valves_together", params["max_valves_together"]}, + {"screen_left_0", params["screen_left_0"]}, + {"screen_left_1", params["screen_left_1"]}, + {"screen_right_0", params["screen_right_0"]}, + {"screen_right_1", params["screen_right_1"]}, {"sizeThreshold",4}, {"file_delay",1180}, @@ -1155,4 +1162,3 @@ void Widget::on_tabWidget_currentChanged(int index) update_colorlist(); // 更新色彩列表 update_polar(); // 更新偏振相机界面 } - diff --git a/widget.ui b/widget.ui index 2b4fb94..6bdd546 100644 --- a/widget.ui +++ b/widget.ui @@ -47,7 +47,7 @@ background-color: rgb(228, 223, 186); - 1 + 2 true @@ -684,9 +684,9 @@ border: 4px solid black; Tab 3 - + - 50 + 40 @@ -720,10 +720,7 @@ border: 4px solid black; - - - 50 - + @@ -916,147 +913,301 @@ border-color: rgb(0, 0, 0); - - - - - - 500 - 16777215 - - - - font: 20pt "Microsoft YaHei UI"; - - - 喷阀测试 - - - - - - - false - - - - 1000 - 16777215 - - - - font: 20pt "Microsoft YaHei UI"; - - - 手动喷阀测试 - - - - 20 + + + QFrame::Shape::StyledPanel + + + QFrame::Shadow::Raised + + + + + + QFrame::Shape::StyledPanel - - - - - 100 - 16777215 - - - - 通道 - - - - - - - - 200 - 200 - - - - - - - - - 200 - 160 - - - - 测试 - - - - - - - - 200 - 160 - - - - 停止测试 - - - - - - - - - - false - - - - 1000 - 16777215 - - - - font: 20pt "Microsoft YaHei UI"; - - - 自动喷阀测试 - - - - 30 + + QFrame::Shadow::Raised - - - - - 200 - 160 - - - - 开始测试 - - - - - - - - 200 - 160 - - - - 停止测试 - - - - - - - + + + + + font: 700 40pt "Microsoft YaHei UI"; +border-color: rgb(0, 0, 0); + + + 相机0 + + + + + + + + + font: 700 40pt "Microsoft YaHei UI"; + + + 屏蔽左 + + + + + + + + 100 + 61 + + + + font: 20pt "Microsoft YaHei UI"; + + + + + + + font: 700 40pt "Microsoft YaHei UI"; + + + 屏蔽右 + + + + + + + + 100 + 61 + + + + font: 20pt "Microsoft YaHei UI"; + + + + + + + + + font: 700 40pt "Microsoft YaHei UI"; +border-color: rgb(0, 0, 0); + + + 相机1 + + + + + + + + + font: 700 40pt "Microsoft YaHei UI"; + + + 屏蔽左 + + + + + + + + 100 + 61 + + + + font: 20pt "Microsoft YaHei UI"; + + + + + + + font: 700 40pt "Microsoft YaHei UI"; + + + 屏蔽右 + + + + + + + + 100 + 61 + + + + font: 20pt "Microsoft YaHei UI"; + + + + + + + + + + + + QFrame::Shape::StyledPanel + + + QFrame::Shadow::Raised + + + + + + + 500 + 16777215 + + + + font: 20pt "Microsoft YaHei UI"; + + + 喷阀测试 + + + + + + + false + + + + 1000 + 16777215 + + + + font: 20pt "Microsoft YaHei UI"; + + + 手动喷阀测试 + + + + 20 + + + + + + 100 + 16777215 + + + + 通道 + + + + + + + + 200 + 200 + + + + + + + + + 200 + 160 + + + + 测试 + + + + + + + + 200 + 160 + + + + 停止测试 + + + + + + + + + + false + + + + 1000 + 16777215 + + + + font: 20pt "Microsoft YaHei UI"; + + + 自动喷阀测试 + + + + 30 + + + + + + 200 + 160 + + + + 开始测试 + + + + + + + + 200 + 160 + + + + 停止测试 + + + + + + + + + + +