安欣阳的飞机票

This commit is contained in:
XinJiang1 2024-12-25 03:23:44 +08:00
parent 8405ee3d1b
commit 79789ac53f
10 changed files with 749 additions and 485 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

@ -3,9 +3,9 @@
#include <QTimer> #include <QTimer>
// Debug Options // Debug Options
#define GlobalDebug 0 // 全局是否允许打印Debug信息打印会拖慢处理时间 #define GlobalDebug 1 // 全局是否允许打印Debug信息打印会拖慢处理时间
#define DebugDetection 0 // 注意开启这个编译选项会导致图片存储, 处理时间会很慢 #define DebugDetection 0 // 注意开启这个编译选项会导致图片存储, 处理时间会很慢
#define DebugDetectionTime 0 // 是否打印处理时间 #define DebugDetectionTime 1 // 是否打印处理时间
#define DebugLowerMacCOM 0 // 是否打印和下位机通讯的相关信息 #define DebugLowerMacCOM 0 // 是否打印和下位机通讯的相关信息
camera::camera() {} camera::camera() {}
@ -145,6 +145,8 @@ MIL_INT ProcessingFunction0(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
{ {
#if(GlobalDebug) #if(GlobalDebug)
qDebug()<<"CallBack1"; qDebug()<<"CallBack1";
Timer call_back_timer0;
call_back_timer0.restart();
#endif #endif
int camera_id = 0; int camera_id = 0;
#if(GlobalDebug && DebugDetectionTime) #if(GlobalDebug && DebugDetectionTime)
@ -155,7 +157,6 @@ MIL_INT ProcessingFunction0(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
{ {
QMutexLocker locker(&gDispPicMutex0); QMutexLocker locker(&gDispPicMutex0);
gDispCurrentPicId0 = ModifiedBufferId0; gDispCurrentPicId0 = ModifiedBufferId0;
} }
#if(GlobalDebug && DebugDetectionTime) #if(GlobalDebug && DebugDetectionTime)
@ -173,7 +174,6 @@ MIL_INT ProcessingFunction0(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
data.camera_id = 0; data.camera_id = 0;
data.image = img.clone(); // 确保图像数据被复制 data.image = img.clone(); // 确保图像数据被复制
g_storageQueue.enqueue(data); g_storageQueue.enqueue(data);
FuncCount0++;
#if(GlobalDebug && DebugDetectionTime) #if(GlobalDebug && DebugDetectionTime)
qDebug() << "CallBack1: push image to storage queue"; qDebug() << "CallBack1: push image to storage queue";
#endif #endif
@ -196,17 +196,23 @@ MIL_INT ProcessingFunction0(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
cv::Mat img = ImageUtils::mil2Mat(MimFlipDedtination); cv::Mat img = ImageUtils::mil2Mat(MimFlipDedtination);
// 将图像推入识别队列 // 将图像推入识别队列
if(g_dl_enable[camera_id])
{
ImageData recognitionData; ImageData recognitionData;
recognitionData.camera_id = camera_id; recognitionData.camera_id = camera_id;
recognitionData.image = img; recognitionData.image = img;
g_img_Queue[camera_id]->enqueue(recognitionData); g_img_Queue[camera_id]->enqueue(recognitionData);
}
#if(GlobalDebug && DebugDetectionTime) #if(GlobalDebug && DebugDetectionTime)
timer_detection_time.printElapsedTime("CallBack1: High sat detection mirror and push to DL"); timer_detection_time.printElapsedTime("CallBack1: High sat detection mirror and push to DL");
timer_detection_time.restart(); timer_detection_time.restart();
#endif #endif
//艳丽检测mask //艳丽检测mask
if(g_traditional_enable[camera_id])
{
high_sat_detect(MimFlipDedtination, detection_result0, params); high_sat_detect(MimFlipDedtination, detection_result0, params);
}
#if(GlobalDebug && DebugDetectionTime) #if(GlobalDebug && DebugDetectionTime)
timer_detection_time.printElapsedTime("CallBack1: High sat detection finish"); timer_detection_time.printElapsedTime("CallBack1: High sat detection finish");
@ -223,6 +229,8 @@ MIL_INT ProcessingFunction0(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
std::vector<std::vector<uint8_t>> dl_mask; std::vector<std::vector<uint8_t>> dl_mask;
ImageData dl_data; ImageData dl_data;
if(g_dl_enable[camera_id])
{
if(!g_result_Queue[camera_id]->dequeue(dl_data)) if(!g_result_Queue[camera_id]->dequeue(dl_data))
{ {
qWarning() << "CallBack1: Receive empty result from Onnx for camera" << camera_id; qWarning() << "CallBack1: Receive empty result from Onnx for camera" << camera_id;
@ -244,13 +252,19 @@ MIL_INT ProcessingFunction0(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
timer_detection_time.restart(); timer_detection_time.restart();
#endif #endif
} }
}
else
{
dl_mask = matrox_mask;
merged_mask = matrox_mask;
}
// Update the current Img MIl id // Update the current Img MIl id
// 更新持久化存储 // 更新持久化存储
{ // {
QMutexLocker locker(&g_detection_result[camera_id].mutex); // QMutexLocker locker(&g_detection_result[camera_id].mutex);
g_detection_result[camera_id].dl_mask = dl_mask; // g_detection_result[camera_id].dl_mask = dl_mask;
g_detection_result[camera_id].traditional_mask = matrox_mask; // g_detection_result[camera_id].traditional_mask = matrox_mask;
} // }
#if(GlobalDebug && DebugDetectionTime) #if(GlobalDebug && DebugDetectionTime)
timer_detection_time.printElapsedTime("CallBack1: Push result to g_detection_result"); timer_detection_time.printElapsedTime("CallBack1: Push result to g_detection_result");
timer_detection_time.restart(); timer_detection_time.restart();
@ -258,6 +272,9 @@ MIL_INT ProcessingFunction0(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
mask_0 = merged_mask; mask_0 = merged_mask;
detection_ready.release(); detection_ready.release();
MbufFree(detection_result0); MbufFree(detection_result0);
#if(GlobalDebug && DebugDetectionTime)
call_back_timer0.printElapsedTime("CallBack1: Total time spent: ");
#endif
return 0; return 0;
} }
@ -266,6 +283,8 @@ MIL_INT ProcessingFunction1(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
{ {
#if(GlobalDebug) #if(GlobalDebug)
qDebug()<<"CallBack2"; qDebug()<<"CallBack2";
Timer call_back_timer1;
call_back_timer1.restart();
#endif #endif
int camera_id = 1; int camera_id = 1;
#if(GlobalDebug && DebugDetectionTime) #if(GlobalDebug && DebugDetectionTime)
@ -293,7 +312,6 @@ MIL_INT ProcessingFunction1(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
data.camera_id = 1; data.camera_id = 1;
data.image = img.clone(); // 确保图像数据被复制 data.image = img.clone(); // 确保图像数据被复制
g_storageQueue.enqueue(data); g_storageQueue.enqueue(data);
FuncCount1++;
#if(GlobalDebug && DebugDetectionTime) #if(GlobalDebug && DebugDetectionTime)
qDebug() << "CallBack2: push image to storage queue"; qDebug() << "CallBack2: push image to storage queue";
#endif #endif
@ -310,20 +328,25 @@ MIL_INT ProcessingFunction1(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
timer_detection_time.restart(); timer_detection_time.restart();
#endif #endif
if(g_dl_enable[camera_id])
{
// 将图像推入识别队列 // 将图像推入识别队列
cv::Mat img = ImageUtils::mil2Mat(MimResizedestination); cv::Mat img = ImageUtils::mil2Mat(MimResizedestination);
ImageData recognitionData; ImageData recognitionData;
recognitionData.camera_id = 1; recognitionData.camera_id = 1;
recognitionData.image = img; recognitionData.image = img;
g_img_Queue[1]->enqueue(recognitionData); g_img_Queue[1]->enqueue(recognitionData);
}
#if(GlobalDebug && DebugDetectionTime) #if(GlobalDebug && DebugDetectionTime)
timer_detection_time.printElapsedTime("CallBack2: Without mirror and push to DL"); timer_detection_time.printElapsedTime("CallBack2: Without mirror and push to DL");
timer_detection_time.restart(); timer_detection_time.restart();
#endif #endif
// 艳丽检测mask // 艳丽检测mask
if(g_traditional_enable[camera_id])
{
high_sat_detect(MimResizedestination, detection_result1, params); high_sat_detect(MimResizedestination, detection_result1, params);
}
#if(GlobalDebug && DebugDetectionTime) #if(GlobalDebug && DebugDetectionTime)
timer_detection_time.printElapsedTime("CallBack2: High sat detection finish"); timer_detection_time.printElapsedTime("CallBack2: High sat detection finish");
@ -341,7 +364,8 @@ MIL_INT ProcessingFunction1(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
std::vector<std::vector<uint8_t>> merged_mask; std::vector<std::vector<uint8_t>> merged_mask;
std::vector<std::vector<uint8_t>> dl_mask; std::vector<std::vector<uint8_t>> dl_mask;
ImageData dl_data; ImageData dl_data;
if(g_dl_enable[camera_id])
{
if(!g_result_Queue[camera_id]->dequeue(dl_data)) if(!g_result_Queue[camera_id]->dequeue(dl_data))
{ {
qWarning() << "Receive empty result from Onnx for camera" << camera_id; qWarning() << "Receive empty result from Onnx for camera" << camera_id;
@ -363,14 +387,14 @@ MIL_INT ProcessingFunction1(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
timer_detection_time.restart(); timer_detection_time.restart();
#endif #endif
} }
}else
{
dl_mask = matrox_mask;
merged_mask = matrox_mask;
}
// Update the current Img MIl id // Update the current Img MIl id
// 更新持久化存储 // 更新持久化存储
{
QMutexLocker locker(&g_detection_result[camera_id].mutex);
g_detection_result[camera_id].dl_mask = dl_mask;
g_detection_result[camera_id].traditional_mask = matrox_mask;
}
#if(GlobalDebug && DebugDetectionTime) #if(GlobalDebug && DebugDetectionTime)
timer_detection_time.printElapsedTime("CallBack2: Push result to g_detection_result"); timer_detection_time.printElapsedTime("CallBack2: Push result to g_detection_result");
timer_detection_time.restart(); timer_detection_time.restart();
@ -410,11 +434,10 @@ MIL_INT ProcessingFunction1(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
qWarning()<<"下位机发送失败"; qWarning()<<"下位机发送失败";
} }
#if(GlobalDebug && DebugDetectionTime)
timer_detection_time.printElapsedTime("Time of Processing From Get into Ca"
"..0llBack to Sent to Lower Mac");
#endif
MbufFree(detection_result1); MbufFree(detection_result1);
#if(GlobalDebug && DebugDetectionTime)
call_back_timer1.printElapsedTime("CallBack2: Total time spent: ");
#endif
return 0; return 0;
} }

View File

@ -96,6 +96,12 @@ extern std::map<std::string, int> params;
void read_params_from_file(const std::string& filename, std::map<std::string, int>& params) ; void read_params_from_file(const std::string& filename, std::map<std::string, int>& params) ;
pair<vector<vector<uint8_t>>, vector<vector<uint8_t>>> applyRowRangeDelay(
const vector<vector<uint8_t>>& mask,
const vector<vector<uint8_t>>& tail,
int rowRange
);
pair<vector<vector<uint8_t>>, vector<vector<uint8_t>>> generateMaskWithTail( pair<vector<vector<uint8_t>>, vector<vector<uint8_t>>> generateMaskWithTail(
const MIL_ID& inputImg, const MIL_ID& inputImg,
const vector<vector<uint8_t>>& tail, const vector<vector<uint8_t>>& tail,

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 15.0.0, 2024-12-23T18:29:43. --> <!-- Written by QtCreator 15.0.0, 2024-12-25T01:32:34. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
@ -140,7 +140,7 @@
</valuemap> </valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1"> <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:\Users\Administrator\Documents\cotton_double</value> <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:\Users\Administrator\Documents\cotton_double</value>
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">C:/Users/Administrator/Documents/cotton_double/build/Desktop_Qt_6_7_3_MSVC2022_64bit-Release</value> <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory.shadowDir">C:/Users/Administrator/Documents/cotton_double</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>

View File

@ -34,6 +34,9 @@ std::thread* g_recognitionThread[2] = { nullptr, nullptr };
// 初始化线程控制变量指针 // 初始化线程控制变量指针
std::atomic<bool>* g_recognitionRunning[2] = { nullptr, nullptr }; std::atomic<bool>* g_recognitionRunning[2] = { nullptr, nullptr };
bool g_dl_enable[2] = { true, true };
bool g_traditional_enable[2] = { true, true };
// 初始化全局ONNXRunner实例数组 // 初始化全局ONNXRunner实例数组
ONNXRunner* g_runner_array[2] = { nullptr, nullptr }; ONNXRunner* g_runner_array[2] = { nullptr, nullptr };

View File

@ -34,7 +34,8 @@ extern MIL_ID gMask1;
// 检测准备信号量 // 检测准备信号量
extern QSemaphore detection_ready; extern QSemaphore detection_ready;
extern bool g_dl_enable[2];
extern bool g_traditional_enable[2];
// 获取保存目录和配置目录函数 // 获取保存目录和配置目录函数
QString getSaveDirectory(); QString getSaveDirectory();

View File

@ -60,6 +60,8 @@ public:
QHBoxLayout *horizontalLayout_4; QHBoxLayout *horizontalLayout_4;
QLabel *label_2; QLabel *label_2;
QSpacerItem *horizontalSpacer; QSpacerItem *horizontalSpacer;
QCheckBox *dl_enable_1;
QCheckBox *tra_enable_1;
QCheckBox *mtx_1_overlay; QCheckBox *mtx_1_overlay;
QCheckBox *dl_1_overlay; QCheckBox *dl_1_overlay;
QCheckBox *img_1_mirror; QCheckBox *img_1_mirror;
@ -68,6 +70,8 @@ public:
QHBoxLayout *horizontalLayout_5; QHBoxLayout *horizontalLayout_5;
QLabel *label_4; QLabel *label_4;
QSpacerItem *horizontalSpacer_2; QSpacerItem *horizontalSpacer_2;
QCheckBox *dl_enable_0;
QCheckBox *tra_enable_0;
QCheckBox *mtx_0_overlay; QCheckBox *mtx_0_overlay;
QCheckBox *dl_0_overlay; QCheckBox *dl_0_overlay;
QCheckBox *img_0_mirror; QCheckBox *img_0_mirror;
@ -256,16 +260,29 @@ public:
horizontalLayout_4->addItem(horizontalSpacer); horizontalLayout_4->addItem(horizontalSpacer);
dl_enable_1 = new QCheckBox(frame);
dl_enable_1->setObjectName("dl_enable_1");
dl_enable_1->setStyleSheet(QString::fromUtf8("font: 12pt \"Microsoft YaHei UI\";"));
horizontalLayout_4->addWidget(dl_enable_1);
tra_enable_1 = new QCheckBox(frame);
tra_enable_1->setObjectName("tra_enable_1");
tra_enable_1->setEnabled(false);
tra_enable_1->setStyleSheet(QString::fromUtf8("font: 12pt \"Microsoft YaHei UI\";"));
horizontalLayout_4->addWidget(tra_enable_1);
mtx_1_overlay = new QCheckBox(frame); mtx_1_overlay = new QCheckBox(frame);
mtx_1_overlay->setObjectName("mtx_1_overlay"); mtx_1_overlay->setObjectName("mtx_1_overlay");
mtx_1_overlay->setEnabled(true); mtx_1_overlay->setEnabled(false);
mtx_1_overlay->setStyleSheet(QString::fromUtf8("font: 12pt \"Microsoft YaHei UI\";")); mtx_1_overlay->setStyleSheet(QString::fromUtf8("font: 12pt \"Microsoft YaHei UI\";"));
horizontalLayout_4->addWidget(mtx_1_overlay); horizontalLayout_4->addWidget(mtx_1_overlay);
dl_1_overlay = new QCheckBox(frame); dl_1_overlay = new QCheckBox(frame);
dl_1_overlay->setObjectName("dl_1_overlay"); dl_1_overlay->setObjectName("dl_1_overlay");
dl_1_overlay->setEnabled(true); dl_1_overlay->setEnabled(false);
dl_1_overlay->setStyleSheet(QString::fromUtf8("font: 12pt \"Microsoft YaHei UI\";")); dl_1_overlay->setStyleSheet(QString::fromUtf8("font: 12pt \"Microsoft YaHei UI\";"));
horizontalLayout_4->addWidget(dl_1_overlay); horizontalLayout_4->addWidget(dl_1_overlay);
@ -308,16 +325,29 @@ public:
horizontalLayout_5->addItem(horizontalSpacer_2); horizontalLayout_5->addItem(horizontalSpacer_2);
dl_enable_0 = new QCheckBox(frame_2);
dl_enable_0->setObjectName("dl_enable_0");
dl_enable_0->setStyleSheet(QString::fromUtf8("font: 12pt \"Microsoft YaHei UI\";"));
horizontalLayout_5->addWidget(dl_enable_0);
tra_enable_0 = new QCheckBox(frame_2);
tra_enable_0->setObjectName("tra_enable_0");
tra_enable_0->setEnabled(false);
tra_enable_0->setStyleSheet(QString::fromUtf8("font: 12pt \"Microsoft YaHei UI\";"));
horizontalLayout_5->addWidget(tra_enable_0);
mtx_0_overlay = new QCheckBox(frame_2); mtx_0_overlay = new QCheckBox(frame_2);
mtx_0_overlay->setObjectName("mtx_0_overlay"); mtx_0_overlay->setObjectName("mtx_0_overlay");
mtx_0_overlay->setEnabled(true); mtx_0_overlay->setEnabled(false);
mtx_0_overlay->setStyleSheet(QString::fromUtf8("font: 12pt \"Microsoft YaHei UI\";")); mtx_0_overlay->setStyleSheet(QString::fromUtf8("font: 12pt \"Microsoft YaHei UI\";"));
horizontalLayout_5->addWidget(mtx_0_overlay); horizontalLayout_5->addWidget(mtx_0_overlay);
dl_0_overlay = new QCheckBox(frame_2); dl_0_overlay = new QCheckBox(frame_2);
dl_0_overlay->setObjectName("dl_0_overlay"); dl_0_overlay->setObjectName("dl_0_overlay");
dl_0_overlay->setEnabled(true); dl_0_overlay->setEnabled(false);
dl_0_overlay->setStyleSheet(QString::fromUtf8("font: 12pt \"Microsoft YaHei UI\";")); dl_0_overlay->setStyleSheet(QString::fromUtf8("font: 12pt \"Microsoft YaHei UI\";"));
horizontalLayout_5->addWidget(dl_0_overlay); horizontalLayout_5->addWidget(dl_0_overlay);
@ -475,11 +505,15 @@ public:
btn_stop->setText(QCoreApplication::translate("Widget", "\345\201\234\346\255\242\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));
btn_quit->setText(QCoreApplication::translate("Widget", "\351\200\200\345\207\272\347\263\273\347\273\237", nullptr)); btn_quit->setText(QCoreApplication::translate("Widget", "\351\200\200\345\207\272\347\263\273\347\273\237", nullptr));
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_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));
dl_enable_1->setText(QCoreApplication::translate("Widget", "\345\261\217\350\224\275\346\267\261\345\272\246\345\255\246\344\271\240", nullptr));
tra_enable_1->setText(QCoreApplication::translate("Widget", "\345\261\217\350\224\275\350\211\263\344\270\275\346\243\200\346\265\213", nullptr));
mtx_1_overlay->setText(QCoreApplication::translate("Widget", "\350\211\262\346\243\200\347\273\223\346\236\234", nullptr)); mtx_1_overlay->setText(QCoreApplication::translate("Widget", "\350\211\262\346\243\200\347\273\223\346\236\234", nullptr));
dl_1_overlay->setText(QCoreApplication::translate("Widget", "\346\231\272\346\243\200\347\273\223\346\236\234", nullptr)); dl_1_overlay->setText(QCoreApplication::translate("Widget", "\346\231\272\346\243\200\347\273\223\346\236\234", nullptr));
img_1_mirror->setText(QCoreApplication::translate("Widget", "\345\233\276\347\211\207\351\225\234\345\203\217", nullptr)); img_1_mirror->setText(QCoreApplication::translate("Widget", "\345\233\276\347\211\207\351\225\234\345\203\217", nullptr));
camera_1_img->setText(QString()); 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)); 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));
dl_enable_0->setText(QCoreApplication::translate("Widget", "\345\261\217\350\224\275\346\267\261\345\272\246\345\255\246\344\271\240", nullptr));
tra_enable_0->setText(QCoreApplication::translate("Widget", "\345\261\217\350\224\275\350\211\263\344\270\275\346\243\200\346\265\213", nullptr));
mtx_0_overlay->setText(QCoreApplication::translate("Widget", "\350\211\262\346\243\200\347\273\223\346\236\234", nullptr)); mtx_0_overlay->setText(QCoreApplication::translate("Widget", "\350\211\262\346\243\200\347\273\223\346\236\234", nullptr));
dl_0_overlay->setText(QCoreApplication::translate("Widget", "\346\231\272\346\243\200\347\273\223\346\236\234", nullptr)); dl_0_overlay->setText(QCoreApplication::translate("Widget", "\346\231\272\346\243\200\347\273\223\346\236\234", nullptr));
img_0_mirror->setText(QCoreApplication::translate("Widget", "\345\233\276\347\211\207\351\225\234\345\203\217", nullptr)); img_0_mirror->setText(QCoreApplication::translate("Widget", "\345\233\276\347\211\207\351\225\234\345\203\217", nullptr));

View File

@ -78,6 +78,11 @@ void Widget::refreshImage()
this->ui->btn_start->setEnabled(!this->isCamRunning); this->ui->btn_start->setEnabled(!this->isCamRunning);
this->ui->btn_stop->setEnabled(this->isCamRunning); this->ui->btn_stop->setEnabled(this->isCamRunning);
this->ui->btn_take_photos->setEnabled(this->isCamRunning); this->ui->btn_take_photos->setEnabled(this->isCamRunning);
// refresh checkouts
this->ui->dl_enable_0->setEnabled(!this->isCamRunning);
this->ui->dl_enable_1->setEnabled(!this->isCamRunning);
this->ui->tra_enable_0->setEnabled(!this->isCamRunning);
this->ui->tra_enable_1->setEnabled(!this->isCamRunning);
// refresh info // refresh info
QString info; QString info;
if(this->isCamRunning) if(this->isCamRunning)
@ -124,7 +129,8 @@ void Widget::refreshSingleImage(int camera_id, bool overlay_traditional_result,
// 将MIL图像转换为OpenCV Mat // 将MIL图像转换为OpenCV Mat
cv::Mat img = ImageUtils::mil2Mat(current_id); cv::Mat img = ImageUtils::mil2Mat(current_id);
if (img.empty()) { if (img.empty())
{
qWarning() << "Failed to convert MIL image to Mat for Camera ID:" << camera_id; qWarning() << "Failed to convert MIL image to Mat for Camera ID:" << camera_id;
return; return;
} }
@ -142,7 +148,7 @@ void Widget::refreshSingleImage(int camera_id, bool overlay_traditional_result,
} }
// 如果需要叠加结果,处理掩码 // 如果需要叠加结果,处理掩码
if (overlay_dl_result) if (overlay_dl_result && g_dl_enable[camera_id])
{ {
if (!dl_mask.empty() && !dl_mask[0].empty()) if (!dl_mask.empty() && !dl_mask[0].empty())
{ {
@ -180,7 +186,7 @@ void Widget::refreshSingleImage(int camera_id, bool overlay_traditional_result,
} }
} }
if (overlay_traditional_result) if (overlay_traditional_result & g_traditional_enable[camera_id])
{ {
if (!traditional_mask.empty() && !traditional_mask[0].empty()) if (!traditional_mask.empty() && !traditional_mask[0].empty())
{ {
@ -237,86 +243,6 @@ void Widget::refreshSingleImage(int camera_id, bool overlay_traditional_result,
// 更新UI标签 // 更新UI标签
cameraLabels[camera_id]->setPixmap(scaledPixmap); cameraLabels[camera_id]->setPixmap(scaledPixmap);
// // 获取当前摄像头的数据
// cv::Mat original_image, dl_mask, traditional_mask;
// {
// QMutexLocker locker(&camera_data[camera_id].mutex);
// original_image = camera_data[camera_id].original_image.clone();
// dl_mask = camera_data[camera_id].dl_mask.clone();
// traditional_mask = camera_data[camera_id].traditional_mask.clone();
// }
// if (original_image.empty()) {
// qWarning() << "Original image is empty for Camera ID:" << camera_id;
// return;
// }
// // 创建一个可编辑的副本
// cv::Mat display_img = original_image.clone();
// // 确保掩膜为单通道
// if (!dl_mask.empty() && dl_mask.channels() > 1) {
// cv::cvtColor(dl_mask, dl_mask, cv::COLOR_BGR2GRAY);
// }
// if (!traditional_mask.empty() && traditional_mask.channels() > 1) {
// cv::cvtColor(traditional_mask, traditional_mask, cv::COLOR_BGR2GRAY);
// }
// // 调整掩膜尺寸并确保二值化
// if (!dl_mask.empty() && overlay_dl_result) {
// if (dl_mask.size() != original_image.size()) {
// cv::resize(dl_mask, dl_mask, original_image.size(), 0, 0, cv::INTER_NEAREST);
// }
// // 确保掩膜为二值图像
// cv::threshold(dl_mask, dl_mask, 128, 255, cv::THRESH_BINARY);
// }
// if (!traditional_mask.empty() && overlay_traditional_result) {
// if (traditional_mask.size() != original_image.size()) {
// cv::resize(traditional_mask, traditional_mask, original_image.size(), 0, 0, cv::INTER_NEAREST);
// }
// // 确保掩膜为二值图像
// cv::threshold(traditional_mask, traditional_mask, 128, 255, cv::THRESH_BINARY);
// }
// // 叠加深度学习掩膜(绿色)
// if (!dl_mask.empty() && overlay_dl_result) {
// // 创建绿色掩膜
// cv::Mat green_overlay(display_img.size(), display_img.type(), cv::Scalar(0, 255, 0));
// green_overlay.setTo(cv::Scalar(0, 255, 0), dl_mask);
// // 叠加掩膜
// cv::addWeighted(display_img, 1.0, green_overlay, 0.5, 0, display_img);
// }
// // 叠加传统掩膜(红色)
// if (!traditional_mask.empty() && overlay_traditional_result) {
// // 创建红色掩膜
// cv::Mat red_overlay(display_img.size(), display_img.type(), cv::Scalar(0, 0, 255));
// red_overlay.setTo(cv::Scalar(0, 0, 255), traditional_mask);
// // 叠加掩膜
// cv::addWeighted(display_img, 1.0, red_overlay, 0.5, 0, display_img);
// }
// // 如果需要镜像处理
// if (mirror) {
// cv::flip(display_img, display_img, 1); // 水平翻转
// }
// // 将OpenCV Mat转换为QPixmap
// QPixmap pixmap = ImageUtils::mat2QPixmap(display_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);
} }
@ -389,6 +315,10 @@ void Widget::on_btn_stop_clicked()
void Widget::on_btn_start_clicked() void Widget::on_btn_start_clicked()
{ {
g_dl_enable[0] = !this->ui->dl_enable_0->isChecked();
g_dl_enable[1] = !this->ui->dl_enable_0->isChecked();
g_traditional_enable[0] = !this->ui->tra_enable_0->isChecked();
g_traditional_enable[1] = !this->ui->tra_enable_1->isChecked();
this->isCamRunning = true; this->isCamRunning = true;
// 热身两个工作者 // 热身两个工作者
for(int i = 0; i < 2; ++i) for(int i = 0; i < 2; ++i)
@ -423,3 +353,4 @@ void Widget::on_btn_quit_clicked()
qApp->quit(); qApp->quit();
} }

View File

@ -370,10 +370,33 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item>
<widget class="QCheckBox" name="dl_enable_1">
<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="tra_enable_1">
<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>
<item> <item>
<widget class="QCheckBox" name="mtx_1_overlay"> <widget class="QCheckBox" name="mtx_1_overlay">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>false</bool>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">font: 12pt &quot;Microsoft YaHei UI&quot;;</string> <string notr="true">font: 12pt &quot;Microsoft YaHei UI&quot;;</string>
@ -386,7 +409,7 @@
<item> <item>
<widget class="QCheckBox" name="dl_1_overlay"> <widget class="QCheckBox" name="dl_1_overlay">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>false</bool>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">font: 12pt &quot;Microsoft YaHei UI&quot;;</string> <string notr="true">font: 12pt &quot;Microsoft YaHei UI&quot;;</string>
@ -461,10 +484,33 @@ border: 4px solid black;</string>
</property> </property>
</spacer> </spacer>
</item> </item>
<item>
<widget class="QCheckBox" name="dl_enable_0">
<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="tra_enable_0">
<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>
<item> <item>
<widget class="QCheckBox" name="mtx_0_overlay"> <widget class="QCheckBox" name="mtx_0_overlay">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>false</bool>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">font: 12pt &quot;Microsoft YaHei UI&quot;;</string> <string notr="true">font: 12pt &quot;Microsoft YaHei UI&quot;;</string>
@ -477,7 +523,7 @@ border: 4px solid black;</string>
<item> <item>
<widget class="QCheckBox" name="dl_0_overlay"> <widget class="QCheckBox" name="dl_0_overlay">
<property name="enabled"> <property name="enabled">
<bool>true</bool> <bool>false</bool>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">font: 12pt &quot;Microsoft YaHei UI&quot;;</string> <string notr="true">font: 12pt &quot;Microsoft YaHei UI&quot;;</string>