拆分出color_range模块,增加界面调参、增减颜色功能。
This commit is contained in:
parent
5daf7b6bf2
commit
9394384cd8
358
Makefile.Debug
358
Makefile.Debug
File diff suppressed because one or more lines are too long
358
Makefile.Release
358
Makefile.Release
File diff suppressed because one or more lines are too long
277
camera.cpp
277
camera.cpp
@ -41,7 +41,8 @@ int SaveImg_Flag;
|
||||
ONNXRunner runner;
|
||||
|
||||
|
||||
std::map<std::string, int> params;
|
||||
|
||||
|
||||
int dual_cam_offset_y = 0; // 双相机之间的上下偏移值
|
||||
int widthBlocks = 20; // 输出的喷阀通道数
|
||||
int heightBlocks = 512; // 输出的Mask高度
|
||||
@ -221,7 +222,7 @@ MIL_INT ProcessingFunction0(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
|
||||
// 使用 std::async 将 high_sat_detect 封装为异步任务
|
||||
auto future = std::async(std::launch::async, [&]() {
|
||||
MIL_ID detection_result_id;
|
||||
high_sat_detect(MimFlipDedtination, detection_result_id, params);
|
||||
high_sat_detect(MimFlipDedtination, detection_result_id, params,colors);
|
||||
matrox_mat = ImageUtils::mil2Mat(detection_result_id);
|
||||
MbufFree(detection_result_id);
|
||||
});
|
||||
@ -391,7 +392,7 @@ MIL_INT ProcessingFunction1(MIL_INT HookType, MIL_ID HookId, void *HookDataPtr)
|
||||
// 使用 std::async 将 high_sat_detect 封装为异步任务
|
||||
auto future = std::async(std::launch::async, [&]() {
|
||||
MIL_ID detection_result_id;
|
||||
high_sat_detect(MimResizedestination, detection_result_id, params);
|
||||
high_sat_detect(MimResizedestination, detection_result_id, params,colors);
|
||||
matrox_mat = ImageUtils::mil2Mat(detection_result_id);
|
||||
MbufFree(detection_result_id);
|
||||
});
|
||||
@ -612,245 +613,6 @@ bool DestoryCamera()
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Optimized LabProcess function
|
||||
void lab_process_raw(const MIL_ID& inputImage, MIL_ID& outputImageLab, const std::map<std::string, int>& params,
|
||||
const std::vector<std::string>& color_vector)
|
||||
{
|
||||
MIL_ID MilLabImage = M_NULL, MilLChannel = M_NULL, MilAChannel = M_NULL, MilBChannel = M_NULL;
|
||||
MIL_ID lab_result=M_NULL;
|
||||
|
||||
int denoising = params.at("lab_denoising");
|
||||
|
||||
// Check number of bands
|
||||
MIL_INT NumBands = 0;
|
||||
MbufInquire(inputImage, M_SIZE_BAND, &NumBands);
|
||||
if (NumBands != 3)
|
||||
{
|
||||
printf("输入图像不是 3 通道图像,请提供彩色图像。\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Inquire image properties once
|
||||
// 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);
|
||||
|
||||
// Allocate buffer for Lab image
|
||||
MbufAllocColor(MilSystem, 3, SizeX, SizeY, 8 + M_UNSIGNED, M_IMAGE + M_PROC, &MilLabImage);
|
||||
|
||||
// Convert image from sRGB to Lab
|
||||
MimConvert(inputImage, MilLabImage, M_SRGB_TO_LAB);
|
||||
|
||||
// Create child buffers for L, a, b channels
|
||||
MbufChildColor(MilLabImage, 0, &MilLChannel);
|
||||
MbufChildColor(MilLabImage, 1, &MilAChannel);
|
||||
MbufChildColor(MilLabImage, 2, &MilBChannel);
|
||||
|
||||
// Allocate output image as 1-bit image
|
||||
MbufAlloc2d(MilSystem, SizeX, SizeY, 8 + M_UNSIGNED, M_IMAGE + M_PROC, &outputImageLab);
|
||||
MbufClear(outputImageLab, 0); // Initialize to 0
|
||||
|
||||
// Pre-allocate binary buffers as 1-bit images
|
||||
MIL_ID MilBinaryL = M_NULL, MilBinaryA = M_NULL, MilBinaryB = M_NULL, MilResultLab = M_NULL;
|
||||
MbufAlloc2d(MilSystem, SizeX, SizeY, 8 + M_UNSIGNED, M_IMAGE + M_PROC, &MilBinaryL);
|
||||
MbufAlloc2d(MilSystem, SizeX, SizeY, 8 + M_UNSIGNED, M_IMAGE + M_PROC, &MilBinaryA);
|
||||
MbufAlloc2d(MilSystem, SizeX, SizeY, 8 + M_UNSIGNED, M_IMAGE + M_PROC, &MilBinaryB);
|
||||
MbufAlloc2d(MilSystem, SizeX, SizeY, 8 + M_UNSIGNED, M_IMAGE + M_PROC, &MilResultLab);
|
||||
MbufAlloc2d(MilSystem, SizeX, SizeY, 8 + M_UNSIGNED, M_IMAGE + M_PROC, &lab_result);
|
||||
|
||||
MbufClear(lab_result, M_COLOR_BLACK);
|
||||
// Iterate over colors
|
||||
// 遍历颜色
|
||||
for (const auto& color : color_vector) {
|
||||
// 构建参数键
|
||||
std::string L_min_key = color + "_L_min";
|
||||
std::string L_max_key = color + "_L_max";
|
||||
std::string a_min_key = color + "_a_min";
|
||||
std::string a_max_key = color + "_a_max";
|
||||
std::string b_min_key = color + "_b_min";
|
||||
std::string b_max_key = color + "_b_max";
|
||||
|
||||
// 获取参数值
|
||||
int L_min = params.at(L_min_key);
|
||||
int L_max = params.at(L_max_key);
|
||||
int a_min = params.at(a_min_key);
|
||||
int a_max = params.at(a_max_key);
|
||||
int b_min = params.at(b_min_key);
|
||||
int b_max = params.at(b_max_key);
|
||||
std::vector<int> lab_min_ps = {L_min, a_min, b_min};
|
||||
std::vector<int> lab_max_ps = {L_max, a_max, b_max};
|
||||
|
||||
std::vector<int> lab_min_cv = psLabToOpenCVLab(lab_min_ps);
|
||||
std::vector<int> lab_max_cv = psLabToOpenCVLab(lab_max_ps);
|
||||
|
||||
L_min = lab_min_cv[0];
|
||||
L_max = lab_max_cv[0];
|
||||
a_min = lab_min_cv[1];
|
||||
a_max = lab_max_cv[1];
|
||||
b_min = lab_min_cv[2];
|
||||
b_max = lab_max_cv[2];
|
||||
|
||||
// 对每个通道进行二值化
|
||||
MimBinarize(MilLChannel, MilBinaryL, M_IN_RANGE, L_min, L_max);
|
||||
MimBinarize(MilAChannel, MilBinaryA, M_IN_RANGE, a_min, a_max);
|
||||
MimBinarize(MilBChannel, MilBinaryB, M_IN_RANGE, b_min, b_max);
|
||||
|
||||
// 合并阈值结果
|
||||
MimArith(MilBinaryL, MilBinaryA, MilResultLab, M_AND);
|
||||
MimArith(MilResultLab, MilBinaryB, MilResultLab, M_AND);
|
||||
|
||||
|
||||
// 与输出图像合并
|
||||
MimArith(lab_result, MilResultLab, lab_result, M_OR);
|
||||
|
||||
}
|
||||
|
||||
MimClose(lab_result, MilResultLab, denoising, M_BINARY);
|
||||
MimOpen(MilResultLab, outputImageLab, denoising, M_BINARY);
|
||||
|
||||
// Free binary buffers
|
||||
MbufFree(MilBinaryL);
|
||||
MbufFree(MilBinaryA);
|
||||
MbufFree(MilBinaryB);
|
||||
MbufFree(MilResultLab);
|
||||
|
||||
// Free resources
|
||||
MbufFree(MilLChannel);
|
||||
MbufFree(MilAChannel);
|
||||
MbufFree(MilBChannel);
|
||||
MbufFree(MilLabImage);
|
||||
MbufFree(lab_result);
|
||||
}
|
||||
|
||||
|
||||
void lab_process(const MIL_ID& inputImage, MIL_ID& outputImageLab, const std::map<std::string, int>& params) {
|
||||
const std::vector<std::string> colors = {"green", "blue", "orange", "black", "red", "purple"};
|
||||
lab_process_raw(inputImage, outputImageLab, params, colors);
|
||||
}
|
||||
|
||||
vector<int> psLabToOpenCVLab(const vector<int>& lab_ps) {
|
||||
int l_ps = lab_ps[0];
|
||||
int a_ps = lab_ps[1];
|
||||
int b_ps = lab_ps[2];
|
||||
|
||||
// Conversion formulas
|
||||
int l_cv = round((l_ps / 100.0) * 255.0); // Scale L from 0-100 to 0-255
|
||||
int a_cv = round(((a_ps + 128.0) / 255.0) * 255.0); // Shift and scale a
|
||||
int b_cv = round(((b_ps + 128.0) / 255.0) * 255.0); // Shift and scale b
|
||||
|
||||
return {l_cv, a_cv, b_cv};
|
||||
}
|
||||
|
||||
vector<int> opencvLabToPsLab(const vector<int>& lab_cv) {
|
||||
int l_cv = lab_cv[0];
|
||||
int a_cv = lab_cv[1];
|
||||
int b_cv = lab_cv[2];
|
||||
|
||||
// Conversion formulas
|
||||
int l_ps = round((l_cv / 255.0) * 100.0); // Scale L from 0-255 to 0-100
|
||||
int a_ps = round((a_cv / 255.0) * 255.0 - 128.0); // Scale and shift a
|
||||
int b_ps = round((b_cv / 255.0) * 255.0 - 128.0); // Scale and shift b
|
||||
|
||||
return {l_ps, a_ps, b_ps};
|
||||
}
|
||||
|
||||
void hsv_process(const MIL_ID& inputImage, MIL_ID& outputImageHSV, const std::map<std::string, int>& params)
|
||||
{
|
||||
MIL_ID MilHSVImage = M_NULL, MilHChannel = M_NULL, MilSChannel = M_NULL, MilVChannel = M_NULL;
|
||||
MIL_ID hsv_result = M_NULL;
|
||||
MIL_ID hsv_denoising = M_NULL;
|
||||
int saturationThreshold = params.at("saturation_threshold");
|
||||
int denoising = params.at("saturation_denoising");
|
||||
|
||||
// 检查输入图像的通道数
|
||||
MIL_INT NumBands = 0;
|
||||
MbufInquire(inputImage, M_SIZE_BAND, &NumBands);
|
||||
if (NumBands != 3)
|
||||
{
|
||||
printf("输入图像不是 3 通道图像,请提供彩色图像。\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// 分配用于存储 HSV 图像的缓冲区
|
||||
MbufAllocColor(MbufInquire(inputImage, M_OWNER_SYSTEM, M_NULL), 3,
|
||||
MbufInquire(inputImage, M_SIZE_X, M_NULL),
|
||||
MbufInquire(inputImage, M_SIZE_Y, M_NULL),
|
||||
8 + M_UNSIGNED,
|
||||
M_IMAGE + M_PROC + M_DISP,
|
||||
&MilHSVImage);
|
||||
|
||||
// 将图像从 sRGB 转换到 HSV
|
||||
MimConvert(inputImage, MilHSVImage, M_RGB_TO_HSV);
|
||||
|
||||
// 创建 HSV 通道的子缓冲区
|
||||
MbufChildColor(MilHSVImage, 0, &MilHChannel);
|
||||
MbufChildColor(MilHSVImage, 1, &MilSChannel);
|
||||
MbufChildColor(MilHSVImage, 2, &MilVChannel);
|
||||
|
||||
// 分配输出图像缓冲区
|
||||
MbufAlloc2d(MilSystem, MbufInquire(inputImage, M_SIZE_X, M_NULL),
|
||||
MbufInquire(inputImage, M_SIZE_Y, M_NULL), 8 + M_UNSIGNED,
|
||||
M_IMAGE + M_PROC + M_DISP, &hsv_result);
|
||||
MbufAlloc2d(MilSystem, MbufInquire(inputImage, M_SIZE_X, M_NULL),
|
||||
MbufInquire(inputImage, M_SIZE_Y, M_NULL), 8 + M_UNSIGNED,
|
||||
M_IMAGE + M_PROC + M_DISP, &hsv_denoising);
|
||||
MbufAlloc2d(MilSystem, MbufInquire(inputImage, M_SIZE_X, M_NULL),
|
||||
MbufInquire(inputImage, M_SIZE_Y, M_NULL), 8 + M_UNSIGNED,
|
||||
M_IMAGE + M_PROC + M_DISP, &outputImageHSV);
|
||||
|
||||
// 对 S 通道进行阈值分割
|
||||
MimBinarize(MilSChannel, hsv_result, M_GREATER,
|
||||
saturationThreshold, M_NULL);
|
||||
|
||||
MimClose(hsv_result, hsv_denoising, denoising, M_BINARY);
|
||||
MimOpen(hsv_denoising, outputImageHSV, denoising, M_BINARY);
|
||||
|
||||
// 释放资源
|
||||
MbufFree(MilHChannel);
|
||||
MbufFree(MilSChannel);
|
||||
MbufFree(MilVChannel);
|
||||
MbufFree(MilHSVImage);
|
||||
MbufFree(hsv_result);
|
||||
MbufFree(hsv_denoising);
|
||||
}
|
||||
|
||||
|
||||
void high_sat_detect(const MIL_ID& inputImage, MIL_ID& outputImage, const std::map<std::string, int>& params) {
|
||||
MIL_ID output_hsv=M_NULL, output_lab=M_NULL;
|
||||
|
||||
hsv_process(inputImage, output_hsv, params);
|
||||
lab_process(inputImage, output_lab, params);
|
||||
|
||||
MbufAlloc2d(MilSystem, MbufInquire(inputImage, M_SIZE_X, M_NULL),
|
||||
MbufInquire(inputImage, M_SIZE_Y, M_NULL), 8 + M_UNSIGNED,
|
||||
M_IMAGE + M_PROC, &outputImage);
|
||||
|
||||
|
||||
// 合并 Lab 和 HSV 的结果(取“或”运算)
|
||||
MimArith(output_hsv, output_lab, outputImage, M_OR);
|
||||
// MIL_ID MilBlobContext = M_NULL, MilBlobResult = M_NULL, MilFiltered = M_NULL;
|
||||
// MIL_INT SizeX = 0, SizeY = 0;
|
||||
// MIL_INT blob_count = 0;
|
||||
// MblobAlloc(MilSystem, M_DEFAULT, M_DEFAULT, &MilBlobContext);
|
||||
// MblobAllocResult(MilSystem, M_DEFAULT, M_DEFAULT, &MilBlobResult);
|
||||
// MblobCalculate(MilBlobContext, outputImage, M_NULL, MilBlobResult);
|
||||
// MblobSelect(MilBlobResult, M_EXCLUDE, M_AREA, M_LESS, MIN_AREA, M_NULL);
|
||||
// MblobGetResult(MilBlobResult, M_NUMBER, &blob_count); // 修正:只传 M_NUMBER
|
||||
// // 获取 detection_result 的尺寸
|
||||
// MbufInquire(outputImage, M_SIZE_X, &SizeX);
|
||||
// MbufInquire(outputImage, M_SIZE_Y, &SizeY);
|
||||
// // 分配一个新的二值图像来存储筛选后的结果
|
||||
// MbufAlloc2d(MilSystem, SizeX, SizeY, 8 + M_UNSIGNED, M_IMAGE + M_PROC, &MilFiltered);
|
||||
// // 将 MilFiltered 初始化为 0(全黑)
|
||||
// MbufClear(MilFiltered, 0);
|
||||
// MIL_ID MilGraphicsContext;
|
||||
// MgraAlloc(MilSystem, &MilGraphicsContext);
|
||||
// MblobDraw(MilGraphicsContext, MilBlobResult, MilFiltered, M_DRAW_BLOBS, M_INCLUDED_BLOBS, M_DEFAULT);
|
||||
// // 将筛选后的结果复制回 detection_result
|
||||
// MbufCopy(MilFiltered, outputImage);
|
||||
MbufFree(output_lab);
|
||||
MbufFree(output_hsv);
|
||||
}
|
||||
|
||||
void read_params_from_file(const std::string& filename, std::map<std::string, int>& params) {
|
||||
std::ifstream infile(filename);
|
||||
@ -895,6 +657,33 @@ void read_params_from_file(const std::string& filename, std::map<std::string, in
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void read_color(const std::string& filename, std::vector<std::string>& colors) {
|
||||
std::ifstream file(filename);
|
||||
if (!file.is_open()) {
|
||||
std::cerr << "Error: Unable to open file " << filename << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<std::string> new_colors;
|
||||
std::string color;
|
||||
while (std::getline(file, color)) {
|
||||
if (!color.empty()) {
|
||||
new_colors.push_back(color);
|
||||
}
|
||||
}
|
||||
|
||||
if (!new_colors.empty()) {
|
||||
colors = std::move(new_colors); // Replace the existing colors
|
||||
}
|
||||
else {
|
||||
std::cerr << "Warning: File is empty or contains no valid data." << std::endl;
|
||||
}
|
||||
|
||||
file.close();
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::vector<uint8_t>> generateMaskFromImage(const MIL_ID& inputImage, int widthBlocks, int heightBlocks, int thresholds= 10) {
|
||||
// 读取图像
|
||||
// cv::Mat image = cv::imread(imagePath, cv::IMREAD_GRAYSCALE);
|
||||
@ -993,7 +782,9 @@ std::vector<std::vector<uint8_t>> generateMaskFromMatImage(const cv::Mat& image,
|
||||
|
||||
bool iniColor()
|
||||
{
|
||||
read_params_from_file((getConfigDirectory()+"/color_range_config.txt").toStdString(), params);
|
||||
// read_params_from_file((getConfigDirectory()+"/color_range_config.txt").toStdString(), params);
|
||||
// loadConfig(getConfigDirectory()+"/color_range_config.txt");
|
||||
// read_color((getConfigDirectory()+"/colors.txt").toStdString(), colors);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
14
camera.h
14
camera.h
@ -23,6 +23,7 @@
|
||||
#include <QTcpServer>
|
||||
#include "globals.h"
|
||||
#include "img_utils.h"
|
||||
#include "color_range.h"
|
||||
|
||||
extern MIL_ID MilApplication;
|
||||
extern MIL_ID MilSystem;
|
||||
@ -79,26 +80,17 @@ MIL_INT MFTYPE ProcessingFunction1(MIL_INT HookType, MIL_ID HookId, void* HookDa
|
||||
|
||||
|
||||
//图像处理
|
||||
std::vector<int> psLabToOpenCVLab(const std::vector<int>& lab_ps);
|
||||
|
||||
std::vector<int> opencvLabToPsLab(const std::vector<int>& lab_cv);
|
||||
|
||||
std::unordered_map<std::string, int> loadConfig(const std::string& filename);
|
||||
|
||||
void lab_process(const MIL_ID& inputImage, MIL_ID& outputImageLab, const std::map<std::string, int>& params);
|
||||
|
||||
void hsv_process(const MIL_ID& inputImage, MIL_ID& outputImageHSV, const std::map<std::string, int>& params);
|
||||
|
||||
void lab_process_raw(const MIL_ID& inputImage, MIL_ID& outputImageLab, const std::map<std::string, int>& params,const std::vector<std::string>& color_vector);
|
||||
|
||||
void high_sat_detect(const MIL_ID& inputImage, MIL_ID& outputImage, const std::map<std::string, int>& params);
|
||||
|
||||
#define MIN_AREA 30
|
||||
|
||||
extern std::map<std::string, int> params;
|
||||
|
||||
void read_params_from_file(const std::string& filename, std::map<std::string, int>& params) ;
|
||||
|
||||
void read_color(const std::string& filename, std::vector<std::string>& colors);
|
||||
|
||||
pair<vector<vector<uint8_t>>, vector<vector<uint8_t>>> applyRowRangeDelay(
|
||||
const vector<vector<uint8_t>>& mask,
|
||||
const vector<vector<uint8_t>>& tail,
|
||||
|
||||
@ -15,12 +15,12 @@ blue_b_min = -48
|
||||
blue_b_max = -8
|
||||
|
||||
# Orange color parameters
|
||||
orange_L_min = 60
|
||||
orange_L_max = 60
|
||||
orange_a_min = 6
|
||||
orange_a_max = 6
|
||||
orange_b_min = 20
|
||||
orange_b_max = 46
|
||||
orange_L_min = 63
|
||||
orange_L_max = 78
|
||||
orange_a_min = 7
|
||||
orange_a_max = 14
|
||||
orange_b_min = 23
|
||||
orange_b_max = 47
|
||||
|
||||
# Black color parameters
|
||||
black_L_min = 0
|
||||
@ -46,6 +46,14 @@ purple_a_max = 20
|
||||
purple_b_min = -45
|
||||
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 = 165
|
||||
|
||||
7
config/colors.txt
Normal file
7
config/colors.txt
Normal file
@ -0,0 +1,7 @@
|
||||
green
|
||||
blue
|
||||
orange
|
||||
black
|
||||
red
|
||||
purple
|
||||
yellow
|
||||
@ -11,6 +11,7 @@ CONFIG += console
|
||||
|
||||
SOURCES += \
|
||||
camera.cpp \
|
||||
color_range.cpp \
|
||||
detectionworker.cpp \
|
||||
globals.cpp \
|
||||
img_utils.cpp \
|
||||
@ -21,6 +22,7 @@ SOURCES += \
|
||||
|
||||
HEADERS += \
|
||||
camera.h \
|
||||
color_range.h \
|
||||
detectionworker.h \
|
||||
globals.h \
|
||||
img_utils.h \
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 15.0.0, 2025-01-01T23:01:59. -->
|
||||
<!-- Written by QtCreator 15.0.0, 2025-01-02T20:20:23. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
|
||||
@ -17,6 +17,9 @@ MIL_ID gMask0 = 0;
|
||||
|
||||
QMutex gMaskMutex1;
|
||||
MIL_ID gMask1 = 0;
|
||||
//艳丽检测参数
|
||||
std::map<std::string, int> params;
|
||||
std::vector<std::string> colors;
|
||||
|
||||
// 初始化 CameraData 实例
|
||||
DetectionResult g_detection_result[2];
|
||||
@ -40,6 +43,7 @@ std::atomic<bool>* g_recognitionRunning[2] = { nullptr, nullptr };
|
||||
bool g_dl_enable[2] = { true, true };
|
||||
bool g_traditional_enable[2] = { true, true };
|
||||
|
||||
|
||||
// 初始化全局ONNXRunner实例数组
|
||||
ONNXRunner* g_runner_array[2] = { nullptr, nullptr };
|
||||
|
||||
@ -173,3 +177,6 @@ struct GlobalsInitializer {
|
||||
}
|
||||
} globalsInitializerInstance; // 全局实例,确保在程序结束时清理
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -143,4 +143,11 @@ extern std::atomic<bool>* g_recognitionRunning[2];
|
||||
// 定义全局ONNXRunner实例数组
|
||||
extern ONNXRunner* g_runner_array[2];
|
||||
|
||||
extern std::map<std::string, int> params;
|
||||
extern std::vector<std::string> colors;
|
||||
|
||||
|
||||
|
||||
#define MIN_AREA 30
|
||||
|
||||
#endif // GLOBALS_H
|
||||
|
||||
@ -282,3 +282,5 @@ void VectorToImg(const std::vector<std::vector<uint8_t> > &array, const std::str
|
||||
// 将图像保存为文件,传入的image_path指定保存路径和文件名
|
||||
imwrite(image_path, image);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
# Green color parameters
|
||||
green_L_min = 16
|
||||
green_L_max = 56
|
||||
green_a_min = -33
|
||||
@ -6,7 +5,6 @@ green_a_max = -11
|
||||
green_b_min = -7
|
||||
green_b_max = 24
|
||||
|
||||
# Blue color parameters
|
||||
blue_L_min = 20
|
||||
blue_L_max = 43
|
||||
blue_a_min = -13
|
||||
@ -14,15 +12,13 @@ blue_a_max = 22
|
||||
blue_b_min = -48
|
||||
blue_b_max = -8
|
||||
|
||||
# Orange color parameters
|
||||
orange_L_min = 60
|
||||
orange_L_max = 60
|
||||
orange_a_min = 6
|
||||
orange_a_max = 6
|
||||
orange_b_min = 20
|
||||
orange_b_max = 46
|
||||
orange_L_min = 63
|
||||
orange_L_max = 78
|
||||
orange_a_min = 7
|
||||
orange_a_max = 14
|
||||
orange_b_min = 23
|
||||
orange_b_max = 47
|
||||
|
||||
# Black color parameters
|
||||
black_L_min = 0
|
||||
black_L_max = 8
|
||||
black_a_min = -4
|
||||
@ -30,7 +26,6 @@ black_a_max = 2
|
||||
black_b_min = -3
|
||||
black_b_max = 4
|
||||
|
||||
# Red color parameters
|
||||
red_L_min = 23
|
||||
red_L_max = 48
|
||||
red_a_min = 12
|
||||
@ -38,7 +33,6 @@ red_a_max = 55
|
||||
red_b_min = -80
|
||||
red_b_max = 37
|
||||
|
||||
# Purple color parameters
|
||||
purple_L_min = 38
|
||||
purple_L_max = 54
|
||||
purple_a_min = 10
|
||||
@ -46,7 +40,13 @@ purple_a_max = 20
|
||||
purple_b_min = -45
|
||||
purple_b_max = 1
|
||||
|
||||
# Other 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
|
||||
|
||||
lab_denoising = 1
|
||||
saturation_threshold = 165
|
||||
saturation_denoising = 1
|
||||
saturation_threshold = 165
|
||||
|
||||
349
ui_widget.h
349
ui_widget.h
@ -85,7 +85,9 @@ public:
|
||||
QSpinBox *spinbox_delaytime;
|
||||
QSpinBox *spinbox_encoder;
|
||||
QSpinBox *spinbox_valve;
|
||||
QPushButton *btn_tab3_backtab2;
|
||||
QPushButton *btn_tab3_backtab2_2;
|
||||
QWidget *layoutWidget;
|
||||
QVBoxLayout *verticalLayout_17;
|
||||
QLabel *label_title_4;
|
||||
QGroupBox *groupBox_2;
|
||||
QLabel *label_explosure_2;
|
||||
@ -95,7 +97,39 @@ public:
|
||||
QGroupBox *groupBox_3;
|
||||
QPushButton *btn_test_single;
|
||||
QPushButton *btn_stop_test;
|
||||
QPushButton *btn_tab3_backtab2_2;
|
||||
QWidget *layoutWidget1;
|
||||
QVBoxLayout *verticalLayout_19;
|
||||
QVBoxLayout *verticalLayout_18;
|
||||
QHBoxLayout *horizontalLayout_39;
|
||||
QLabel *label_31;
|
||||
QComboBox *comboBox_colorlist;
|
||||
QHBoxLayout *horizontalLayout_36;
|
||||
QLabel *label_33;
|
||||
QSpinBox *spinBox_L_max;
|
||||
QLabel *label_32;
|
||||
QSpinBox *spinBox_L_min;
|
||||
QHBoxLayout *horizontalLayout_37;
|
||||
QLabel *label_34;
|
||||
QSpinBox *spinBox_A_max;
|
||||
QLabel *label_35;
|
||||
QSpinBox *spinBox_A_min;
|
||||
QHBoxLayout *horizontalLayout_38;
|
||||
QLabel *label_36;
|
||||
QSpinBox *spinBox_B_max;
|
||||
QLabel *label_37;
|
||||
QSpinBox *spinBox_B_min;
|
||||
QHBoxLayout *horizontalLayout_40;
|
||||
QLabel *label_38;
|
||||
QLineEdit *lineEdit_color;
|
||||
QHBoxLayout *horizontalLayout_42;
|
||||
QPushButton *btn_add_color;
|
||||
QPushButton *btn_del_color;
|
||||
QPushButton *btn_reset_color;
|
||||
QHBoxLayout *horizontalLayout_41;
|
||||
QSpacerItem *horizontalSpacer_25;
|
||||
QPushButton *btn_setColor;
|
||||
QSpacerItem *horizontalSpacer_26;
|
||||
QPushButton *btn_tab3_backtab2;
|
||||
QWidget *tab_4;
|
||||
QVBoxLayout *verticalLayout_8;
|
||||
QFrame *frame_4;
|
||||
@ -575,7 +609,7 @@ public:
|
||||
"border-color: rgb(0, 0, 0);"));
|
||||
btn_set_lower = new QPushButton(groupBox_4);
|
||||
btn_set_lower->setObjectName("btn_set_lower");
|
||||
btn_set_lower->setGeometry(QRect(30, 470, 231, 141));
|
||||
btn_set_lower->setGeometry(QRect(210, 450, 231, 141));
|
||||
frame_3 = new QFrame(groupBox_4);
|
||||
frame_3->setObjectName("frame_3");
|
||||
frame_3->setGeometry(QRect(20, 80, 698, 373));
|
||||
@ -637,15 +671,23 @@ public:
|
||||
|
||||
horizontalLayout_6->addLayout(verticalLayout_4);
|
||||
|
||||
btn_tab3_backtab2 = new QPushButton(groupBox_4);
|
||||
btn_tab3_backtab2->setObjectName("btn_tab3_backtab2");
|
||||
btn_tab3_backtab2->setGeometry(QRect(480, 470, 231, 141));
|
||||
label_title_4 = new QLabel(tab_3);
|
||||
btn_tab3_backtab2_2 = new QPushButton(tab_3);
|
||||
btn_tab3_backtab2_2->setObjectName("btn_tab3_backtab2_2");
|
||||
btn_tab3_backtab2_2->setGeometry(QRect(100, 750, 231, 141));
|
||||
btn_tab3_backtab2_2->setStyleSheet(QString::fromUtf8("font: 700 48pt \"Microsoft YaHei UI\";"));
|
||||
layoutWidget = new QWidget(tab_3);
|
||||
layoutWidget->setObjectName("layoutWidget");
|
||||
layoutWidget->setGeometry(QRect(1630, 40, 94, 147));
|
||||
verticalLayout_17 = new QVBoxLayout(layoutWidget);
|
||||
verticalLayout_17->setObjectName("verticalLayout_17");
|
||||
verticalLayout_17->setContentsMargins(0, 0, 0, 0);
|
||||
label_title_4 = new QLabel(layoutWidget);
|
||||
label_title_4->setObjectName("label_title_4");
|
||||
label_title_4->setGeometry(QRect(920, 150, 91, 21));
|
||||
groupBox_2 = new QGroupBox(tab_3);
|
||||
|
||||
verticalLayout_17->addWidget(label_title_4);
|
||||
|
||||
groupBox_2 = new QGroupBox(layoutWidget);
|
||||
groupBox_2->setObjectName("groupBox_2");
|
||||
groupBox_2->setGeometry(QRect(1050, 240, 331, 91));
|
||||
label_explosure_2 = new QLabel(groupBox_2);
|
||||
label_explosure_2->setObjectName("label_explosure_2");
|
||||
label_explosure_2->setGeometry(QRect(30, 40, 31, 16));
|
||||
@ -658,18 +700,245 @@ public:
|
||||
btn_stop_single = new QPushButton(groupBox_2);
|
||||
btn_stop_single->setObjectName("btn_stop_single");
|
||||
btn_stop_single->setGeometry(QRect(240, 40, 75, 23));
|
||||
groupBox_3 = new QGroupBox(tab_3);
|
||||
|
||||
verticalLayout_17->addWidget(groupBox_2);
|
||||
|
||||
groupBox_3 = new QGroupBox(layoutWidget);
|
||||
groupBox_3->setObjectName("groupBox_3");
|
||||
groupBox_3->setGeometry(QRect(1050, 420, 331, 91));
|
||||
btn_test_single = new QPushButton(groupBox_3);
|
||||
btn_test_single->setObjectName("btn_test_single");
|
||||
btn_test_single->setGeometry(QRect(60, 40, 75, 23));
|
||||
btn_stop_test = new QPushButton(groupBox_3);
|
||||
btn_stop_test->setObjectName("btn_stop_test");
|
||||
btn_stop_test->setGeometry(QRect(210, 40, 75, 23));
|
||||
btn_tab3_backtab2_2 = new QPushButton(tab_3);
|
||||
btn_tab3_backtab2_2->setObjectName("btn_tab3_backtab2_2");
|
||||
btn_tab3_backtab2_2->setGeometry(QRect(510, 770, 231, 141));
|
||||
|
||||
verticalLayout_17->addWidget(groupBox_3);
|
||||
|
||||
layoutWidget1 = new QWidget(tab_3);
|
||||
layoutWidget1->setObjectName("layoutWidget1");
|
||||
layoutWidget1->setGeometry(QRect(770, 40, 854, 769));
|
||||
verticalLayout_19 = new QVBoxLayout(layoutWidget1);
|
||||
verticalLayout_19->setSpacing(20);
|
||||
verticalLayout_19->setObjectName("verticalLayout_19");
|
||||
verticalLayout_19->setContentsMargins(0, 0, 0, 0);
|
||||
verticalLayout_18 = new QVBoxLayout();
|
||||
verticalLayout_18->setSpacing(30);
|
||||
verticalLayout_18->setObjectName("verticalLayout_18");
|
||||
horizontalLayout_39 = new QHBoxLayout();
|
||||
horizontalLayout_39->setObjectName("horizontalLayout_39");
|
||||
label_31 = new QLabel(layoutWidget1);
|
||||
label_31->setObjectName("label_31");
|
||||
label_31->setStyleSheet(QString::fromUtf8("font: 700 48pt \"Microsoft YaHei UI\";"));
|
||||
|
||||
horizontalLayout_39->addWidget(label_31);
|
||||
|
||||
comboBox_colorlist = new QComboBox(layoutWidget1);
|
||||
comboBox_colorlist->setObjectName("comboBox_colorlist");
|
||||
comboBox_colorlist->setMinimumSize(QSize(250, 80));
|
||||
comboBox_colorlist->setStyleSheet(QString::fromUtf8("font: 20pt \"Microsoft YaHei UI\";"));
|
||||
|
||||
horizontalLayout_39->addWidget(comboBox_colorlist);
|
||||
|
||||
|
||||
verticalLayout_18->addLayout(horizontalLayout_39);
|
||||
|
||||
horizontalLayout_36 = new QHBoxLayout();
|
||||
horizontalLayout_36->setObjectName("horizontalLayout_36");
|
||||
label_33 = new QLabel(layoutWidget1);
|
||||
label_33->setObjectName("label_33");
|
||||
label_33->setStyleSheet(QString::fromUtf8("font: 22pt \"Microsoft YaHei UI\";"));
|
||||
|
||||
horizontalLayout_36->addWidget(label_33);
|
||||
|
||||
spinBox_L_max = new QSpinBox(layoutWidget1);
|
||||
spinBox_L_max->setObjectName("spinBox_L_max");
|
||||
QSizePolicy sizePolicy2(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Preferred);
|
||||
sizePolicy2.setHorizontalStretch(0);
|
||||
sizePolicy2.setVerticalStretch(0);
|
||||
sizePolicy2.setHeightForWidth(spinBox_L_max->sizePolicy().hasHeightForWidth());
|
||||
spinBox_L_max->setSizePolicy(sizePolicy2);
|
||||
spinBox_L_max->setMinimumSize(QSize(100, 80));
|
||||
spinBox_L_max->setStyleSheet(QString::fromUtf8("font: 20pt \"Microsoft YaHei UI\";"));
|
||||
spinBox_L_max->setMinimum(0);
|
||||
spinBox_L_max->setMaximum(100);
|
||||
|
||||
horizontalLayout_36->addWidget(spinBox_L_max);
|
||||
|
||||
label_32 = new QLabel(layoutWidget1);
|
||||
label_32->setObjectName("label_32");
|
||||
label_32->setStyleSheet(QString::fromUtf8("font: 22pt \"Microsoft YaHei UI\";"));
|
||||
|
||||
horizontalLayout_36->addWidget(label_32);
|
||||
|
||||
spinBox_L_min = new QSpinBox(layoutWidget1);
|
||||
spinBox_L_min->setObjectName("spinBox_L_min");
|
||||
sizePolicy2.setHeightForWidth(spinBox_L_min->sizePolicy().hasHeightForWidth());
|
||||
spinBox_L_min->setSizePolicy(sizePolicy2);
|
||||
spinBox_L_min->setMinimumSize(QSize(100, 80));
|
||||
spinBox_L_min->setStyleSheet(QString::fromUtf8("font: 20pt \"Microsoft YaHei UI\";"));
|
||||
spinBox_L_min->setMinimum(0);
|
||||
spinBox_L_min->setMaximum(100);
|
||||
|
||||
horizontalLayout_36->addWidget(spinBox_L_min);
|
||||
|
||||
|
||||
verticalLayout_18->addLayout(horizontalLayout_36);
|
||||
|
||||
horizontalLayout_37 = new QHBoxLayout();
|
||||
horizontalLayout_37->setObjectName("horizontalLayout_37");
|
||||
label_34 = new QLabel(layoutWidget1);
|
||||
label_34->setObjectName("label_34");
|
||||
label_34->setStyleSheet(QString::fromUtf8("font: 22pt \"Microsoft YaHei UI\";"));
|
||||
|
||||
horizontalLayout_37->addWidget(label_34);
|
||||
|
||||
spinBox_A_max = new QSpinBox(layoutWidget1);
|
||||
spinBox_A_max->setObjectName("spinBox_A_max");
|
||||
sizePolicy2.setHeightForWidth(spinBox_A_max->sizePolicy().hasHeightForWidth());
|
||||
spinBox_A_max->setSizePolicy(sizePolicy2);
|
||||
spinBox_A_max->setMinimumSize(QSize(100, 80));
|
||||
spinBox_A_max->setStyleSheet(QString::fromUtf8("font: 20pt \"Microsoft YaHei UI\";"));
|
||||
spinBox_A_max->setMinimum(-128);
|
||||
spinBox_A_max->setMaximum(128);
|
||||
|
||||
horizontalLayout_37->addWidget(spinBox_A_max);
|
||||
|
||||
label_35 = new QLabel(layoutWidget1);
|
||||
label_35->setObjectName("label_35");
|
||||
label_35->setStyleSheet(QString::fromUtf8("font: 22pt \"Microsoft YaHei UI\";"));
|
||||
|
||||
horizontalLayout_37->addWidget(label_35);
|
||||
|
||||
spinBox_A_min = new QSpinBox(layoutWidget1);
|
||||
spinBox_A_min->setObjectName("spinBox_A_min");
|
||||
sizePolicy2.setHeightForWidth(spinBox_A_min->sizePolicy().hasHeightForWidth());
|
||||
spinBox_A_min->setSizePolicy(sizePolicy2);
|
||||
spinBox_A_min->setMinimumSize(QSize(100, 80));
|
||||
spinBox_A_min->setStyleSheet(QString::fromUtf8("font: 20pt \"Microsoft YaHei UI\";"));
|
||||
spinBox_A_min->setMinimum(-128);
|
||||
spinBox_A_min->setMaximum(128);
|
||||
|
||||
horizontalLayout_37->addWidget(spinBox_A_min);
|
||||
|
||||
|
||||
verticalLayout_18->addLayout(horizontalLayout_37);
|
||||
|
||||
horizontalLayout_38 = new QHBoxLayout();
|
||||
horizontalLayout_38->setObjectName("horizontalLayout_38");
|
||||
label_36 = new QLabel(layoutWidget1);
|
||||
label_36->setObjectName("label_36");
|
||||
label_36->setStyleSheet(QString::fromUtf8("font: 22pt \"Microsoft YaHei UI\";"));
|
||||
|
||||
horizontalLayout_38->addWidget(label_36);
|
||||
|
||||
spinBox_B_max = new QSpinBox(layoutWidget1);
|
||||
spinBox_B_max->setObjectName("spinBox_B_max");
|
||||
sizePolicy2.setHeightForWidth(spinBox_B_max->sizePolicy().hasHeightForWidth());
|
||||
spinBox_B_max->setSizePolicy(sizePolicy2);
|
||||
spinBox_B_max->setMinimumSize(QSize(100, 80));
|
||||
spinBox_B_max->setStyleSheet(QString::fromUtf8("font: 20pt \"Microsoft YaHei UI\";"));
|
||||
spinBox_B_max->setMinimum(-128);
|
||||
spinBox_B_max->setMaximum(128);
|
||||
|
||||
horizontalLayout_38->addWidget(spinBox_B_max);
|
||||
|
||||
label_37 = new QLabel(layoutWidget1);
|
||||
label_37->setObjectName("label_37");
|
||||
label_37->setStyleSheet(QString::fromUtf8("font: 22pt \"Microsoft YaHei UI\";"));
|
||||
|
||||
horizontalLayout_38->addWidget(label_37);
|
||||
|
||||
spinBox_B_min = new QSpinBox(layoutWidget1);
|
||||
spinBox_B_min->setObjectName("spinBox_B_min");
|
||||
sizePolicy2.setHeightForWidth(spinBox_B_min->sizePolicy().hasHeightForWidth());
|
||||
spinBox_B_min->setSizePolicy(sizePolicy2);
|
||||
spinBox_B_min->setMinimumSize(QSize(100, 80));
|
||||
spinBox_B_min->setStyleSheet(QString::fromUtf8("font: 20pt \"Microsoft YaHei UI\";"));
|
||||
spinBox_B_min->setMinimum(-128);
|
||||
spinBox_B_min->setMaximum(128);
|
||||
|
||||
horizontalLayout_38->addWidget(spinBox_B_min);
|
||||
|
||||
|
||||
verticalLayout_18->addLayout(horizontalLayout_38);
|
||||
|
||||
|
||||
verticalLayout_19->addLayout(verticalLayout_18);
|
||||
|
||||
horizontalLayout_40 = new QHBoxLayout();
|
||||
horizontalLayout_40->setObjectName("horizontalLayout_40");
|
||||
label_38 = new QLabel(layoutWidget1);
|
||||
label_38->setObjectName("label_38");
|
||||
label_38->setStyleSheet(QString::fromUtf8("font: 20pt \"Microsoft YaHei UI\";"));
|
||||
|
||||
horizontalLayout_40->addWidget(label_38);
|
||||
|
||||
lineEdit_color = new QLineEdit(layoutWidget1);
|
||||
lineEdit_color->setObjectName("lineEdit_color");
|
||||
lineEdit_color->setEnabled(true);
|
||||
lineEdit_color->setStyleSheet(QString::fromUtf8("font: 20pt \"Microsoft YaHei UI\";"));
|
||||
|
||||
horizontalLayout_40->addWidget(lineEdit_color);
|
||||
|
||||
|
||||
verticalLayout_19->addLayout(horizontalLayout_40);
|
||||
|
||||
horizontalLayout_42 = new QHBoxLayout();
|
||||
horizontalLayout_42->setSpacing(50);
|
||||
horizontalLayout_42->setObjectName("horizontalLayout_42");
|
||||
btn_add_color = new QPushButton(layoutWidget1);
|
||||
btn_add_color->setObjectName("btn_add_color");
|
||||
QSizePolicy sizePolicy3(QSizePolicy::Policy::Minimum, QSizePolicy::Policy::Minimum);
|
||||
sizePolicy3.setHorizontalStretch(0);
|
||||
sizePolicy3.setVerticalStretch(0);
|
||||
sizePolicy3.setHeightForWidth(btn_add_color->sizePolicy().hasHeightForWidth());
|
||||
btn_add_color->setSizePolicy(sizePolicy3);
|
||||
btn_add_color->setMinimumSize(QSize(250, 80));
|
||||
btn_add_color->setStyleSheet(QString::fromUtf8("font: 700 40pt \"Microsoft YaHei UI\";"));
|
||||
|
||||
horizontalLayout_42->addWidget(btn_add_color);
|
||||
|
||||
btn_del_color = new QPushButton(layoutWidget1);
|
||||
btn_del_color->setObjectName("btn_del_color");
|
||||
btn_del_color->setMinimumSize(QSize(250, 120));
|
||||
btn_del_color->setStyleSheet(QString::fromUtf8("font: 700 40pt \"Microsoft YaHei UI\";"));
|
||||
|
||||
horizontalLayout_42->addWidget(btn_del_color);
|
||||
|
||||
btn_reset_color = new QPushButton(layoutWidget1);
|
||||
btn_reset_color->setObjectName("btn_reset_color");
|
||||
btn_reset_color->setMinimumSize(QSize(250, 120));
|
||||
btn_reset_color->setStyleSheet(QString::fromUtf8("font: 700 40pt \"Microsoft YaHei UI\";"));
|
||||
|
||||
horizontalLayout_42->addWidget(btn_reset_color);
|
||||
|
||||
|
||||
verticalLayout_19->addLayout(horizontalLayout_42);
|
||||
|
||||
horizontalLayout_41 = new QHBoxLayout();
|
||||
horizontalLayout_41->setObjectName("horizontalLayout_41");
|
||||
horizontalSpacer_25 = new QSpacerItem(40, 20, QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Minimum);
|
||||
|
||||
horizontalLayout_41->addItem(horizontalSpacer_25);
|
||||
|
||||
btn_setColor = new QPushButton(layoutWidget1);
|
||||
btn_setColor->setObjectName("btn_setColor");
|
||||
btn_setColor->setMinimumSize(QSize(250, 120));
|
||||
btn_setColor->setStyleSheet(QString::fromUtf8("font: 700 48pt \"Microsoft YaHei UI\";"));
|
||||
|
||||
horizontalLayout_41->addWidget(btn_setColor);
|
||||
|
||||
horizontalSpacer_26 = new QSpacerItem(40, 20, QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Minimum);
|
||||
|
||||
horizontalLayout_41->addItem(horizontalSpacer_26);
|
||||
|
||||
|
||||
verticalLayout_19->addLayout(horizontalLayout_41);
|
||||
|
||||
btn_tab3_backtab2 = new QPushButton(tab_3);
|
||||
btn_tab3_backtab2->setObjectName("btn_tab3_backtab2");
|
||||
btn_tab3_backtab2->setGeometry(QRect(390, 750, 231, 141));
|
||||
btn_tab3_backtab2->setStyleSheet(QString::fromUtf8("font: 700 48pt \"Microsoft YaHei UI\";"));
|
||||
tabWidget->addTab(tab_3, QString());
|
||||
tab_4 = new QWidget();
|
||||
tab_4->setObjectName("tab_4");
|
||||
@ -707,9 +976,6 @@ public:
|
||||
|
||||
btn_settings = new QPushButton(frame_4);
|
||||
btn_settings->setObjectName("btn_settings");
|
||||
QSizePolicy sizePolicy2(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Preferred);
|
||||
sizePolicy2.setHorizontalStretch(0);
|
||||
sizePolicy2.setVerticalStretch(0);
|
||||
sizePolicy2.setHeightForWidth(btn_settings->sizePolicy().hasHeightForWidth());
|
||||
btn_settings->setSizePolicy(sizePolicy2);
|
||||
btn_settings->setMinimumSize(QSize(0, 0));
|
||||
@ -797,11 +1063,11 @@ public:
|
||||
horizontalLayout_16->setContentsMargins(38, 20, 38, 20);
|
||||
frame_running_time = new QFrame(frame_5);
|
||||
frame_running_time->setObjectName("frame_running_time");
|
||||
QSizePolicy sizePolicy3(QSizePolicy::Policy::Minimum, QSizePolicy::Policy::Expanding);
|
||||
sizePolicy3.setHorizontalStretch(0);
|
||||
sizePolicy3.setVerticalStretch(0);
|
||||
sizePolicy3.setHeightForWidth(frame_running_time->sizePolicy().hasHeightForWidth());
|
||||
frame_running_time->setSizePolicy(sizePolicy3);
|
||||
QSizePolicy sizePolicy4(QSizePolicy::Policy::Minimum, QSizePolicy::Policy::Expanding);
|
||||
sizePolicy4.setHorizontalStretch(0);
|
||||
sizePolicy4.setVerticalStretch(0);
|
||||
sizePolicy4.setHeightForWidth(frame_running_time->sizePolicy().hasHeightForWidth());
|
||||
frame_running_time->setSizePolicy(sizePolicy4);
|
||||
frame_running_time->setMinimumSize(QSize(346, 0));
|
||||
frame_running_time->setMaximumSize(QSize(16777215, 16777215));
|
||||
frame_running_time->setStyleSheet(QString::fromUtf8("QFrame#frame_running_time{\n"
|
||||
@ -851,11 +1117,8 @@ public:
|
||||
|
||||
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_hourUnit->sizePolicy().hasHeightForWidth());
|
||||
label_hourUnit->setSizePolicy(sizePolicy4);
|
||||
sizePolicy3.setHeightForWidth(label_hourUnit->sizePolicy().hasHeightForWidth());
|
||||
label_hourUnit->setSizePolicy(sizePolicy3);
|
||||
label_hourUnit->setStyleSheet(QString::fromUtf8("font: 700 20pt \"Microsoft YaHei UI\";\n"
|
||||
"color:rgb(105,186,210);\n"
|
||||
"background-color: #2d2d2d;;\n"
|
||||
@ -874,8 +1137,8 @@ public:
|
||||
|
||||
label_minuteUnit = new QLabel(frame_running_time);
|
||||
label_minuteUnit->setObjectName("label_minuteUnit");
|
||||
sizePolicy4.setHeightForWidth(label_minuteUnit->sizePolicy().hasHeightForWidth());
|
||||
label_minuteUnit->setSizePolicy(sizePolicy4);
|
||||
sizePolicy3.setHeightForWidth(label_minuteUnit->sizePolicy().hasHeightForWidth());
|
||||
label_minuteUnit->setSizePolicy(sizePolicy3);
|
||||
label_minuteUnit->setStyleSheet(QString::fromUtf8("font: 700 20pt \"Microsoft YaHei UI\";\n"
|
||||
"color:rgb(105,186,210);\n"
|
||||
"background-color: #2d2d2d;;\n"
|
||||
@ -949,8 +1212,8 @@ public:
|
||||
|
||||
frame_valve = new QFrame(frame_5);
|
||||
frame_valve->setObjectName("frame_valve");
|
||||
sizePolicy3.setHeightForWidth(frame_valve->sizePolicy().hasHeightForWidth());
|
||||
frame_valve->setSizePolicy(sizePolicy3);
|
||||
sizePolicy4.setHeightForWidth(frame_valve->sizePolicy().hasHeightForWidth());
|
||||
frame_valve->setSizePolicy(sizePolicy4);
|
||||
frame_valve->setMaximumSize(QSize(16777215, 16777215));
|
||||
frame_valve->setStyleSheet(QString::fromUtf8("QFrame#frame_valve{\n"
|
||||
"background: #2d2d2d;\n"
|
||||
@ -999,8 +1262,8 @@ public:
|
||||
|
||||
label_17 = new QLabel(frame_valve);
|
||||
label_17->setObjectName("label_17");
|
||||
sizePolicy4.setHeightForWidth(label_17->sizePolicy().hasHeightForWidth());
|
||||
label_17->setSizePolicy(sizePolicy4);
|
||||
sizePolicy3.setHeightForWidth(label_17->sizePolicy().hasHeightForWidth());
|
||||
label_17->setSizePolicy(sizePolicy3);
|
||||
label_17->setStyleSheet(QString::fromUtf8("font: 700 20pt \"Microsoft YaHei UI\";\n"
|
||||
"color:rgb(105,186,210);\n"
|
||||
"background-color: #2d2d2d;;\n"
|
||||
@ -1189,7 +1452,7 @@ public:
|
||||
|
||||
retranslateUi(Widget);
|
||||
|
||||
tabWidget->setCurrentIndex(1);
|
||||
tabWidget->setCurrentIndex(2);
|
||||
|
||||
|
||||
QMetaObject::connectSlotsByName(Widget);
|
||||
@ -1228,7 +1491,7 @@ public:
|
||||
label_delaytime->setText(QCoreApplication::translate("Widget", "\345\273\266\350\277\237\346\227\266\351\227\264", 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));
|
||||
btn_tab3_backtab2->setText(QCoreApplication::translate("Widget", "\350\277\224\345\233\236", nullptr));
|
||||
btn_tab3_backtab2_2->setText(QCoreApplication::translate("Widget", "home", nullptr));
|
||||
label_title_4->setText(QCoreApplication::translate("Widget", "\345\226\267\351\230\200\346\265\213\350\257\225\347\225\214\351\235\242", 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));
|
||||
@ -1237,7 +1500,19 @@ public:
|
||||
groupBox_3->setTitle(QCoreApplication::translate("Widget", "\350\207\252\345\212\250\345\226\267\351\230\200\346\265\213\350\257\225", nullptr));
|
||||
btn_test_single->setText(QCoreApplication::translate("Widget", "\345\274\200\345\247\213\346\265\213\350\257\225", nullptr));
|
||||
btn_stop_test->setText(QCoreApplication::translate("Widget", "\345\201\234\346\255\242\346\265\213\350\257\225", nullptr));
|
||||
btn_tab3_backtab2_2->setText(QCoreApplication::translate("Widget", "home", nullptr));
|
||||
label_31->setText(QCoreApplication::translate("Widget", "\351\242\234\350\211\262", nullptr));
|
||||
label_33->setText(QCoreApplication::translate("Widget", "L_max", nullptr));
|
||||
label_32->setText(QCoreApplication::translate("Widget", "L_min", nullptr));
|
||||
label_34->setText(QCoreApplication::translate("Widget", "A_max", nullptr));
|
||||
label_35->setText(QCoreApplication::translate("Widget", "A_min", nullptr));
|
||||
label_36->setText(QCoreApplication::translate("Widget", "B_max", nullptr));
|
||||
label_37->setText(QCoreApplication::translate("Widget", "B_min", nullptr));
|
||||
label_38->setText(QCoreApplication::translate("Widget", "\346\226\260\345\273\272\351\242\234\350\211\262", nullptr));
|
||||
btn_add_color->setText(QCoreApplication::translate("Widget", "\346\267\273\345\212\240\351\242\234\350\211\262", nullptr));
|
||||
btn_del_color->setText(QCoreApplication::translate("Widget", "\345\210\240\351\231\244\351\242\234\350\211\262", nullptr));
|
||||
btn_reset_color->setText(QCoreApplication::translate("Widget", "\344\270\200\351\224\256\346\201\242\345\244\215", nullptr));
|
||||
btn_setColor->setText(QCoreApplication::translate("Widget", "\350\256\276\347\275\256\351\242\234\350\211\262", nullptr));
|
||||
btn_tab3_backtab2->setText(QCoreApplication::translate("Widget", "\350\277\224\345\233\236", 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_currentDateTime->setText(QCoreApplication::translate("Widget", "2024-12-26 10:30AM", nullptr));
|
||||
|
||||
381
widget.cpp
381
widget.cpp
@ -15,6 +15,14 @@
|
||||
#include <QTabBar>
|
||||
#include <img_utils.h>
|
||||
#include <detectionworker.h>
|
||||
#include <Qstring>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include <QDebug>
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <warning.h>
|
||||
#include <QMessageBox>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -54,10 +62,11 @@ Widget::Widget(QWidget *parent)
|
||||
ui->camera_1_img->setScaledContents(false);
|
||||
|
||||
iniOnnx();
|
||||
iniColor();
|
||||
// iniColor();
|
||||
loadConfig(getConfigDirectory()+"/color_range_config.txt");
|
||||
iniLowMac();
|
||||
iniCamera();
|
||||
|
||||
update_colorlist();
|
||||
// 初始化存储工作者和线程
|
||||
storageWorker = new StorageWorker();
|
||||
storageWorker->moveToThread(&storageThread);
|
||||
@ -448,3 +457,371 @@ void Widget::on_btn_settings_clicked()
|
||||
ui->tabWidget->setCurrentIndex(2);
|
||||
}
|
||||
|
||||
|
||||
bool Widget::saveConfig(const QString &filePath, const std::map<std::string, int>& params_to_set, const std::vector<std::string>& color_vector_to_set)
|
||||
{
|
||||
QFile file(filePath);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
|
||||
{
|
||||
qWarning() << "无法打开配置文件进行写入:" << filePath;
|
||||
return false;
|
||||
}
|
||||
|
||||
QTextStream out(&file);
|
||||
// Qt 6 默认使用 UTF-8 编码,无需设置编码
|
||||
|
||||
// 保存每种颜色的参数
|
||||
for (const auto &color : color_vector_to_set)
|
||||
{
|
||||
std::string color_lower = color;
|
||||
// 将颜色名称首字母小写以匹配键名
|
||||
if (!color_lower.empty())
|
||||
{
|
||||
color_lower[0] = static_cast<char>(std::tolower(color_lower[0]));
|
||||
}
|
||||
|
||||
try {
|
||||
// 使用 at() 方法访问元素
|
||||
out << QString::fromStdString(color_lower) << "_L_min = " << QString::number(params_to_set.at(color_lower + "_L_min")) << "\n";
|
||||
out << QString::fromStdString(color_lower) << "_L_max = " << QString::number(params_to_set.at(color_lower + "_L_max")) << "\n";
|
||||
out << QString::fromStdString(color_lower) << "_a_min = " << QString::number(params_to_set.at(color_lower + "_a_min")) << "\n";
|
||||
out << QString::fromStdString(color_lower) << "_a_max = " << QString::number(params_to_set.at(color_lower + "_a_max")) << "\n";
|
||||
out << QString::fromStdString(color_lower) << "_b_min = " << QString::number(params_to_set.at(color_lower + "_b_min")) << "\n";
|
||||
out << QString::fromStdString(color_lower) << "_b_max = " << QString::number(params_to_set.at(color_lower + "_b_max")) << "\n\n";
|
||||
}
|
||||
catch (const std::out_of_range& e) {
|
||||
qWarning() << "缺少参数:" << QString::fromStdString(color_lower + "_L_min") << "等在颜色" << QString::fromStdString(color_lower);
|
||||
// 根据需要,您可以决定如何处理缺少的参数,例如设置默认值或跳过
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// 保存其他参数(不涉及颜色参数)
|
||||
for (const auto ¶m : params_to_set)
|
||||
{
|
||||
std::string key = param.first;
|
||||
// 如果不是颜色参数,则保存
|
||||
if (key.find("_L_min") == std::string::npos &&
|
||||
key.find("_L_max") == std::string::npos &&
|
||||
key.find("_a_min") == std::string::npos &&
|
||||
key.find("_a_max") == std::string::npos &&
|
||||
key.find("_b_min") == std::string::npos &&
|
||||
key.find("_b_max") == std::string::npos)
|
||||
{
|
||||
out << QString::fromStdString(key) << " = " << QString::number(param.second) << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
qDebug() << "配置已成功保存到" << filePath;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Widget::loadConfig(const QString &filePath)
|
||||
{
|
||||
QFile file(filePath);
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
|
||||
{
|
||||
qWarning() << "无法打开配置文件进行读取:" << filePath;
|
||||
return false;
|
||||
}
|
||||
|
||||
QTextStream in(&file);
|
||||
// Qt 6 默认使用 UTF-8 编码,无需设置编码
|
||||
|
||||
// 清空当前配置
|
||||
colors.clear();
|
||||
params.clear();
|
||||
|
||||
while (!in.atEnd())
|
||||
{
|
||||
QString line = in.readLine().trimmed();
|
||||
|
||||
// 跳过空行和注释行
|
||||
if (line.isEmpty() || line.startsWith("#"))
|
||||
continue;
|
||||
|
||||
// 处理键值对
|
||||
QStringList keyValue = line.split("=");
|
||||
if (keyValue.size() != 2)
|
||||
continue; // 无效行
|
||||
|
||||
QString key = keyValue[0].trimmed();
|
||||
QString valueStr = keyValue[1].trimmed();
|
||||
bool ok;
|
||||
int value = valueStr.toInt(&ok);
|
||||
if (!ok)
|
||||
{
|
||||
qWarning() << "无效的数值:" << valueStr << "在行:" << line;
|
||||
continue;
|
||||
}
|
||||
|
||||
std::string key_std = key.toStdString();
|
||||
params[key_std] = value;
|
||||
// 检查是否为颜色参数(格式为 color_property,例如 green_L_min)
|
||||
size_t underscorePos = key_std.find('_');
|
||||
if (underscorePos != std::string::npos)
|
||||
{
|
||||
std::string colorName = key_std.substr(0, underscorePos);
|
||||
size_t second_underscore = key_std.find('_', underscorePos + 1);
|
||||
if (second_underscore != std::string::npos)
|
||||
{
|
||||
// 提取第二个部分,例如 "L"、"a"、"b"
|
||||
std::string param_type = key_std.substr(underscorePos + 1, second_underscore - underscorePos - 1);
|
||||
|
||||
// 过滤不需要的参数类型
|
||||
if ((param_type != "L") && (param_type != "a") && (param_type != "b"))
|
||||
continue;
|
||||
|
||||
// 避免重复添加颜色
|
||||
if (std::find(colors.begin(), colors.end(), colorName) == colors.end())
|
||||
{
|
||||
colors.push_back(colorName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
qDebug() << "配置已成功从" << filePath << "加载";
|
||||
// qDebug()<<colors;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Widget::initDefaultConfig()
|
||||
{
|
||||
// 定义默认颜色和参数
|
||||
colors = {"green", "blue", "orange", "black", "red", "purple", "yellow"};
|
||||
|
||||
params = {
|
||||
// Green
|
||||
{"green_L_min", 16}, {"green_L_max", 56},
|
||||
{"green_a_min", -33}, {"green_a_max", -11},
|
||||
{"green_b_min", -7}, {"green_b_max", 24},
|
||||
|
||||
// Blue
|
||||
{"blue_L_min", 20}, {"blue_L_max", 43},
|
||||
{"blue_a_min", -13}, {"blue_a_max", 22},
|
||||
{"blue_b_min", -48}, {"blue_b_max", -8},
|
||||
|
||||
// Orange
|
||||
{"orange_L_min", 63}, {"orange_L_max", 78},
|
||||
{"orange_a_min", 7}, {"orange_a_max", 14},
|
||||
{"orange_b_min", 23}, {"orange_b_max", 47},
|
||||
|
||||
// Black
|
||||
{"black_L_min", 0}, {"black_L_max", 8},
|
||||
{"black_a_min", -4}, {"black_a_max", 2},
|
||||
{"black_b_min", -3}, {"black_b_max", 4},
|
||||
|
||||
// Red
|
||||
{"red_L_min", 23}, {"red_L_max", 48},
|
||||
{"red_a_min", 12}, {"red_a_max", 55},
|
||||
{"red_b_min", -80}, {"red_b_max", 37},
|
||||
|
||||
// Purple
|
||||
{"purple_L_min", 38}, {"purple_L_max", 54},
|
||||
{"purple_a_min", 10}, {"purple_a_max", 20},
|
||||
{"purple_b_min", -45}, {"purple_b_max", 1},
|
||||
|
||||
// Yellow
|
||||
{"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", 165},
|
||||
{"saturation_denoising", 1}
|
||||
};
|
||||
}
|
||||
|
||||
void Widget::on_btn_setColor_clicked()
|
||||
{
|
||||
std::string current_color=ui->comboBox_colorlist->currentText().toLocal8Bit().constData();
|
||||
if (!(std::find(colors.begin(), colors.end(), current_color) != colors.end()))
|
||||
return;
|
||||
params[current_color+"_L_min"]=ui->spinBox_L_min->value();
|
||||
params[current_color+"_L_max"]=ui->spinBox_L_max->value();
|
||||
params[current_color+"_a_min"]=ui->spinBox_A_min->value();
|
||||
params[current_color+"_a_max"]=ui->spinBox_A_max->value();
|
||||
params[current_color+"_b_min"]=ui->spinBox_B_min->value();
|
||||
params[current_color+"_b_max"]=ui->spinBox_B_max->value();
|
||||
saveConfig(getConfigDirectory()+"/color_range_config.txt",params,colors);
|
||||
|
||||
}
|
||||
|
||||
void Widget::update_colorlist()
|
||||
{
|
||||
ui->comboBox_colorlist->clear();
|
||||
for(auto color :colors)
|
||||
{
|
||||
ui->comboBox_colorlist->addItem(QString::fromStdString(color));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Widget::on_comboBox_colorlist_currentIndexChanged(int index)
|
||||
{
|
||||
std::string current_color=ui->comboBox_colorlist->currentText().toLocal8Bit().constData();
|
||||
if (!(std::find(colors.begin(), colors.end(), current_color) != colors.end()))
|
||||
return;
|
||||
int l_min = params[current_color+"_L_min"];
|
||||
int l_max = params[current_color+"_L_max"];
|
||||
int a_min = params[current_color+"_a_min"];
|
||||
int a_max = params[current_color+"_a_max"];
|
||||
int b_min = params[current_color+"_b_min"];
|
||||
int b_max = params[current_color+"_b_max"];
|
||||
ui->spinBox_L_max->setValue(l_max);
|
||||
ui->spinBox_L_min->setValue(l_min);
|
||||
ui->spinBox_A_max->setValue(a_max);
|
||||
ui->spinBox_A_min->setValue(a_min);
|
||||
ui->spinBox_B_max->setValue(b_max);
|
||||
ui->spinBox_B_min->setValue(b_min);
|
||||
}
|
||||
|
||||
|
||||
void Widget::on_btn_add_color_clicked()
|
||||
{
|
||||
std::string current_color=ui->lineEdit_color->text().toLocal8Bit().constData();
|
||||
if(current_color== "")
|
||||
return;
|
||||
if (!(std::find(colors.begin(), colors.end(), current_color) != colors.end()))
|
||||
colors.push_back(current_color);
|
||||
else
|
||||
return;
|
||||
params[current_color+"_L_min"]=ui->spinBox_L_min->value();
|
||||
params[current_color+"_L_max"]=ui->spinBox_L_max->value();
|
||||
params[current_color+"_a_min"]=ui->spinBox_A_min->value();
|
||||
params[current_color+"_a_max"]=ui->spinBox_A_max->value();
|
||||
params[current_color+"_b_min"]=ui->spinBox_B_min->value();
|
||||
params[current_color+"_b_max"]=ui->spinBox_B_max->value();
|
||||
saveConfig(getConfigDirectory()+"/color_range_config.txt",params,colors);
|
||||
update_colorlist();
|
||||
ui->lineEdit_color->clear();
|
||||
}
|
||||
|
||||
|
||||
void Widget::on_btn_del_color_clicked()
|
||||
{
|
||||
|
||||
// 获取当前选中的颜色文本
|
||||
QString currentColorQStr = ui->comboBox_colorlist->currentText();
|
||||
if (currentColorQStr.isEmpty())
|
||||
{
|
||||
QMessageBox::warning(this, "删除颜色", "当前没有选中的颜色。");
|
||||
return;
|
||||
}
|
||||
|
||||
std::string currentColor = currentColorQStr.toStdString();
|
||||
std::string color_lower = currentColor;
|
||||
if (!color_lower.empty())
|
||||
{
|
||||
color_lower[0] = static_cast<char>(std::tolower(color_lower[0]));
|
||||
}
|
||||
|
||||
// 确认删除
|
||||
QMessageBox::StandardButton reply;
|
||||
reply = QMessageBox::question(this, "删除颜色",
|
||||
QString("确定要删除颜色 '%1' 吗?").arg(currentColorQStr),
|
||||
QMessageBox::Yes | QMessageBox::No);
|
||||
if (reply != QMessageBox::Yes)
|
||||
return;
|
||||
|
||||
// 查找颜色在 colors 向量中的位置
|
||||
auto it = std::find(colors.begin(), colors.end(), currentColor);
|
||||
if (it != colors.end())
|
||||
{
|
||||
// 计算索引
|
||||
size_t index = std::distance(colors.begin(), it);
|
||||
|
||||
// 从 colors 向量中删除
|
||||
colors.erase(it);
|
||||
|
||||
// 从 params 映射中删除相关参数
|
||||
params.erase(color_lower + "_L_min");
|
||||
params.erase(color_lower + "_L_max");
|
||||
params.erase(color_lower + "_a_min");
|
||||
params.erase(color_lower + "_a_max");
|
||||
params.erase(color_lower + "_b_min");
|
||||
params.erase(color_lower + "_b_max");
|
||||
|
||||
// 更新配置文件
|
||||
saveConfig(getConfigDirectory()+"/color_range_config.txt",params,colors);
|
||||
|
||||
// 更新 UI
|
||||
update_colorlist();
|
||||
|
||||
// 如果还有颜色,选择被删除颜色后的第一个颜色
|
||||
if (!colors.empty())
|
||||
{
|
||||
if (index >= colors.size())
|
||||
index = colors.size() - 1;
|
||||
ui->comboBox_colorlist->setCurrentIndex(static_cast<int>(index));
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果没有颜色,重置所有 spinBox
|
||||
ui->spinBox_L_min->setValue(0);
|
||||
ui->spinBox_L_max->setValue(0);
|
||||
ui->spinBox_A_min->setValue(0);
|
||||
ui->spinBox_A_max->setValue(0);
|
||||
ui->spinBox_B_min->setValue(0);
|
||||
ui->spinBox_B_max->setValue(0);
|
||||
}
|
||||
|
||||
QMessageBox::information(this, "删除颜色", QString("颜色 '%1' 已成功删除。").arg(currentColorQStr));
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox::warning(this, "删除颜色", "未找到选中的颜色。");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Widget::on_btn_reset_color_clicked()
|
||||
{
|
||||
// 新增全部还原槽
|
||||
|
||||
// 确认重置
|
||||
QMessageBox::StandardButton reply;
|
||||
reply = QMessageBox::question(this, "全部还原", "确定要将配置还原为默认设置吗?",
|
||||
QMessageBox::Yes | QMessageBox::No);
|
||||
if (reply != QMessageBox::Yes)
|
||||
return;
|
||||
|
||||
// 初始化默认配置
|
||||
initDefaultConfig();
|
||||
|
||||
saveConfig(getConfigDirectory()+"/color_range_config.txt",params,colors);
|
||||
// 更新 UI
|
||||
update_colorlist();
|
||||
|
||||
// 选择第一个颜色(如果有)
|
||||
if (!colors.empty())
|
||||
{
|
||||
ui->comboBox_colorlist->setCurrentIndex(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果没有颜色,重置所有 spinBox
|
||||
ui->spinBox_L_min->setValue(0);
|
||||
ui->spinBox_L_max->setValue(0);
|
||||
ui->spinBox_A_min->setValue(0);
|
||||
ui->spinBox_A_max->setValue(0);
|
||||
ui->spinBox_B_min->setValue(0);
|
||||
ui->spinBox_B_max->setValue(0);
|
||||
}
|
||||
|
||||
QMessageBox::information(this, "全部还原", "配置已成功还原为默认设置。");
|
||||
|
||||
}
|
||||
|
||||
|
||||
18
widget.h
18
widget.h
@ -54,6 +54,24 @@ private slots:
|
||||
|
||||
void on_btn_settings_clicked();
|
||||
|
||||
void on_btn_setColor_clicked();
|
||||
|
||||
void update_colorlist();
|
||||
|
||||
void on_comboBox_colorlist_currentIndexChanged(int index);
|
||||
|
||||
bool loadConfig(const QString &filePath);
|
||||
|
||||
bool saveConfig(const QString &filePath, const std::map<std::string, int>& params_to_set,const std::vector<std::string>& color_vector_to_set);
|
||||
|
||||
void initDefaultConfig();
|
||||
|
||||
void on_btn_add_color_clicked();
|
||||
|
||||
void on_btn_del_color_clicked();
|
||||
|
||||
void on_btn_reset_color_clicked();
|
||||
|
||||
private:
|
||||
Ui::Widget *ui;
|
||||
|
||||
|
||||
468
widget.ui
468
widget.ui
@ -35,7 +35,7 @@
|
||||
<string notr="true">background-color: rgb(228, 223, 186);</string>
|
||||
</property>
|
||||
<property name="currentIndex">
|
||||
<number>1</number>
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="tabBarAutoHide">
|
||||
<bool>true</bool>
|
||||
@ -673,8 +673,8 @@ border-color: rgb(0, 0, 0);</string>
|
||||
<widget class="QPushButton" name="btn_set_lower">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>30</x>
|
||||
<y>470</y>
|
||||
<x>210</x>
|
||||
<y>450</y>
|
||||
<width>231</width>
|
||||
<height>141</height>
|
||||
</rect>
|
||||
@ -784,42 +784,42 @@ border-color: rgb(0, 0, 0);</string>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="btn_tab3_backtab2">
|
||||
</widget>
|
||||
<widget class="QPushButton" name="btn_tab3_backtab2_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>480</x>
|
||||
<y>470</y>
|
||||
<x>100</x>
|
||||
<y>750</y>
|
||||
<width>231</width>
|
||||
<height>141</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 700 48pt "Microsoft YaHei UI";</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>返回</string>
|
||||
<string>home</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QLabel" name="label_title_4">
|
||||
<widget class="QWidget" name="layoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>920</x>
|
||||
<y>150</y>
|
||||
<width>91</width>
|
||||
<height>21</height>
|
||||
<x>1630</x>
|
||||
<y>40</y>
|
||||
<width>94</width>
|
||||
<height>147</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_17">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_title_4">
|
||||
<property name="text">
|
||||
<string>喷阀测试界面</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>1050</x>
|
||||
<y>240</y>
|
||||
<width>331</width>
|
||||
<height>91</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>手动喷阀测试</string>
|
||||
</property>
|
||||
@ -873,15 +873,9 @@ border-color: rgb(0, 0, 0);</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_3">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>1050</x>
|
||||
<y>420</y>
|
||||
<width>331</width>
|
||||
<height>91</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>自动喷阀测试</string>
|
||||
</property>
|
||||
@ -912,17 +906,425 @@ border-color: rgb(0, 0, 0);</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="btn_tab3_backtab2_2">
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="layoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>510</x>
|
||||
<y>770</y>
|
||||
<x>770</x>
|
||||
<y>40</y>
|
||||
<width>854</width>
|
||||
<height>769</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_19">
|
||||
<property name="spacing">
|
||||
<number>20</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_18">
|
||||
<property name="spacing">
|
||||
<number>30</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_39">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_31">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 700 48pt "Microsoft YaHei UI";</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>颜色</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="comboBox_colorlist">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>250</width>
|
||||
<height>80</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 20pt "Microsoft YaHei UI";</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_36">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_33">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 22pt "Microsoft YaHei UI";</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>L_max</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_L_max">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>80</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 20pt "Microsoft YaHei UI";</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>100</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_32">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 22pt "Microsoft YaHei UI";</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>L_min</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_L_min">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>80</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 20pt "Microsoft YaHei UI";</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>100</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_37">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_34">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 22pt "Microsoft YaHei UI";</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>A_max</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_A_max">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>80</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 20pt "Microsoft YaHei UI";</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>-128</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>128</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_35">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 22pt "Microsoft YaHei UI";</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>A_min</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_A_min">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>80</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 20pt "Microsoft YaHei UI";</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>-128</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>128</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_38">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_36">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 22pt "Microsoft YaHei UI";</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>B_max</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_B_max">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>80</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 20pt "Microsoft YaHei UI";</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>-128</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>128</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_37">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 22pt "Microsoft YaHei UI";</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>B_min</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="spinBox_B_min">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>80</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 20pt "Microsoft YaHei UI";</string>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<number>-128</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>128</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_40">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_38">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 20pt "Microsoft YaHei UI";</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>新建颜色</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_color">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 20pt "Microsoft YaHei UI";</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_42">
|
||||
<property name="spacing">
|
||||
<number>50</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btn_add_color">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>250</width>
|
||||
<height>80</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 700 40pt "Microsoft YaHei UI";</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>添加颜色</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btn_del_color">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>250</width>
|
||||
<height>120</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 700 40pt "Microsoft YaHei UI";</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>删除颜色</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btn_reset_color">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>250</width>
|
||||
<height>120</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 700 40pt "Microsoft YaHei UI";</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>一键恢复</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_41">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_25">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btn_setColor">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>250</width>
|
||||
<height>120</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 700 48pt "Microsoft YaHei UI";</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>设置颜色</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_26">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QPushButton" name="btn_tab3_backtab2">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>390</x>
|
||||
<y>750</y>
|
||||
<width>231</width>
|
||||
<height>141</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">font: 700 48pt "Microsoft YaHei UI";</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>home</string>
|
||||
<string>返回</string>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user