添加了相机的左右屏蔽功能

This commit is contained in:
XinJiang1 2025-01-09 16:04:14 +08:00
parent 091257d18e
commit cba4629927
10 changed files with 531 additions and 237 deletions

View File

@ -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\QtCore\QDateTime \
..\..\..\..\Qt\6.7.3\msvc2022_64\include\QtWidgets\QTabBar \ ..\..\..\..\Qt\6.7.3\msvc2022_64\include\QtWidgets\QTabBar \
detection_worker.h \ 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\QtCore\QTextStream \
..\..\..\..\Qt\6.7.3\msvc2022_64\include\QtWidgets\QMessageBox \ ..\..\..\..\Qt\6.7.3\msvc2022_64\include\QtWidgets\QMessageBox \
..\..\..\..\Qt\6.7.3\msvc2022_64\include\QtWidgets\qmessagebox.h \ ..\..\..\..\Qt\6.7.3\msvc2022_64\include\QtWidgets\qmessagebox.h \

View File

@ -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\QtCore\QDateTime \
..\..\..\..\Qt\6.7.3\msvc2022_64\include\QtWidgets\QTabBar \ ..\..\..\..\Qt\6.7.3\msvc2022_64\include\QtWidgets\QTabBar \
detection_worker.h \ 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\QtCore\QTextStream \
..\..\..\..\Qt\6.7.3\msvc2022_64\include\QtWidgets\QMessageBox \ ..\..\..\..\Qt\6.7.3\msvc2022_64\include\QtWidgets\QMessageBox \
..\..\..\..\Qt\6.7.3\msvc2022_64\include\QtWidgets\qmessagebox.h \ ..\..\..\..\Qt\6.7.3\msvc2022_64\include\QtWidgets\qmessagebox.h \

View File

@ -230,7 +230,9 @@ MIL_INT ProcessingFunction0(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
#endif #endif
// 使 detection_result1 \ // 使 detection_result1 \
// 将 Matrox 的检测结果转换为 二维vector // 将 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 else
{ {
@ -272,7 +274,9 @@ MIL_INT ProcessingFunction0(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
timer_detection_time.restart(); timer_detection_time.restart();
#endif #endif
// 将深度学习的检测结果转换为 OpenCV Mat // 将深度学习的检测结果转换为 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); merged_mask = ImageUtils::mergeMasks(dl_mask, matrox_mask);
} }
else else
@ -400,7 +404,9 @@ MIL_INT ProcessingFunction1(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
#endif #endif
// 20ms内完成使 detection_result1 \ // 20ms内完成使 detection_result1 \
// 将 Matrox 的检测结果转换为 二维vector // 将 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) #if(GlobalDebug && DebugDetectionTime)
timer_detection_time.printElapsedTime("CallBack2: High sat detection to mask"); timer_detection_time.printElapsedTime("CallBack2: High sat detection to mask");
timer_detection_time.restart(); timer_detection_time.restart();
@ -446,7 +452,9 @@ MIL_INT ProcessingFunction1(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
timer_detection_time.restart(); timer_detection_time.restart();
#endif #endif
// 将深度学习的检测结果转换为 OpenCV Mat // 将深度学习的检测结果转换为 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); merged_mask = ImageUtils::mergeMasks(dl_mask, matrox_mask);
} }
else else
@ -712,48 +720,46 @@ std::vector<std::vector<uint8_t>> generateMaskFromImage(const MIL_ID& inputImage
} }
std::vector<std::vector<uint8_t>> generateMaskFromMatImage(const cv::Mat& image, int widthBlocks, int heightBlocks, int thresholds= 10) { std::vector<std::vector<uint8_t>> 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); cv::threshold(image, image, 128, 255, cv::THRESH_BINARY);
// 获取图像的宽度和高度
int imageWidth = image.cols; int imageWidth = image.cols;
int imageHeight = image.rows; int imageHeight = image.rows;
// 计算每个块的宽度和高度 // Adjust image width by excluding skipLeftCols and skipRightCols
int blockWidth = imageWidth / widthBlocks; int effectiveWidth = imageWidth - skipLeftCols - skipRightCols;
int blockHeight = imageHeight / heightBlocks; if (effectiveWidth <= 0) {
throw std::invalid_argument("Invalid column skip values. Effective width is less than or equal to zero.");
}
// 创建掩膜矩阵 int blockWidth = effectiveWidth / outputWidth;
std::vector<std::vector<uint8_t>> mask(heightBlocks, std::vector<uint8_t>(widthBlocks, false)); int blockHeight = imageHeight / outputHeight;
// 遍历每个块并统计白色像素点的数量 vector<vector<uint8_t>> mask(outputHeight, vector<uint8_t>(outputWidth, 0));
for (int i = 0; i < heightBlocks; ++i)
{ for (int i = 0; i < outputHeight; ++i) {
for (int j = 0; j < widthBlocks; ++j) for (int j = 0; j < outputWidth; ++j) {
{ int x_start = skipLeftCols + j * blockWidth;
// 计算块的起始和结束位置
int x_start = j * blockWidth;
int y_start = i * blockHeight; int y_start = i * blockHeight;
int x_end = (j == widthBlocks - 1) ? imageWidth : (j + 1) * blockWidth; int x_end = (j == outputWidth - 1) ? (imageWidth - skipRightCols) : (skipLeftCols + (j + 1) * blockWidth);
int y_end = (i == heightBlocks - 1) ? imageHeight : (i + 1) * blockHeight; 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)); cv::Mat block = image(cv::Rect(x_start, y_start, x_end - x_start, y_end - y_start));
// 统计块中白色像素的数量
int whitePixelCount = cv::countNonZero(block); int whitePixelCount = cv::countNonZero(block);
if (whitePixelCount > sizeThreshold) {
// 如果白色像素数大于阈值,将该块标记为 true mask[i][j] = 1;
if (whitePixelCount > thresholds) }
{
mask[i][j] = true;
}
} }
} }
return mask; return mask;
} }

View File

@ -30,7 +30,12 @@ extern MIL_ID MilApplication;
extern MIL_ID MilSystem; extern MIL_ID MilSystem;
std::vector<std::vector<uint8_t>> generateMaskFromImage(const MIL_ID& inputImage, int widthBlocks, int heightBlocks, int thresholds); std::vector<std::vector<uint8_t>> generateMaskFromImage(const MIL_ID& inputImage, int widthBlocks, int heightBlocks, int thresholds);
std::vector<std::vector<uint8_t>> generateMaskFromMatImage(const cv::Mat& image, int widthBlocks, int heightBlocks, int thresholds); std::vector<std::vector<uint8_t>> generateMaskFromMatImage(const cv::Mat& image,
int widthBlocks,
int heightBlocks,
int thresholds = 10,
int skipLeftCols = 0,
int skipRightCols = 0);
void PadColumns(std::vector<std::vector<uint8_t>>& data, int pad_left, int pad_right, uint8_t fill_value ); void PadColumns(std::vector<std::vector<uint8_t>>& data, int pad_left, int pad_right, uint8_t fill_value );

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, 2025-01-08T14:41:38. --> <!-- Written by QtCreator 15.0.0, 2025-01-09T15:44:34. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>

View File

@ -12,17 +12,17 @@ blue_a_max = 22
blue_b_min = -48 blue_b_min = -48
blue_b_max = -8 blue_b_max = -8
orange_L_min = 67 orange_L_min = 63
orange_L_max = 93 orange_L_max = 78
orange_a_min = -8 orange_a_min = 7
orange_a_max = 8 orange_a_max = 14
orange_b_min = 36 orange_b_min = 23
orange_b_max = 58 orange_b_max = 47
black_L_min = 0 black_L_min = 0
black_L_max = 30 black_L_max = 8
black_a_min = -5 black_a_min = -4
black_a_max = 3 black_a_max = 2
black_b_min = -3 black_b_min = -3
black_b_max = 4 black_b_max = 4
@ -34,9 +34,9 @@ red_b_min = -80
red_b_max = 37 red_b_max = 37
purple_L_min = 38 purple_L_min = 38
purple_L_max = 60 purple_L_max = 54
purple_a_min = 10 purple_a_min = 10
purple_a_max = 25 purple_a_max = 20
purple_b_min = -45 purple_b_min = -45
purple_b_max = 1 purple_b_max = 1
@ -51,12 +51,16 @@ expansionRaidus = 1
file_delay = 1180 file_delay = 1180
lab_denoising = 1 lab_denoising = 1
lowmac_dp = 350 lowmac_dp = 350
lowmac_sg = 60 lowmac_sg = 70
lowmac_sm = 1800 lowmac_sm = 1200
lowmac_td = 2 lowmac_td = 7
lowmac_ts = 13 lowmac_ts = 10
machine_num = 0 machine_num = 0
max_valves_together = 20 max_valves_together = 18
saturation_denoising = 1 saturation_denoising = 1
saturation_threshold = 165 saturation_threshold = 165
screen_left_0 = 0
screen_left_1 = 0
screen_right_0 = 10
screen_right_1 = 0
sizeThreshold = 4 sizeThreshold = 4

View File

@ -59,4 +59,8 @@ machine_num = 0
max_valves_together = 18 max_valves_together = 18
saturation_denoising = 1 saturation_denoising = 1
saturation_threshold = 165 saturation_threshold = 165
screen_left_0 = 0
screen_left_1 = 0
screen_right_0 = 10
screen_right_1 = 0
sizeThreshold = 4 sizeThreshold = 4

View File

@ -75,10 +75,10 @@ public:
QCheckBox *img_0_mirror; QCheckBox *img_0_mirror;
QLabel *camera_0_img; QLabel *camera_0_img;
QWidget *tab_3; QWidget *tab_3;
QVBoxLayout *verticalLayout_11; QVBoxLayout *verticalLayout_15;
QLabel *label_title_3; QLabel *label_title_3;
QSpacerItem *verticalSpacer_9; QSpacerItem *verticalSpacer_9;
QHBoxLayout *horizontalLayout_24; QHBoxLayout *horizontalLayout_44;
QGroupBox *groupBox_4; QGroupBox *groupBox_4;
QVBoxLayout *verticalLayout_4; QVBoxLayout *verticalLayout_4;
QFrame *frame_3; QFrame *frame_3;
@ -99,7 +99,24 @@ public:
QLabel *label_encoder_2; QLabel *label_encoder_2;
QSpinBox *spinbox_valve; QSpinBox *spinbox_valve;
QPushButton *btn_set_lower; QPushButton *btn_set_lower;
QFrame *frame_12;
QVBoxLayout *verticalLayout_14;
QFrame *frame_10;
QVBoxLayout *verticalLayout_9; 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; QLabel *label_title_4;
QGroupBox *groupBox_2; QGroupBox *groupBox_2;
QHBoxLayout *horizontalLayout_25; QHBoxLayout *horizontalLayout_25;
@ -698,9 +715,9 @@ public:
tabWidget->addTab(tab_2, QString()); tabWidget->addTab(tab_2, QString());
tab_3 = new QWidget(); tab_3 = new QWidget();
tab_3->setObjectName("tab_3"); tab_3->setObjectName("tab_3");
verticalLayout_11 = new QVBoxLayout(tab_3); verticalLayout_15 = new QVBoxLayout(tab_3);
verticalLayout_11->setObjectName("verticalLayout_11"); verticalLayout_15->setObjectName("verticalLayout_15");
verticalLayout_11->setContentsMargins(-1, -1, -1, 50); verticalLayout_15->setContentsMargins(-1, -1, -1, 40);
label_title_3 = new QLabel(tab_3); label_title_3 = new QLabel(tab_3);
label_title_3->setObjectName("label_title_3"); label_title_3->setObjectName("label_title_3");
QFont font1; QFont font1;
@ -711,15 +728,14 @@ public:
label_title_3->setFont(font1); label_title_3->setFont(font1);
label_title_3->setStyleSheet(QString::fromUtf8("font: 700 48pt \"Microsoft YaHei UI\";")); 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); 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_44 = new QHBoxLayout();
horizontalLayout_24->setSpacing(50); horizontalLayout_44->setObjectName("horizontalLayout_44");
horizontalLayout_24->setObjectName("horizontalLayout_24");
groupBox_4 = new QGroupBox(tab_3); groupBox_4 = new QGroupBox(tab_3);
groupBox_4->setObjectName("groupBox_4"); groupBox_4->setObjectName("groupBox_4");
groupBox_4->setMaximumSize(QSize(900, 16777215)); groupBox_4->setMaximumSize(QSize(900, 16777215));
@ -843,18 +859,113 @@ public:
verticalLayout_4->addWidget(btn_set_lower); 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"); 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->setObjectName("label_title_4");
label_title_4->setMaximumSize(QSize(500, 16777215)); label_title_4->setMaximumSize(QSize(500, 16777215));
label_title_4->setStyleSheet(QString::fromUtf8("font: 20pt \"Microsoft YaHei UI\";")); 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->setObjectName("groupBox_2");
groupBox_2->setEnabled(false); groupBox_2->setEnabled(false);
groupBox_2->setMaximumSize(QSize(1000, 16777215)); groupBox_2->setMaximumSize(QSize(1000, 16777215));
@ -887,9 +998,9 @@ public:
horizontalLayout_25->addWidget(btn_stop_single); 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->setObjectName("groupBox_3");
groupBox_3->setEnabled(false); groupBox_3->setEnabled(false);
groupBox_3->setMaximumSize(QSize(1000, 16777215)); groupBox_3->setMaximumSize(QSize(1000, 16777215));
@ -910,17 +1021,20 @@ public:
horizontalLayout_26->addWidget(btn_stop_test); 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); 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 = new QHBoxLayout();
horizontalLayout_19->setSpacing(40); horizontalLayout_19->setSpacing(40);
@ -965,7 +1079,7 @@ public:
horizontalLayout_19->addWidget(btn_tab3_backtab2_4); horizontalLayout_19->addWidget(btn_tab3_backtab2_4);
verticalLayout_11->addLayout(horizontalLayout_19); verticalLayout_15->addLayout(horizontalLayout_19);
tabWidget->addTab(tab_3, QString()); tabWidget->addTab(tab_3, QString());
tab_color = new QWidget(); tab_color = new QWidget();
@ -2018,7 +2132,7 @@ public:
retranslateUi(Widget); retranslateUi(Widget);
tabWidget->setCurrentIndex(1); tabWidget->setCurrentIndex(2);
QMetaObject::connectSlotsByName(Widget); 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->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)); 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)); 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)); 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)); 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)); label_explosure_2->setText(QCoreApplication::translate("Widget", "\351\200\232\351\201\223", nullptr));

View File

@ -15,7 +15,7 @@
#include <QTabBar> #include <QTabBar>
#include <img_utils.h> #include <img_utils.h>
#include <detection_worker.h> #include <detection_worker.h>
#include <Qstring> #include <QString>
#include <QFile> #include <QFile>
#include <QTextStream> #include <QTextStream>
#include <QDebug> #include <QDebug>
@ -64,7 +64,6 @@ Widget::Widget(QWidget *parent)
iniOnnx(); iniOnnx();
// iniColor(); // iniColor();
loadConfig(getConfigDirectory()+"/color_range_config.txt"); // 读取配置文件 loadConfig(getConfigDirectory()+"/color_range_config.txt"); // 读取配置文件
check_lower_machine();
iniCamera(); iniCamera();
// 更新界面 // 更新界面
@ -96,11 +95,10 @@ Widget::Widget(QWidget *parent)
// 启动PLC定时器每秒检查一次 // 启动PLC定时器每秒检查一次
QTimer* timer_lower = new QTimer(this); QTimer* timer_lower = new QTimer(this);
connect(timer_lower, &QTimer::timeout, this, &Widget::check_lower_machine); connect(timer_lower, &QTimer::timeout, this, &Widget::check_lower_machine);
check_lower_machine(); // 先尝试一次连接
timer_lower->start(10000); // 每10秒检查一次FPGA的状态 timer_lower->start(10000); // 每10秒检查一次FPGA的状态
ui->tabWidget->setCurrentIndex(1); ui->tabWidget->setCurrentIndex(1);
// on_btn_start_clicked();
// 显示启动倒计时
showStartupCountdown(); showStartupCountdown();
} }
@ -124,7 +122,7 @@ void Widget::check_lower_machine(){
} }
else else
{ {
this->ui->lab_plc->setStyleSheet( this->ui->lab_fpga->setStyleSheet(
"QLabel{" "QLabel{"
"background-color: red;" "background-color: red;"
"color: white;" "color: white;"
@ -499,7 +497,6 @@ void Widget::on_btn_stop_clicked()
{ {
stop_grab(); stop_grab();
DestoryLowMac(); DestoryLowMac();
this->isCamRunning = false; this->isCamRunning = false;
// 恢复显示的图片 // 恢复显示的图片
{ {
@ -570,12 +567,15 @@ void Widget::on_btn_quit_clicked()
void Widget::on_btn_set_lower_clicked() void Widget::on_btn_set_lower_clicked()
{ {
// 硬编码参数值 // 硬编码参数值
lowmac_sm = ui->spinbox_maintime->value(); lowmac_sm = ui->spinbox_maintime->value();
params["lowmac_sm"]=lowmac_sm; params["lowmac_sm"]=lowmac_sm;
params["machine_num"] = ui->spinbox_machine_code->value(); params["machine_num"] = ui->spinbox_machine_code->value();
params["max_valves_together"] = ui->spinbox_max_valves_together->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); saveConfig(getConfigDirectory()+"/color_range_config.txt", params, colors);
// 两个过去的参量不支持读取配置文件 // 两个过去的参量不支持读取配置文件
@ -586,7 +586,6 @@ void Widget::on_btn_set_lower_clicked()
QMutexLocker locker(&plc_mutex); QMutexLocker locker(&plc_mutex);
plc_connector = std::make_unique<PLCConnector>(params["machine_num"]); plc_connector = std::make_unique<PLCConnector>(params["machine_num"]);
} }
// 可选:立即更新 PLC 连接状态
heart_beat(); heart_beat();
} }
@ -596,6 +595,10 @@ void Widget::update_main_settings()
ui->spinbox_machine_code->setValue(params["machine_num"]); ui->spinbox_machine_code->setValue(params["machine_num"]);
ui->spinbox_maintime->setValue(params["lowmac_sm"]); ui->spinbox_maintime->setValue(params["lowmac_sm"]);
ui->spinbox_max_valves_together->setValue(params["max_valves_together"]); 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() void Widget::on_btn_set_valve_clicked()
@ -822,6 +825,10 @@ void Widget::initDefaultConfig()
{"lowmac_sm", lowmac_sm}, {"lowmac_sm", lowmac_sm},
{"machine_num", params["machine_num"]}, {"machine_num", params["machine_num"]},
{"max_valves_together", params["max_valves_together"]}, {"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}, {"sizeThreshold",4},
{"file_delay",1180}, {"file_delay",1180},
@ -1155,4 +1162,3 @@ void Widget::on_tabWidget_currentChanged(int index)
update_colorlist(); // 更新色彩列表 update_colorlist(); // 更新色彩列表
update_polar(); // 更新偏振相机界面 update_polar(); // 更新偏振相机界面
} }

165
widget.ui
View File

@ -47,7 +47,7 @@
<string notr="true">background-color: rgb(228, 223, 186);</string> <string notr="true">background-color: rgb(228, 223, 186);</string>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>2</number>
</property> </property>
<property name="tabBarAutoHide"> <property name="tabBarAutoHide">
<bool>true</bool> <bool>true</bool>
@ -684,9 +684,9 @@ border: 4px solid black;
<attribute name="title"> <attribute name="title">
<string>Tab 3</string> <string>Tab 3</string>
</attribute> </attribute>
<layout class="QVBoxLayout" name="verticalLayout_11"> <layout class="QVBoxLayout" name="verticalLayout_15">
<property name="bottomMargin"> <property name="bottomMargin">
<number>50</number> <number>40</number>
</property> </property>
<item> <item>
<widget class="QLabel" name="label_title_3"> <widget class="QLabel" name="label_title_3">
@ -720,10 +720,7 @@ border: 4px solid black;
</spacer> </spacer>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_24"> <layout class="QHBoxLayout" name="horizontalLayout_44">
<property name="spacing">
<number>50</number>
</property>
<item> <item>
<widget class="QGroupBox" name="groupBox_4"> <widget class="QGroupBox" name="groupBox_4">
<property name="maximumSize"> <property name="maximumSize">
@ -916,7 +913,157 @@ border-color: rgb(0, 0, 0);</string>
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QFrame" name="frame_12">
<property name="frameShape">
<enum>QFrame::Shape::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Shadow::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_14">
<item>
<widget class="QFrame" name="frame_10">
<property name="frameShape">
<enum>QFrame::Shape::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Shadow::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_9"> <layout class="QVBoxLayout" name="verticalLayout_9">
<item>
<widget class="QLabel" name="label_22">
<property name="styleSheet">
<string notr="true">font: 700 40pt &quot;Microsoft YaHei UI&quot;;
border-color: rgb(0, 0, 0);</string>
</property>
<property name="text">
<string>相机0</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_43">
<item>
<widget class="QLabel" name="label_24">
<property name="styleSheet">
<string notr="true">font: 700 40pt &quot;Microsoft YaHei UI&quot;;</string>
</property>
<property name="text">
<string>屏蔽左</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spb_screen_left_0">
<property name="minimumSize">
<size>
<width>100</width>
<height>61</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">font: 20pt &quot;Microsoft YaHei UI&quot;;</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_25">
<property name="styleSheet">
<string notr="true">font: 700 40pt &quot;Microsoft YaHei UI&quot;;</string>
</property>
<property name="text">
<string>屏蔽右</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spb_screen_right_0">
<property name="minimumSize">
<size>
<width>100</width>
<height>61</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">font: 20pt &quot;Microsoft YaHei UI&quot;;</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="label_23">
<property name="styleSheet">
<string notr="true">font: 700 40pt &quot;Microsoft YaHei UI&quot;;
border-color: rgb(0, 0, 0);</string>
</property>
<property name="text">
<string>相机1</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_24">
<item>
<widget class="QLabel" name="label_26">
<property name="styleSheet">
<string notr="true">font: 700 40pt &quot;Microsoft YaHei UI&quot;;</string>
</property>
<property name="text">
<string>屏蔽左</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spb_screen_left_1">
<property name="minimumSize">
<size>
<width>100</width>
<height>61</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">font: 20pt &quot;Microsoft YaHei UI&quot;;</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_27">
<property name="styleSheet">
<string notr="true">font: 700 40pt &quot;Microsoft YaHei UI&quot;;</string>
</property>
<property name="text">
<string>屏蔽右</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spb_screen_right_1">
<property name="minimumSize">
<size>
<width>100</width>
<height>61</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">font: 20pt &quot;Microsoft YaHei UI&quot;;</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QFrame" name="frame_11">
<property name="frameShape">
<enum>QFrame::Shape::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Shadow::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_11">
<item> <item>
<widget class="QLabel" name="label_title_4"> <widget class="QLabel" name="label_title_4">
<property name="maximumSize"> <property name="maximumSize">
@ -1057,6 +1204,10 @@ border-color: rgb(0, 0, 0);</string>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget>
</item>
</layout>
</widget>
</item> </item>
</layout> </layout>
</item> </item>