From c967a2daecb3279af1a5a4f66e419185ee62f92c Mon Sep 17 00:00:00 2001 From: XinJiang1 <1170701029@qq.com> Date: Sat, 28 Dec 2024 19:00:19 +0800 Subject: [PATCH] napoleon version for polarization camera --- camera.cpp | 227 +++++++++++++++++++++++--- config/color_range_config.txt | 9 - cotton_double2.pro.user | 2 +- globals.cpp | 3 + globals.h | 2 + release/config/color_range_config.txt | 9 - ui_widget.h | 165 +++++++++++++------ widget.cpp | 86 +++++++--- widget.h | 2 + widget.ui | 167 +++++++++++++++++-- 10 files changed, 546 insertions(+), 126 deletions(-) diff --git a/camera.cpp b/camera.cpp index 1efbb88..950c3bc 100644 --- a/camera.cpp +++ b/camera.cpp @@ -67,6 +67,13 @@ extern int file_delay; extern int file_encoder; extern int file_valve; +//下位机参数 +extern int lowmac_dp; //偏振延迟时间 +extern int lowmac_sm; //吹气量 +extern int lowmac_ts; //模板匹配阈值 +extern int lowmac_sg; //偏振绿色通道大小阈值 +extern int lowmac_td; //偏振红色通道差值 + Timer CallBackTimer0; Timer CallBackTimer1; @@ -126,12 +133,12 @@ bool iniCamera() return 1; } -#if(GlobalDebug && DebugDetection) -// #define SAVE_PATH_resize MIL_TEXT ("C:\\Users\\Pc\\Desktop\\cotton_double2//resize.png") -#define SAVE_PATH_flip MIL_TEXT ("C:\\Users\\Pc\\Desktop\\cotton_double2//flip.png") -#define SAVE_PATH_raw MIL_TEXT ("C:\\Users\\Pc\\Desktop\\cotton_double2//raw.png") -#define SAVE_PATH_result MIL_TEXT ("C:\\Users\\Pc\\Desktop\\cotton_double2//result.png") -#endif +// #if(GlobalDebug && DebugDetection) +// // #define SAVE_PATH_resize MIL_TEXT ("C:\\Users\\Pc\\Desktop\\cotton_double2//resize.png") +// #define SAVE_PATH_flip MIL_TEXT ("C:\\Users\\Pc\\Desktop\\cotton_double2//flip.png") +// #define SAVE_PATH_raw MIL_TEXT ("C:\\Users\\Pc\\Desktop\\cotton_double2//raw.png") +// #define SAVE_PATH_result MIL_TEXT ("C:\\Users\\Pc\\Desktop\\cotton_double2//result.png") +// #endif MIL_INT ProcessingFunction0(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr) { @@ -366,9 +373,9 @@ MIL_INT ProcessingFunction1(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr) // 将图像推入识别队列 cv::Mat img = ImageUtils::mil2Mat(MimResizedestination); ImageData recognitionData; - recognitionData.camera_id = 1; + recognitionData.camera_id = camera_id; recognitionData.image = img; - g_img_Queue[1]->enqueue(recognitionData); + g_img_Queue[camera_id]->enqueue(recognitionData); } #if(GlobalDebug && DebugDetectionTime) @@ -440,7 +447,7 @@ MIL_INT ProcessingFunction1(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr) if (future_dl.wait_for(std::chrono::milliseconds(20)) == std::future_status::ready && future_dl.get()) { #if(GlobalDebug && DebugDetectionTime) - timer_detection_time.printElapsedTime("CallBack1: DL detection finished within 20ms"); + timer_detection_time.printElapsedTime("CallBack2: DL detection finished within 20ms"); timer_detection_time.restart(); #endif // 将深度学习的检测结果转换为 OpenCV Mat @@ -454,7 +461,7 @@ MIL_INT ProcessingFunction1(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr) dl_mask = matrox_mask; merged_mask = matrox_mask; #if(GlobalDebug && DebugDetectionTime) - timer_detection_time.printElapsedTime("CallBack1: DL detection error or timeout to mask"); + timer_detection_time.printElapsedTime("CallBack2: DL detection error or timeout to mask"); timer_detection_time.restart(); #endif } @@ -474,7 +481,7 @@ MIL_INT ProcessingFunction1(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr) #endif mask_1 = merged_mask; -#if(GlobalDebug && DebugDetection) +#if(GlobalDebug && DebufgDetection) MbufSave(SAVE_PATH_flip,MimFlipDedtination); // MbufSave(SAVE_PATH_resize,MimResizedestination); MbufSave(SAVE_PATH_raw,MilImage_Color0); @@ -484,23 +491,88 @@ MIL_INT ProcessingFunction1(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr) detection_ready.acquire(); vector> mask_tail; + merged_mask = ImageUtils::mergeMasks(mask_0, mask_1, dual_cam_offset_y); std::tie(merged_mask, mask_tail) = ImageUtils::extractROI(merged_mask, 0, 0, widthBlocks, heightBlocks); +#if(GlobalDebug && DebugDetection) + int row_count = 0; + std::cout << "<<<<<<<<<<<<<<<<<<<<3) + break; + } + std::cout << ">>>>>>>>>>>>>>>>>>>>Mask_0>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std:: endl; + row_count = 0; + std::cout << "<<<<<<<<<<<<<<<<<<<<3) + break; + } + std::cout << ">>>>>>>>>>>>>>>>>>>>Mask_1>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std:: endl; + row_count = 0; + std::cout << "<<<<<<<<<<<<<<<<<<<<3) + break; + } + std::cout << ">>>>>>>>>>>>>>>>>>>>merged_mask>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" << std:: endl; +#endif + // 结果后处理Post Process // 将每个结果左右扩展,扩展半径默认为1 auto mask_expaned = expandMaskHorizontally(merged_mask, expansionRaidus); // 将结果的左右补充上0,让物体大小符合要求 PadColumns(mask_expaned, padLeft, padRight, 0); + + // ======= 新增:统计 mask_expaned 里的 1 的总个数,并累加到全局变量 ======= + { + long long count_ones_this_time = 0; + for(const auto & row : mask_expaned) + { + for(uint8_t val : row) + { + count_ones_this_time += (val == 1); + } + } + g_valveActionCount += count_ones_this_time; + // 如果你想调试打印,可以 + // qDebug() << "This callback1 new triggered bits =" << count_ones_this_time + // << ", total=" << g_valveActionCount; + } + // ======= 新增结束 ======= //将mask扩展到合适发送的大小 std::vector> mask_Total = expandArray(mask_expaned,64); // save masks -#if(GlobalDebug && DebugDetection) - VectorToImg(mask_1,"C:/Users/Pc/Desktop/img/mask" + std::to_string(FuncCount1) + ".bmp"); - VectorToImg(mask_1,"C:/Users/Pc/Desktop/img/mask_ignored" + std::to_string(FuncCount1) + ".bmp"); - VectorToImg(mask_Total,"C:/Users/Pc/Desktop/img/mask_expended" + std::to_string(FuncCount1) + ".bmp"); -#endif +// #if(GlobalDebug && DebugDetection) +// VectorToImg(mask_1,"C:/Users/Pc/Desktop/img/mask" + std::to_string(FuncCount1) + ".bmp"); +// VectorToImg(mask_1,"C:/Users/Pc/Desktop/img/mask_ignored" + std::to_string(FuncCount1) + ".bmp"); +// VectorToImg(mask_Total,"C:/Users/Pc/Desktop/img/mask_expended" + std::to_string(FuncCount1) + ".bmp"); +// #endif // 发送到下位机 bool result_Low = get_valve_data(mask_Total); if(!result_Low) @@ -559,7 +631,7 @@ void lab_process_raw(const MIL_ID& inputImage, MIL_ID& outputImageLab, const std } // Inquire image properties once - MIL_ID MilSystem = MbufInquire(inputImage, M_OWNER_SYSTEM, M_NULL); + // MIL_ID MilSystem = MbufInquire(inputImage, M_OWNER_SYSTEM, M_NULL); MIL_INT SizeX = MbufInquire(inputImage, M_SIZE_X, M_NULL); MIL_INT SizeY = MbufInquire(inputImage, M_SIZE_Y, M_NULL); @@ -650,7 +722,7 @@ void lab_process_raw(const MIL_ID& inputImage, MIL_ID& outputImageLab, const std void lab_process(const MIL_ID& inputImage, MIL_ID& outputImageLab, const std::map& params) { - const std::vector colors = {"green", "blue", "orange", "black", "red", "purple", "yellow"}; + const std::vector colors = {"green", "blue", "orange", "black", "red", "purple"}; lab_process_raw(inputImage, outputImageLab, params, colors); } @@ -967,10 +1039,6 @@ bool iniLowMac() QString divide_parameter = QString("%1").arg(divide_camera, 8, 10, QChar('0')); QString sv_parameter = QString("%1").arg(divide_valve, 8, 10, QChar('0')); - // QString delay_time = QString("%1").arg(file_delay, 0, 16); // 去掉补0的部分 - // QString divide_parameter = QString("%1").arg(file_encoder, 0, 16); - // QString sv_parameter = QString("%1").arg(file_valve, 0, 16); - int len_delay = delay_time.size(); int len_divide = divide_parameter.size(); int len_sv = sv_parameter.size(); @@ -1040,6 +1108,121 @@ bool iniLowMac() delete[] valve_divide_buf; + // //下位机参数 + // int lowmac_dp = 400; //偏振延迟时间 + // int lowmac_sm = 5; //吹气量 + // int lowmac_ts = 15; //模板匹配阈值 + // int lowmac_sg = 80; //偏振绿色通道大小阈值 + // int lowmac_td = 10; //偏振红色通道差值 + //新增下位机协议 + // 将参数转换为长度为8的字符串,前面补0 + QString dp = QString("%1").arg(lowmac_dp, 8, 10, QChar('0')); + QString sm = QString("%1").arg(lowmac_sm, 8, 10, QChar('0')); + QString ts = QString("%1").arg(lowmac_ts, 8, 10, QChar('0')); + QString sg = QString("%1").arg(lowmac_sg, 8, 10, QChar('0')); + QString td = QString("%1").arg(lowmac_td, 8, 10, QChar('0')); + + int len_dp = dp.size(); + int len_sm = sm.size(); + int len_ts = ts.size(); + int len_sg = sg.size(); + int len_td = td.size(); + + QByteArray dp_byte = dp.toLatin1(); + QByteArray sm_byte = sm.toLatin1(); + QByteArray ts_byte = ts.toLatin1(); + QByteArray sg_byte = sg.toLatin1(); + QByteArray td_byte = td.toLatin1(); + + uint8_t* dp_buf = new uint8_t[len_dp + 8]; + dp_buf[0] = 0xAA; + dp_buf[1] = 0x00; + dp_buf[2] = len_dp + 2; + dp_buf[3] = 'd'; + dp_buf[4] = 'p'; + memcpy(dp_buf + 5, dp_byte.data(), len_dp); + dp_buf[len_dp + 5] = 0xFF; + dp_buf[len_dp + 6] = 0xFF; + dp_buf[len_dp + 7] = 0xBB; + + if (lower_machine->isWritable()) { + lower_machine->write((const char*)dp_buf, len_dp + 8); + } else { + cout << "Error: Unable to write to lower machine for dp parameter." << endl; + } + delete[] dp_buf; + + uint8_t* sm_buf = new uint8_t[len_sm + 8]; + sm_buf[0] = 0xAA; + sm_buf[1] = 0x00; + sm_buf[2] = len_sm + 2; + sm_buf[3] = 's'; + sm_buf[4] = 'm'; + memcpy(sm_buf + 5, sm_byte.data(), len_sm); + sm_buf[len_sm + 5] = 0xFF; + sm_buf[len_sm + 6] = 0xFF; + sm_buf[len_sm + 7] = 0xBB; + + if (lower_machine->isWritable()) { + lower_machine->write((const char*)sm_buf, len_sm + 8); + } else { + cout << "Error: Unable to write to lower machine for sm parameter." << endl; + } + delete[] sm_buf; + + uint8_t* ts_buf = new uint8_t[len_ts + 8]; + ts_buf[0] = 0xAA; + ts_buf[1] = 0x00; + ts_buf[2] = len_ts + 2; + ts_buf[3] = 't'; + ts_buf[4] = 's'; + memcpy(ts_buf + 5, ts_byte.data(), len_ts); + ts_buf[len_ts + 5] = 0xFF; + ts_buf[len_ts + 6] = 0xFF; + ts_buf[len_ts + 7] = 0xBB; + + if (lower_machine->isWritable()) { + lower_machine->write((const char*)ts_buf, len_ts + 8); + } else { + cout << "Error: Unable to write to lower machine for ts parameter." << endl; + } + delete[] ts_buf; + + uint8_t* sg_buf = new uint8_t[len_sg + 8]; + sg_buf[0] = 0xAA; + sg_buf[1] = 0x00; + sg_buf[2] = len_sg + 2; + sg_buf[3] = 's'; + sg_buf[4] = 'g'; + memcpy(sg_buf + 5, sg_byte.data(), len_sg); + sg_buf[len_sg + 5] = 0xFF; + sg_buf[len_sg + 6] = 0xFF; + sg_buf[len_sg + 7] = 0xBB; + + if (lower_machine->isWritable()) { + lower_machine->write((const char*)sg_buf, len_sg + 8); + } else { + cout << "Error: Unable to write to lower machine for sg parameter." << endl; + } + delete[] sg_buf; + + uint8_t* td_buf = new uint8_t[len_td + 8]; + td_buf[0] = 0xAA; + td_buf[1] = 0x00; + td_buf[2] = len_td + 2; + td_buf[3] = 't'; + td_buf[4] = 'd'; + memcpy(td_buf + 5, td_byte.data(), len_td); + td_buf[len_td + 5] = 0xFF; + td_buf[len_td + 6] = 0xFF; + td_buf[len_td + 7] = 0xBB; + + if (lower_machine->isWritable()) { + lower_machine->write((const char*)td_buf, len_td + 8); + } else { + cout << "Error: Unable to write to lower machine for td parameter." << endl; + } + delete[] td_buf; return 1; } diff --git a/config/color_range_config.txt b/config/color_range_config.txt index ecef269..32f1db4 100644 --- a/config/color_range_config.txt +++ b/config/color_range_config.txt @@ -46,15 +46,6 @@ purple_a_max = 22 purple_b_min = -48 purple_b_max = 1 -# yellow color parameters -yellow_L_min = 45 -yellow_L_max = 56 -yellow_a_min = -4 -yellow_a_max = 7 -yellow_b_min = 20 -yellow_b_max = 21 - - # Other parameters lab_denoising = 1 saturation_threshold = 155 diff --git a/cotton_double2.pro.user b/cotton_double2.pro.user index cd26437..14f6c5c 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 759d742..628cb55 100644 --- a/globals.cpp +++ b/globals.cpp @@ -1,6 +1,9 @@ // globals.cpp #include "globals.h" +// camera.cpp 顶部或 globals.cpp 中 +long long g_valveActionCount = 0; + // 初始化图片显示互斥锁和MIL_ID QMutex gDispPicMutex0; MIL_ID gDispCurrentPicId0 = 0; diff --git a/globals.h b/globals.h index 0d25a4d..cbfed93 100644 --- a/globals.h +++ b/globals.h @@ -16,6 +16,8 @@ #include #include "onnxrunner.h" +extern long long g_valveActionCount; + // 图片显示0 extern QMutex gDispPicMutex0; extern MIL_ID gDispCurrentPicId0; diff --git a/release/config/color_range_config.txt b/release/config/color_range_config.txt index ecef269..32f1db4 100644 --- a/release/config/color_range_config.txt +++ b/release/config/color_range_config.txt @@ -46,15 +46,6 @@ purple_a_max = 22 purple_b_min = -48 purple_b_max = 1 -# yellow color parameters -yellow_L_min = 45 -yellow_L_max = 56 -yellow_a_min = -4 -yellow_a_max = 7 -yellow_b_min = 20 -yellow_b_max = 21 - - # Other parameters lab_denoising = 1 saturation_threshold = 155 diff --git a/ui_widget.h b/ui_widget.h index 9b9d56d..ff05353 100644 --- a/ui_widget.h +++ b/ui_widget.h @@ -12,10 +12,14 @@ #include #include #include +#include #include #include #include #include +#include +#include +#include #include #include #include @@ -98,7 +102,7 @@ public: QHBoxLayout *horizontalLayout_2; QLabel *label_5; QSpacerItem *horizontalSpacer_3; - QLabel *label_6; + QLabel *label_currentDateTime; QSpacerItem *horizontalSpacer_4; QPushButton *btn_settings; QPushButton *btn_live; @@ -111,13 +115,13 @@ public: QSpacerItem *horizontalSpacer_5; QSpacerItem *verticalSpacer_3; QHBoxLayout *horizontalLayout_8; - QLabel *label_10; - QLabel *label_8; - QLabel *label_11; - QLabel *label_9; + QLabel *label_totalHours; + QLabel *label_hourUnit; + QLabel *label_totalMinutes; + QLabel *label_minuteUnit; QSpacerItem *verticalSpacer_2; QHBoxLayout *horizontalLayout_9; - QLabel *label_12; + QLabel *label_todayRunningTime; QSpacerItem *horizontalSpacer_6; QProgressBar *progressBar; QFrame *frame_valve; @@ -127,7 +131,7 @@ public: QSpacerItem *horizontalSpacer_7; QSpacerItem *verticalSpacer_4; QHBoxLayout *horizontalLayout_11; - QLabel *label_16; + QLabel *label_valve_actions; QLabel *label_17; QSpacerItem *verticalSpacer_5; QHBoxLayout *horizontalLayout_17; @@ -150,6 +154,18 @@ public: QLabel *label_20; QLabel *label_21; QSpacerItem *horizontalSpacer_12; + QWidget *tab_5; + QLineEdit *lineEdit_search; + QLabel *label_6; + QComboBox *comboBox_dateFilter; + QLabel *label_8; + QListWidget *listWidget_dateTimeline; + QListView *listView_thumbnails; + QLabel *label_imagePreview; + QLabel *label_captureTime; + QCheckBox *checkBox_dl; + QCheckBox *checkBox_matrox; + QSpinBox *spinBox_pagination; void setupUi(QWidget *Widget) { @@ -416,7 +432,9 @@ public: dl_enable_1 = new QCheckBox(frame); dl_enable_1->setObjectName("dl_enable_1"); + dl_enable_1->setEnabled(false); dl_enable_1->setStyleSheet(QString::fromUtf8("font: 12pt \"Microsoft YaHei UI\";")); + dl_enable_1->setChecked(true); horizontalLayout_4->addWidget(dl_enable_1); @@ -482,7 +500,9 @@ public: dl_enable_0 = new QCheckBox(frame_2); dl_enable_0->setObjectName("dl_enable_0"); + dl_enable_0->setEnabled(false); dl_enable_0->setStyleSheet(QString::fromUtf8("font: 12pt \"Microsoft YaHei UI\";")); + dl_enable_0->setChecked(true); horizontalLayout_5->addWidget(dl_enable_0); @@ -674,12 +694,12 @@ public: horizontalLayout_2->addItem(horizontalSpacer_3); - label_6 = new QLabel(frame_4); - label_6->setObjectName("label_6"); - label_6->setStyleSheet(QString::fromUtf8("font: 14pt \"Microsoft YaHei UI\";\n" + label_currentDateTime = new QLabel(frame_4); + label_currentDateTime->setObjectName("label_currentDateTime"); + label_currentDateTime->setStyleSheet(QString::fromUtf8("font: 14pt \"Microsoft YaHei UI\";\n" "color: rgb(170, 170, 170)")); - horizontalLayout_2->addWidget(label_6); + horizontalLayout_2->addWidget(label_currentDateTime); horizontalSpacer_4 = new QSpacerItem(672, 20, QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Minimum); @@ -790,7 +810,7 @@ public: "border-radius: 12px;\n" "padding: 20px;\n" "min-width: 300px;\n" -"box-shadow: 0px 8px 12px rgba(0, 0, 0, 0.5);}")); +"}")); frame_running_time->setFrameShape(QFrame::Shape::StyledPanel); frame_running_time->setFrameShadow(QFrame::Shadow::Raised); verticalLayout_2 = new QVBoxLayout(frame_running_time); @@ -820,48 +840,48 @@ public: horizontalLayout_8 = new QHBoxLayout(); horizontalLayout_8->setObjectName("horizontalLayout_8"); horizontalLayout_8->setSizeConstraint(QLayout::SizeConstraint::SetMinimumSize); - label_10 = new QLabel(frame_running_time); - label_10->setObjectName("label_10"); - label_10->setStyleSheet(QString::fromUtf8("font: 700 32pt \"Microsoft YaHei UI\";\n" + label_totalHours = new QLabel(frame_running_time); + label_totalHours->setObjectName("label_totalHours"); + label_totalHours->setStyleSheet(QString::fromUtf8("font: 700 32pt \"Microsoft YaHei UI\";\n" "color:rgb(105,186,210);\n" "background-color: #2d2d2d;;\n" "")); - horizontalLayout_8->addWidget(label_10); + horizontalLayout_8->addWidget(label_totalHours); - label_8 = new QLabel(frame_running_time); - label_8->setObjectName("label_8"); + label_hourUnit = new QLabel(frame_running_time); + label_hourUnit->setObjectName("label_hourUnit"); QSizePolicy sizePolicy4(QSizePolicy::Policy::Minimum, QSizePolicy::Policy::Minimum); sizePolicy4.setHorizontalStretch(0); sizePolicy4.setVerticalStretch(0); - sizePolicy4.setHeightForWidth(label_8->sizePolicy().hasHeightForWidth()); - label_8->setSizePolicy(sizePolicy4); - label_8->setStyleSheet(QString::fromUtf8("font: 700 20pt \"Microsoft YaHei UI\";\n" + sizePolicy4.setHeightForWidth(label_hourUnit->sizePolicy().hasHeightForWidth()); + label_hourUnit->setSizePolicy(sizePolicy4); + label_hourUnit->setStyleSheet(QString::fromUtf8("font: 700 20pt \"Microsoft YaHei UI\";\n" "color:rgb(105,186,210);\n" "background-color: #2d2d2d;;\n" "")); - horizontalLayout_8->addWidget(label_8); + horizontalLayout_8->addWidget(label_hourUnit); - label_11 = new QLabel(frame_running_time); - label_11->setObjectName("label_11"); - label_11->setStyleSheet(QString::fromUtf8("font: 700 32pt \"Microsoft YaHei UI\";\n" + label_totalMinutes = new QLabel(frame_running_time); + label_totalMinutes->setObjectName("label_totalMinutes"); + label_totalMinutes->setStyleSheet(QString::fromUtf8("font: 700 32pt \"Microsoft YaHei UI\";\n" "color:rgb(105,186,210);\n" "background-color: #2d2d2d;;\n" "")); - horizontalLayout_8->addWidget(label_11); + horizontalLayout_8->addWidget(label_totalMinutes); - label_9 = new QLabel(frame_running_time); - label_9->setObjectName("label_9"); - sizePolicy4.setHeightForWidth(label_9->sizePolicy().hasHeightForWidth()); - label_9->setSizePolicy(sizePolicy4); - label_9->setStyleSheet(QString::fromUtf8("font: 700 20pt \"Microsoft YaHei UI\";\n" + label_minuteUnit = new QLabel(frame_running_time); + label_minuteUnit->setObjectName("label_minuteUnit"); + sizePolicy4.setHeightForWidth(label_minuteUnit->sizePolicy().hasHeightForWidth()); + label_minuteUnit->setSizePolicy(sizePolicy4); + label_minuteUnit->setStyleSheet(QString::fromUtf8("font: 700 20pt \"Microsoft YaHei UI\";\n" "color:rgb(105,186,210);\n" "background-color: #2d2d2d;;\n" "")); - horizontalLayout_8->addWidget(label_9); + horizontalLayout_8->addWidget(label_minuteUnit); verticalLayout_2->addLayout(horizontalLayout_8); @@ -872,14 +892,14 @@ public: horizontalLayout_9 = new QHBoxLayout(); horizontalLayout_9->setObjectName("horizontalLayout_9"); - label_12 = new QLabel(frame_running_time); - label_12->setObjectName("label_12"); - label_12->setStyleSheet(QString::fromUtf8("font: 700 14pt \"Microsoft YaHei UI\";\n" + label_todayRunningTime = new QLabel(frame_running_time); + label_todayRunningTime->setObjectName("label_todayRunningTime"); + label_todayRunningTime->setStyleSheet(QString::fromUtf8("font: 700 14pt \"Microsoft YaHei UI\";\n" "color:rgb(169,169,169);\n" "background-color: #2d2d2d;;\n" "")); - horizontalLayout_9->addWidget(label_12); + horizontalLayout_9->addWidget(label_todayRunningTime); horizontalSpacer_6 = new QSpacerItem(40, 20, QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Minimum); @@ -938,7 +958,7 @@ public: "border-radius: 12px;\n" "padding: 20px;\n" "min-width: 300px;\n" -"box-shadow: 0px 8px 12px rgba(0, 0, 0, 0.5);}")); +"}")); frame_valve->setFrameShape(QFrame::Shape::StyledPanel); frame_valve->setFrameShadow(QFrame::Shadow::Raised); verticalLayout_6 = new QVBoxLayout(frame_valve); @@ -967,15 +987,15 @@ public: horizontalLayout_11 = new QHBoxLayout(); horizontalLayout_11->setObjectName("horizontalLayout_11"); - label_16 = new QLabel(frame_valve); - label_16->setObjectName("label_16"); - label_16->setStyleSheet(QString::fromUtf8("font: 700 32pt \"Microsoft YaHei UI\";\n" + label_valve_actions = new QLabel(frame_valve); + label_valve_actions->setObjectName("label_valve_actions"); + label_valve_actions->setStyleSheet(QString::fromUtf8("font: 700 32pt \"Microsoft YaHei UI\";\n" "color:rgb(105,186,210);\n" "background-color: #2d2d2d;;\n" "")); - label_16->setAlignment(Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter); + label_valve_actions->setAlignment(Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter); - horizontalLayout_11->addWidget(label_16); + horizontalLayout_11->addWidget(label_valve_actions); label_17 = new QLabel(frame_valve); label_17->setObjectName("label_17"); @@ -1048,7 +1068,7 @@ public: "border-radius: 12px;\n" "padding: 20px;\n" "min-width: 300px;\n" -"box-shadow: 0px 8px 12px rgba(0, 0, 0, 0.5);}")); +"}")); frame_history->setFrameShape(QFrame::Shape::StyledPanel); frame_history->setFrameShadow(QFrame::Shadow::Raised); verticalLayout_7 = new QVBoxLayout(frame_history); @@ -1127,13 +1147,49 @@ public: verticalLayout_8->addWidget(frame_8); tabWidget->addTab(tab_4, QString()); + tab_5 = new QWidget(); + tab_5->setObjectName("tab_5"); + lineEdit_search = new QLineEdit(tab_5); + lineEdit_search->setObjectName("lineEdit_search"); + lineEdit_search->setGeometry(QRect(180, 80, 301, 51)); + label_6 = new QLabel(tab_5); + label_6->setObjectName("label_6"); + label_6->setGeometry(QRect(80, 80, 91, 61)); + comboBox_dateFilter = new QComboBox(tab_5); + comboBox_dateFilter->setObjectName("comboBox_dateFilter"); + comboBox_dateFilter->setGeometry(QRect(600, 100, 69, 22)); + label_8 = new QLabel(tab_5); + label_8->setObjectName("label_8"); + label_8->setGeometry(QRect(550, 100, 53, 15)); + listWidget_dateTimeline = new QListWidget(tab_5); + listWidget_dateTimeline->setObjectName("listWidget_dateTimeline"); + listWidget_dateTimeline->setGeometry(QRect(40, 220, 241, 681)); + listView_thumbnails = new QListView(tab_5); + listView_thumbnails->setObjectName("listView_thumbnails"); + listView_thumbnails->setGeometry(QRect(310, 220, 621, 681)); + label_imagePreview = new QLabel(tab_5); + label_imagePreview->setObjectName("label_imagePreview"); + label_imagePreview->setGeometry(QRect(970, 220, 841, 521)); + label_captureTime = new QLabel(tab_5); + label_captureTime->setObjectName("label_captureTime"); + label_captureTime->setGeometry(QRect(1030, 800, 211, 41)); + checkBox_dl = new QCheckBox(tab_5); + checkBox_dl->setObjectName("checkBox_dl"); + checkBox_dl->setGeometry(QRect(1310, 790, 111, 51)); + checkBox_matrox = new QCheckBox(tab_5); + checkBox_matrox->setObjectName("checkBox_matrox"); + checkBox_matrox->setGeometry(QRect(1540, 790, 211, 61)); + spinBox_pagination = new QSpinBox(tab_5); + spinBox_pagination->setObjectName("spinBox_pagination"); + spinBox_pagination->setGeometry(QRect(490, 930, 42, 22)); + tabWidget->addTab(tab_5, QString()); horizontalLayout->addWidget(tabWidget); retranslateUi(Widget); - tabWidget->setCurrentIndex(2); + tabWidget->setCurrentIndex(1); QMetaObject::connectSlotsByName(Widget); @@ -1184,17 +1240,17 @@ public: btn_tab3_backtab2_2->setText(QCoreApplication::translate("Widget", "home", nullptr)); tabWidget->setTabText(tabWidget->indexOf(tab_3), QCoreApplication::translate("Widget", "Tab 3", nullptr)); label_5->setText(QCoreApplication::translate("Widget", "\351\223\266\345\212\233\346\243\211\346\262\271\346\234\272\346\242\260\346\234\211\351\231\220\345\205\254\345\217\270", nullptr)); - label_6->setText(QCoreApplication::translate("Widget", "2024-12-26 10:30AM", nullptr)); + label_currentDateTime->setText(QCoreApplication::translate("Widget", "2024-12-26 10:30AM", nullptr)); btn_settings->setText(QCoreApplication::translate("Widget", "\350\256\276\347\275\256", nullptr)); btn_live->setText(QCoreApplication::translate("Widget", "\347\233\270\346\234\272", nullptr)); label_7->setText(QCoreApplication::translate("Widget", "\350\277\220\350\241\214\346\227\266\351\227\264", nullptr)); - label_10->setText(QCoreApplication::translate("Widget", "482", nullptr)); - label_8->setText(QCoreApplication::translate("Widget", "\345\260\217\346\227\266", nullptr)); - label_11->setText(QCoreApplication::translate("Widget", "52", nullptr)); - label_9->setText(QCoreApplication::translate("Widget", "\345\210\206\351\222\237", nullptr)); - label_12->setText(QCoreApplication::translate("Widget", "\344\273\212\346\227\245\350\277\220\350\241\214\346\227\266\351\225\277:8\345\260\217\346\227\26615\345\210\206\351\222\23732\347\247\222", nullptr)); + label_totalHours->setText(QCoreApplication::translate("Widget", "482", nullptr)); + label_hourUnit->setText(QCoreApplication::translate("Widget", "\345\260\217\346\227\266", nullptr)); + label_totalMinutes->setText(QCoreApplication::translate("Widget", "52", nullptr)); + label_minuteUnit->setText(QCoreApplication::translate("Widget", "\345\210\206\351\222\237", nullptr)); + label_todayRunningTime->setText(QCoreApplication::translate("Widget", "\344\273\212\346\227\245\350\277\220\350\241\214\346\227\266\351\225\277:8\345\260\217\346\227\26615\345\210\206\351\222\23732\347\247\222", nullptr)); label_13->setText(QCoreApplication::translate("Widget", "\345\226\267\346\260\224\346\254\241\346\225\260", nullptr)); - label_16->setText(QCoreApplication::translate("Widget", "12,233,473", nullptr)); + label_valve_actions->setText(QCoreApplication::translate("Widget", "12,233,473", nullptr)); label_17->setText(QCoreApplication::translate("Widget", "\346\254\241", nullptr)); label_19->setText(QCoreApplication::translate("Widget", "\344\273\212\346\227\245\347\264\257\350\256\241\345\226\267\346\260\224\346\254\241\346\225\260:", nullptr)); label_18->setText(QCoreApplication::translate("Widget", "320\346\254\241", nullptr)); @@ -1202,6 +1258,13 @@ public: label_20->setText(QCoreApplication::translate("Widget", "\350\256\276\345\244\207\347\212\266\346\200\201: ", nullptr)); label_21->setText(QCoreApplication::translate("Widget", "\346\255\243\345\270\270\350\277\220\350\241\214", nullptr)); tabWidget->setTabText(tabWidget->indexOf(tab_4), QCoreApplication::translate("Widget", "Tab 4", nullptr)); + label_6->setText(QCoreApplication::translate("Widget", "search", nullptr)); + label_8->setText(QCoreApplication::translate("Widget", "date", nullptr)); + label_imagePreview->setText(QCoreApplication::translate("Widget", "TextLabel", nullptr)); + label_captureTime->setText(QCoreApplication::translate("Widget", "TextLabel", nullptr)); + checkBox_dl->setText(QCoreApplication::translate("Widget", "DL", nullptr)); + checkBox_matrox->setText(QCoreApplication::translate("Widget", "traditional", nullptr)); + tabWidget->setTabText(tabWidget->indexOf(tab_5), QCoreApplication::translate("Widget", "\351\241\265", nullptr)); } // retranslateUi }; diff --git a/widget.cpp b/widget.cpp index b169e51..f67cc0a 100644 --- a/widget.cpp +++ b/widget.cpp @@ -24,6 +24,12 @@ int file_delay = 1200; // 延迟时间(毫秒) int file_encoder = 12000; // 行频 int file_valve = 200; // 喷阀触发频率 +//下位机参数 +int lowmac_dp = 350; //偏振延迟时间 +int lowmac_sm = 1200; //吹气量 valve/12 = 吹气时间ms +int lowmac_ts = 8; //模板匹配阈值 +int lowmac_sg = 60; //偏振绿色通道大小阈值 +int lowmac_td = 7; //偏振红色通道差值 Widget::Widget(QWidget *parent) : QWidget(parent) , ui(new Ui::Widget) @@ -67,7 +73,7 @@ Widget::Widget(QWidget *parent) connect(timer, &QTimer::timeout, this, &Widget::refreshImage); timer->start(50); // 每50毫秒秒刷新一次界面 - // ui->tabWidget->setCurrentIndex(1); + ui->tabWidget->setCurrentIndex(1); } Widget::~Widget() @@ -99,6 +105,39 @@ void Widget::refreshImage() this->ui->dl_enable_1->setEnabled(!this->isCamRunning); this->ui->tra_enable_0->setEnabled(!this->isCamRunning); this->ui->tra_enable_1->setEnabled(!this->isCamRunning); + // + QDateTime now = QDateTime::currentDateTime(); + ui->label_currentDateTime->setText(now.toString("yyyy-MM-dd hh:mm:ss")); + + if (this->isCamRunning) + { + // 计算启动至今的秒数差 + qint64 elapsedSeconds = this->startTime.secsTo(now); + // 转化为小时、分钟、秒 + qint64 hours = elapsedSeconds / 3600; + qint64 minutes = (elapsedSeconds % 3600) / 60; + qint64 seconds = elapsedSeconds % 60; + + // 将“总运行时间”的小时/分钟分别更新到 UI + ui->label_totalHours->setText(QString::number(hours)); // e.g. "482" + ui->label_totalMinutes->setText(QString::number(minutes)); // e.g. "52" + + // 拼接“今日运行时长”一句话 (根据实际需求,可直接使用上面 hours、minutes、seconds) + QString todayRunStr = QString("今日运行时长:%1小时%2分钟%3秒") + .arg(hours) + .arg(minutes) + .arg(seconds); + ui->label_todayRunningTime->setText(todayRunStr); + } + else + { + // 如果设备没在运行,UI可以显示默认内容或保持不变 + // 下面示例:将运行时长重置为 0 + ui->label_totalHours->setText("0"); + ui->label_totalMinutes->setText("0"); + ui->label_todayRunningTime->setText("今日运行时长:0小时0分钟0秒"); + } + // refresh info QString info; if(this->isCamRunning) @@ -115,6 +154,7 @@ void Widget::refreshImage() info = "停止"; }; this->ui->lab_info->setText(info); + ui->label_valve_actions->setText(QLocale(QLocale::English).toString(g_valveActionCount)); } void Widget::refreshSingleImage(int camera_id, bool overlay_traditional_result, bool overlay_dl_result, bool mirror) @@ -154,7 +194,6 @@ void Widget::refreshSingleImage(int camera_id, bool overlay_traditional_result, if (current_id == 0) return; - std::vector> dl_mask; std::vector> traditional_mask; { @@ -294,6 +333,7 @@ void Widget::on_btn_start_clicked() g_traditional_enable[0] = !this->ui->tra_enable_0->isChecked(); g_traditional_enable[1] = !this->ui->tra_enable_1->isChecked(); this->isCamRunning = true; + this->startTime = QDateTime::currentDateTime(); // 从这里开始计算设备运行时间 // 热身两个工作者 for(int i = 0; i < 2; ++i) { @@ -337,29 +377,29 @@ void Widget::on_btn_take_photos_released() void Widget::on_btn_quit_clicked() { - // 停止检测工作者线程 - for(int i = 0; i < 2; ++i) - { - g_recognitionRunning[i]->store(false); - g_img_Queue[i]->stop(); // 停止队列以唤醒线程 - } + // // 停止检测工作者线程 + // for(int i = 0; i < 2; ++i) + // { + // g_recognitionRunning[i]->store(false); + // g_img_Queue[i]->stop(); // 停止队列以唤醒线程 + // } - // 等待检测工作者线程结束 - for(int i = 0; i < 2; ++i) - { - if(g_recognitionThread[i] && g_recognitionThread[i]->joinable()) - { - g_recognitionThread[i]->join(); - delete g_recognitionThread[i]; - g_recognitionThread[i] = nullptr; - } + // // 等待检测工作者线程结束 + // for(int i = 0; i < 2; ++i) + // { + // if(g_recognitionThread[i] && g_recognitionThread[i]->joinable()) + // { + // g_recognitionThread[i]->join(); + // delete g_recognitionThread[i]; + // g_recognitionThread[i] = nullptr; + // } - if(g_recognitionRunning[i]) - { - delete g_recognitionRunning[i]; - g_recognitionRunning[i] = nullptr; - } - } + // if(g_recognitionRunning[i]) + // { + // delete g_recognitionRunning[i]; + // g_recognitionRunning[i] = nullptr; + // } + // } DestoryCamera(); DestoryLowMac(); diff --git a/widget.h b/widget.h index 511a457..e28bbdc 100644 --- a/widget.h +++ b/widget.h @@ -59,6 +59,8 @@ private: bool isCamRunning; + QDateTime startTime; // 记录点“开始分选”的时间,用于计算总运行时长 + QThread storageThread; // 存储线程 StorageWorker* storageWorker; // 存储工作者 diff --git a/widget.ui b/widget.ui index f676136..06b512e 100644 --- a/widget.ui +++ b/widget.ui @@ -35,7 +35,7 @@ background-color: rgb(228, 223, 186); - 2 + 1 true @@ -412,12 +412,18 @@ QPushButton#btn_quit:disabled { + + false + font: 12pt "Microsoft YaHei UI"; 屏蔽深度学习 + + true + @@ -525,12 +531,18 @@ border: 4px solid black; + + false + font: 12pt "Microsoft YaHei UI"; 屏蔽深度学习 + + true + @@ -962,7 +974,7 @@ color: rgb(255, 255, 255) - + font: 14pt "Microsoft YaHei UI"; color: rgb(170, 170, 170) @@ -1141,7 +1153,7 @@ border: 3px solid #444; border-radius: 12px; padding: 20px; min-width: 300px; -box-shadow: 0px 8px 12px rgba(0, 0, 0, 0.5);} +} QFrame::Shape::StyledPanel @@ -1199,7 +1211,7 @@ background-color: #2d2d2d;; QLayout::SizeConstraint::SetMinimumSize - + font: 700 32pt "Microsoft YaHei UI"; color:rgb(105,186,210); @@ -1212,7 +1224,7 @@ background-color: #2d2d2d;; - + 0 @@ -1231,7 +1243,7 @@ background-color: #2d2d2d;; - + font: 700 32pt "Microsoft YaHei UI"; color:rgb(105,186,210); @@ -1244,7 +1256,7 @@ background-color: #2d2d2d;; - + 0 @@ -1280,7 +1292,7 @@ background-color: #2d2d2d;; - + font: 700 14pt "Microsoft YaHei UI"; color:rgb(169,169,169); @@ -1371,7 +1383,7 @@ border: 3px solid #444; border-radius: 12px; padding: 20px; min-width: 300px; -box-shadow: 0px 8px 12px rgba(0, 0, 0, 0.5);} +} QFrame::Shape::StyledPanel @@ -1426,7 +1438,7 @@ background-color: #2d2d2d;; - + font: 700 32pt "Microsoft YaHei UI"; color:rgb(105,186,210); @@ -1559,7 +1571,7 @@ border: 3px solid #444; border-radius: 12px; padding: 20px; min-width: 300px; -box-shadow: 0px 8px 12px rgba(0, 0, 0, 0.5);} +} QFrame::Shape::StyledPanel @@ -1691,6 +1703,139 @@ color: rgb(144,255,60);r'g'b + + + + + + + + 180 + 80 + 301 + 51 + + + + + + + 80 + 80 + 91 + 61 + + + + search + + + + + + 600 + 100 + 69 + 22 + + + + + + + 550 + 100 + 53 + 15 + + + + date + + + + + + 40 + 220 + 241 + 681 + + + + + + + 310 + 220 + 621 + 681 + + + + + + + 970 + 220 + 841 + 521 + + + + TextLabel + + + + + + 1030 + 800 + 211 + 41 + + + + TextLabel + + + + + + 1310 + 790 + 111 + 51 + + + + DL + + + + + + 1540 + 790 + 211 + 61 + + + + traditional + + + + + + 490 + 930 + 42 + 22 + + + +