You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1120 lines
49 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#include "JsonConfig.h"
Json::Value CommonParamJson::toJsonValue()
{
return Json::Value();
}
void CommonParamJson::toObjectFromValue(Json::Value root)
{
_config.image = root["image"].asString();
_config.skuName = root["sku_name"].asString();
_config.value = root["value"].asString();
}
int CommonParamJson::GetConfig(CommonParamST &config)
{
config.copy(_config);
return 0;
}
Json::Value CommonParamToCheckConfigJson::toJsonValue()
{
return Json::Value();
}
// 读取和图片相关的参数
void CommonParamToCheckConfigJson::toObjectFromValue(Json::Value root)
{
auto strJson = root.asString();
Json::CharReaderBuilder builder;
std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
Json::Value rootvalue;
std::string err;
// std::cout << strJson << std::endl;
auto nSize = strJson.size();
if (reader->parse(strJson.c_str(), strJson.c_str() + nSize, &rootvalue, &err))
{
// 和节点无关参数提取
{
auto value = rootvalue["base"];
// std::cout << value << std::endl;
// getchar();
if (value.isObject())
{
_config.baseConfig.image_widht = value["image_widht"].asInt();
_config.baseConfig.Image_height = value["Image_height"].asInt();
_config.baseConfig.bDrawShieldRoi = value["bDrawShieldRoi"].asBool();
_config.baseConfig.bDrawPreRoi = value["Draw_PreROI"].asBool();
_config.baseConfig.bShield_ZF = value["bShield_ZF"].asBool();
_config.baseConfig.fUP_IOU = value["UP_IOU"].asFloat();
_config.baseConfig.strCamName = value["cameraCode"].asString();
_config.baseConfig.strCamearName = value["cameraCode"].asString();
_config.baseConfig.bCal_ImageScale = value["bImageScale_Cal"].asBool();
_config.baseConfig.Product_Size_Width_mm = value["Product_Size_W"].asFloat();
_config.baseConfig.Product_Size_Height_mm = value["Product_Size_H"].asFloat();
_config.baseConfig.fImage_Scale_x = value["Image_Scale_X"].asFloat();
_config.baseConfig.fImage_Scale_y = value["Image_Scale_Y"].asFloat();
if (value["Density_R"])
{
_config.baseConfig.density_R_mm = value["Density_R"].asFloat();
if (_config.baseConfig.density_R_mm <= 0 || _config.baseConfig.density_R_mm > 99999)
{
_config.baseConfig.density_R_mm = 5;
}
}
}
}
// 读取每个节点的参数
{
auto value_node = rootvalue["node"];
// 读取每个节点的参数
for (int i = 0; i < value_node.size(); i++)
{
printf("Node idx %d /%d \n", i, value_node.size());
CommonConfigNodeST tem_node;
// 和节点相关基础参数
{
auto value_node_base = value_node[i]["node_base"];
// std::cout << value_node_base << std::endl;
if (value_node_base.isObject())
{
tem_node.nodebasicConfog.calss_conf = value_node_base["class_conf"].asFloat();
tem_node.nodebasicConfog.calss_area = value_node_base["Class_AreaT"].asFloat();
// tem_node.nodebasicConfog.print("nodebasicConfog");
}
}
// 读取当前节点下 的每张图片 一般只读第一张图
{
auto value_node_imgs = value_node[i]["node_images"];
if (value_node_imgs.size() > 0)
{
int img_idx = 0;
tem_node.nodebasicConfog.img_width = value_node_imgs[img_idx]["width"].asInt();
tem_node.nodebasicConfog.img_height = value_node_imgs[img_idx]["height"].asInt();
auto value_node_imgs_region = value_node_imgs[img_idx]["params"];
// printf("tem_node.img_height %d, tem_node.img_width %d region num %d\n",
// tem_node.nodebasicConfog.img_height,
// tem_node.nodebasicConfog.img_width,
// value_node_imgs_region.size());
for (int region_idx = 0; region_idx < value_node_imgs_region.size(); region_idx++)
{
// printf("region idx %d /%d \n", region_idx, value_node_imgs_region.size());
RegionConfigST temRegion;
temRegion.buse = true;
// 1、读取基本参数
{
auto value_node_imgs_region_base = value_node_imgs_region[region_idx];
// std::cout<<value_node_imgs_region_base<<std::endl;
if (value_node_imgs_region_base.isObject())
{
temRegion.basicInfo.lay = value_node_imgs_region_base["tier"].asInt();
temRegion.basicInfo.type = value_node_imgs_region_base["areaType"].asInt();
temRegion.basicInfo.name = value_node_imgs_region_base["en_name"].asString();
temRegion.basicInfo.bdraw = value_node_imgs_region_base["bdraw"].asInt();
// printf("--- tier %d type %d\n ", temRegion.basicInfo.lay, temRegion.basicInfo.type);
}
}
// 读取通道
{
auto value_node_imgs_region_chanel = value_node_imgs_region[region_idx]["Channel_Param"]["channel"];
if (value_node_imgs_region_chanel.isArray())
{
for (int idx = 0; idx < value_node_imgs_region_chanel.size(); idx++)
{
std::string str = value_node_imgs_region_chanel[idx].asString();
temRegion.basicInfo.ChannelArry.emplace_back(str);
}
}
}
// 2、读取区域点
{
auto value_node_imgs_region_coord = value_node_imgs_region[region_idx]["coord"];
if (value_node_imgs_region_coord.isArray())
{
for (int idx = 0; idx < value_node_imgs_region_coord.size(); idx++)
{
cv::Point p;
p.x = value_node_imgs_region_coord[idx][0].asInt();
p.y = value_node_imgs_region_coord[idx][1].asInt();
if (p.x < 0)
{
p.x = 0;
}
if (p.x > tem_node.nodebasicConfog.img_width)
{
p.x = tem_node.nodebasicConfog.img_width;
}
if (p.y < 0)
{
p.y = 0;
}
if (p.y > tem_node.nodebasicConfog.img_height)
{
p.y = tem_node.nodebasicConfog.img_height;
}
temRegion.basicInfo.pointArry.emplace_back(p);
}
}
}
// 3、读取检测参数 和存图参数
for (int ParamType_idx = 0; ParamType_idx < ANALYSIS_TYPE_COUNT; ParamType_idx++)
{
if (temRegion.basicInfo.type == 1)
{
continue;
}
// int param_type = ParamType_idx;
auto value_node_imgs_region_Check_Param = value_node_imgs_region[region_idx][ANALYSIS_TYPE_Names[ParamType_idx]];
if (value_node_imgs_region_Check_Param.isObject())
{
for (Json::ValueIterator iter = value_node_imgs_region_Check_Param.begin(); iter != value_node_imgs_region_Check_Param.end(); iter++)
{
CheckConfig_Regions_Param tem_paramValue;
// const char *name = iter.memberName();
std::string name = iter.name(); // 新方法,推荐使用
tem_paramValue.param_name = name;
auto value_node_imgs_region_Check_Param_value = value_node_imgs_region_Check_Param[name];
if (value_node_imgs_region_Check_Param_value.isArray())
{
for (int idx = 0; idx < value_node_imgs_region_Check_Param_value.size(); idx++)
{
AandEParam temparam;
temparam.bEnable = value_node_imgs_region_Check_Param_value[idx]["state"].asBool();
temparam.bOk = value_node_imgs_region_Check_Param_value[idx]["bOK"].asBool();
if (value_node_imgs_region_Check_Param_value[idx]["area"])
{
temparam.area = value_node_imgs_region_Check_Param_value[idx]["area"].asFloat();
}
if (value_node_imgs_region_Check_Param_value[idx]["area_max"])
{
temparam.area_max = value_node_imgs_region_Check_Param_value[idx]["area_max"].asFloat();
}
if (value_node_imgs_region_Check_Param_value[idx]["energy"])
{
temparam.energy = value_node_imgs_region_Check_Param_value[idx]["energy"].asFloat();
}
if (value_node_imgs_region_Check_Param_value[idx]["hj"])
{
temparam.hj = value_node_imgs_region_Check_Param_value[idx]["hj"].asFloat();
}
if (value_node_imgs_region_Check_Param_value[idx]["length"])
{
temparam.length = value_node_imgs_region_Check_Param_value[idx]["length"].asFloat();
}
if (value_node_imgs_region_Check_Param_value[idx]["breadth"])
{
temparam.breadth = value_node_imgs_region_Check_Param_value[idx]["breadth"].asFloat();
}
if (value_node_imgs_region_Check_Param_value[idx]["num"])
{
temparam.num = value_node_imgs_region_Check_Param_value[idx]["num"].asInt();
}
if (value_node_imgs_region_Check_Param_value[idx]["dis"])
{
temparam.dis = value_node_imgs_region_Check_Param_value[idx]["dis"].asFloat();
}
if (value_node_imgs_region_Check_Param_value[idx]["density"])
{
temparam.density = value_node_imgs_region_Check_Param_value[idx]["density"].asFloat();
}
std::string str = ANALYSIS_TYPE_Names[ParamType_idx] + " " + name + " " + std::to_string(idx);
// temparam.print(str);
tem_paramValue.addParam(temparam);
}
}
temRegion.checkConfig_Regions_type[ParamType_idx].checkConfig_Regions_Param.push_back(tem_paramValue);
}
}
}
tem_node.regionConfigArr.push_back(temRegion);
}
}
}
_config.nodeConfigArr.push_back(tem_node);
}
}
}
else
{
printf("--- ******error json*** \n");
}
}
int CommonParamToCheckConfigJson::GetConfig(CommonCheckConfigST &config)
{
config.copy(_config);
return 0;
}
Json::Value CheckConfigJson::toJsonValue()
{
return Json::Value();
}
void CheckConfigJson::toObjectFromValue(Json::Value root)
{
{
auto value = root["AI_Model_Path"];
if (value.isObject())
{
}
}
{
auto value = root["image_preprocess_param"];
if (value.isObject())
{
auto arr = value["crop_roi"];
if (arr.isArray())
{
_config.preDealImgConfig.cutRoi.x = arr[0].asInt();
_config.preDealImgConfig.cutRoi.y = arr[1].asInt();
_config.preDealImgConfig.cutRoi.width = arr[2].asInt();
_config.preDealImgConfig.cutRoi.height = arr[3].asInt();
}
_config.preDealImgConfig.bresize = value["resize"].asBool();
_config.preDealImgConfig.bInAI_ImgFflip = value["ai_input_image_flip"].asBool();
_config.preDealImgConfig.bOutAI_ImgFflip = value["ai_output_image_flip"].asBool();
}
}
{
auto value = root["Camer_param"];
if (value.isObject())
{
_config.camConfig.fscale_x = value["scale_x"].asFloat();
_config.camConfig.fscale_y = value["scale_y"].asFloat();
std::cout << "_config.camConfig.fscale_x=" << _config.camConfig.fscale_x << std::endl;
std::cout << "_config.camConfig.fscale_y=" << _config.camConfig.fscale_y << std::endl;
}
}
{
auto value = root["image_Info"];
if (value.isObject())
{
_config.resultimg_out.width = value["result_image_width"].asInt();
_config.resultimg_out.height = value["result_image_height"].asInt();
_config.resultimg_out.channels = value["result_image_channels"].asInt();
_config.resultimg_out.print("resultimg_out");
_config.Srcimg_in.width = value["src_image_width"].asInt();
_config.Srcimg_in.height = value["src_image_height"].asInt();
_config.Srcimg_in.channels = value["src_image_channels"].asInt();
_config.Srcimg_in.print("Srcimg_in");
}
}
}
int CheckConfigJson::GetConfig(CheckConfigST &config)
{
config.copy(_config);
return 0;
}
Json::Value ChannelFuntonConfigJson::toJsonValue()
{
return Json::Value();
}
void ChannelFuntonConfigJson::toObjectFromValue(Json::Value root)
{
auto strJson = root.asString();
Json::CharReaderBuilder builder;
std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
Json::Value rootvalue;
std::string err;
// std::cout << "ChannelFuntonConfigJson" << std::endl
// << std::endl
// << std::endl;
// std::cout << strJson << std::endl;
auto nSize = strJson.size();
if (reader->parse(strJson.c_str(), strJson.c_str() + nSize, &rootvalue, &err))
{
// 和节点无关参数提取
auto value = rootvalue["checkData"];
if (value.isArray())
{
for (int idx = 0; idx < value.size(); idx++)
{
ChannelCheckFunction channel;
if (value[idx]["panelCode"])
{
channel.strChannelName = value[idx]["panelCode"].asString();
}
else
{
continue;
}
GetFunction(value[idx]["checkItem"], channel.function);
// up 特殊处理
if (channel.strChannelName == "Up-Particle" && channel.function.f_BaseDet.bOpen)
{
channel.function.f_OnlyBLob.bOpen = true;
}
// channel.print("channel");
// getchar();
_config.channelFunctionArr.push_back(channel);
}
// _config.print("channelFunction");
}
}
}
int ChannelFuntonConfigJson::GetConfig(ALLChannelCheckFunction &config)
{
config.copy(_config);
return 0;
}
int ChannelFuntonConfigJson::GetFunction(Json::Value value, CheckFunction &function)
{
// std::cout << value << std::endl;
if (value.isArray())
{
for (int i = 0; i < value.size(); i++)
{
std::string strCode = value[i]["itemCode"].asString();
// std::cout << strCode << std::endl;
// 注:支架/把手/标签检测(Support_Detect/Handle_Detect/BQ_Detect)已移至Base层(baseCheckData)解析
// 大缺陷检测
if ("BigQX_Detect" == strCode)
{
auto value_f = value[i];
// std::cout << value_f << std::endl;
function.f_Big_QX.bOpen = value_f["isOpen"].asBool();
if (value_f["form"]["SingleConfig"]["Area"])
{
function.f_Big_QX.Single_Area = value_f["form"]["SingleConfig"]["Area"].asFloat();
}
if (value_f["form"]["SingleConfig"]["HJ"])
{
function.f_Big_QX.Single_HJ = value_f["form"]["SingleConfig"]["HJ"].asInt();
}
if (value_f["form"]["SingleConfig"]["Length"])
{
function.f_Big_QX.Single_Len = value_f["form"]["SingleConfig"]["Length"].asFloat();
}
if (value_f["form"]["Sum_Area"]["Blob_Num"])
{
function.f_Big_QX.Sum_blob_Num = value_f["form"]["Sum_Area"]["Blob_Num"].asInt();
}
if (value_f["form"]["Sum_Area"]["Area_Sum"])
{
function.f_Big_QX.Sum_Area = value_f["form"]["Sum_Area"]["Area_Sum"].asFloat();
}
}
// 屏蔽区域
if ("ShieldRegion" == strCode)
{
auto value_f = value[i];
// std::cout << value_f << std::endl;
function.f_ShieldRegion.bOpen = value_f["isOpen"].asBool();
if (function.f_ShieldRegion.bOpen)
{
/* code */
if (value_f["form"]["ShieldRegionConfig"]["bDraw"])
{
function.f_ShieldRegion.bDraw = value_f["form"]["ShieldRegionConfig"]["bDraw"].asBool();
}
{
auto region_coord = value_f["form"]["ShieldRegionConfig"]["region_1"];
if (region_coord.isArray())
{
for (int idx = 0; idx < region_coord.size(); idx++)
{
cv::Point p;
p.x = region_coord[idx][0].asInt();
p.y = region_coord[idx][1].asInt();
function.f_ShieldRegion.pointArry1.emplace_back(p);
}
}
// printf(" pointArry1 size %d \n", function.f_ShieldRegion.pointArry1.size());
}
{
auto region_coord = value_f["form"]["ShieldRegionConfig"]["region_2"];
if (region_coord.isArray())
{
for (int idx = 0; idx < region_coord.size(); idx++)
{
cv::Point p;
p.x = region_coord[idx][0].asInt();
p.y = region_coord[idx][1].asInt();
function.f_ShieldRegion.pointArry2.emplace_back(p);
}
}
// printf(" pointArry2 size %d \n", function.f_ShieldRegion.pointArry2.size());
}
{
auto region_coord = value_f["form"]["ShieldRegionConfig"]["region_3"];
if (region_coord.isArray())
{
for (int idx = 0; idx < region_coord.size(); idx++)
{
cv::Point p;
p.x = region_coord[idx][0].asInt();
p.y = region_coord[idx][1].asInt();
function.f_ShieldRegion.pointArry3.emplace_back(p);
}
}
// printf(" pointArry3 size %d \n", function.f_ShieldRegion.pointArry3.size());
}
{
auto region_coord = value_f["form"]["ShieldRegionConfig"]["region_4"];
if (region_coord.isArray())
{
for (int idx = 0; idx < region_coord.size(); idx++)
{
cv::Point p;
p.x = region_coord[idx][0].asInt();
p.y = region_coord[idx][1].asInt();
function.f_ShieldRegion.pointArry4.emplace_back(p);
}
}
// printf(" pointArry4 size %d \n", function.f_ShieldRegion.pointArry4.size());
}
{
auto region_coord = value_f["form"]["ShieldRegionConfig"]["region_5"];
if (region_coord.isArray())
{
for (int idx = 0; idx < region_coord.size(); idx++)
{
cv::Point p;
p.x = region_coord[idx][0].asInt();
p.y = region_coord[idx][1].asInt();
function.f_ShieldRegion.pointArry5.emplace_back(p);
}
}
// printf(" pointArry5 size %d \n", function.f_ShieldRegion.pointArry5.size());
}
}
else
{
function.f_ShieldRegion.Init();
}
}
// 边缘roi
if ("Crop_ROI" == strCode)
{
auto value_f = value[i];
// std::cout << value_f << std::endl;
function.f_EdgeROI.bOpen = value_f["isOpen"].asBool();
if (function.f_EdgeROI.bOpen)
{
/* code */
if (value_f["form"]["ROI_Config"]["Use_DrawROI"])
{
function.f_EdgeROI.Use_DrawROI = value_f["form"]["ROI_Config"]["Use_DrawROI"].asBool();
}
if (value_f["form"]["ROI_Config"]["Use_DetEdge"])
{
function.f_EdgeROI.Use_DetEdge = value_f["form"]["ROI_Config"]["Use_DetEdge"].asBool();
}
if (value_f["form"]["ROI_Config"]["Use_AIEdge"])
{
function.f_EdgeROI.Use_AIEdge = value_f["form"]["ROI_Config"]["Use_AIEdge"].asBool();
}
if (value_f["form"]["ROI_Config"]["AI_Fail_UseDraw"])
{
function.f_EdgeROI.AI_Fail_UseDraw = value_f["form"]["ROI_Config"]["AI_Fail_UseDraw"].asBool();
}
if (value_f["form"]["ROI_Config"]["threshold_value"])
{
function.f_EdgeROI.threshold_value = value_f["form"]["ROI_Config"]["threshold_value"].asInt();
}
if (value_f["form"]["ROI_Config"]["threshold_value"])
{
function.f_EdgeROI.AI_Erode_Size = value_f["form"]["ROI_Config"]["AI_Erode_Size"].asInt();
}
{
auto region_coord = value_f["form"]["ROI_Config"]["ROI"];
if (region_coord.isArray())
{
for (int idx = 0; idx < region_coord.size(); idx++)
{
cv::Point p;
p.x = region_coord[idx][0].asInt();
p.y = region_coord[idx][1].asInt();
function.f_EdgeROI.pointArry1.emplace_back(p);
}
}
// printf(" pointArry1 size %d \n", function.f_ShieldRegion.pointArry1.size());
}
}
else
{
function.f_EdgeROI.Init();
}
}
// 边缘roi
if ("Image_Align_T" == strCode)
{
auto value_f = value[i];
// std::cout << value_f << std::endl;
function.f_Image_Align.bOpen = value_f["isOpen"].asBool();
if (function.f_Image_Align.bOpen)
{
/* code */
{
auto region_coord = value_f["form"]["Align_Config"]["Edge_TZ"];
if (region_coord.isArray())
{
for (int idx = 0; idx < region_coord.size(); idx++)
{
cv::Point p;
p.x = region_coord[idx][0].asInt();
p.y = region_coord[idx][1].asInt();
function.f_Image_Align.pointArry1.emplace_back(p);
}
}
// printf(" pointArry1 size %d \n", function.f_ShieldRegion.pointArry1.size());
}
{
auto region_roi = value_f["form"]["Align_Config"]["Search_ROI"];
{
if (region_roi["x"])
{
function.f_Image_Align.search_Roi.x = region_roi["x"].asInt();
}
if (region_roi["y"])
{
function.f_Image_Align.search_Roi.y = region_roi["y"].asInt();
}
if (region_roi["width"])
{
function.f_Image_Align.search_Roi.width = region_roi["width"].asInt();
}
if (region_roi["height"])
{
function.f_Image_Align.search_Roi.height = region_roi["height"].asInt();
}
}
// printf(" pointArry1 size %d \n", function.f_ShieldRegion.pointArry1.size());
}
{
auto Kernel_roi = value_f["form"]["Align_Config"]["Kernel_ROI"];
{
if (Kernel_roi["x"])
{
function.f_Image_Align.feature_Roi.x = Kernel_roi["x"].asInt();
}
if (Kernel_roi["y"])
{
function.f_Image_Align.feature_Roi.y = Kernel_roi["y"].asInt();
}
if (Kernel_roi["width"])
{
function.f_Image_Align.feature_Roi.width = Kernel_roi["width"].asInt();
}
if (Kernel_roi["height"])
{
function.f_Image_Align.feature_Roi.height = Kernel_roi["height"].asInt();
}
}
// printf(" pointArry1 size %d \n", function.f_ShieldRegion.pointArry1.size());
}
{
auto crop_roi = value_f["form"]["Align_Config"]["Crop_ROI"];
{
if (crop_roi["x"])
{
function.f_Image_Align.Crop_Roi.x = crop_roi["x"].asInt();
}
if (crop_roi["y"])
{
function.f_Image_Align.Crop_Roi.y = crop_roi["y"].asInt();
}
if (crop_roi["width"])
{
function.f_Image_Align.Crop_Roi.width = crop_roi["width"].asInt();
}
if (crop_roi["height"])
{
function.f_Image_Align.Crop_Roi.height = crop_roi["height"].asInt();
}
}
// printf(" pointArry1 size %d \n", function.f_ShieldRegion.pointArry1.size());
}
{
if (value_f["form"]["Align_Config"]["bDraw"])
{
function.f_Image_Align.bDraw = value_f["form"]["Align_Config"]["bDraw"].asBool();
}
}
{
if (value_f["form"]["Align_Config"]["Score"])
{
float fs = value_f["form"]["Align_Config"]["Score"].asFloat();
if (fs > 0.01 && fs <= 1)
{
function.f_Image_Align.fscore = fs;
}
}
}
if (value_f["form"]["Align_Config"]["UseType"])
{
std::string str = value_f["form"]["Align_Config"]["UseType"].asString();
if (str == "Use")
{
function.f_Image_Align.runType = Function_Image_Align::type_Use;
}
else if (str == "Test")
{
function.f_Image_Align.runType = Function_Image_Align::type_Test;
}
else
{
function.f_Image_Align.runType = Function_Image_Align::type_Use;
}
}
}
else
{
function.f_Image_Align.Init();
}
}
}
}
return 0;
}
Json::Value BaseFuntonConfigJson::toJsonValue()
{
return Json::Value();
}
void BaseFuntonConfigJson::toObjectFromValue(Json::Value root)
{
auto strJson = root.asString();
Json::CharReaderBuilder builder;
std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
Json::Value rootvalue;
std::string err;
// std::cout << "BaseFuntonConfigJson" << std::endl
// << std::endl
// << std::endl;
// std::cout << strJson << std::endl;
auto nSize = strJson.size();
if (reader->parse(strJson.c_str(), strJson.c_str() + nSize, &rootvalue, &err))
{
// 和节点无关参数提取
auto value = rootvalue["baseCheckData"];
// printf("\n\n\n");
// std::cout << value << std::endl;
// getchar();
if (value.isArray())
{
for (int idx = 0; idx < value.size(); idx++)
{
GetFunction(value[idx]);
}
// _config.print("channelFunction");
}
}
}
int BaseFuntonConfigJson::GetConfig(BaseCheckFunction &config)
{
config.copy(_config);
return 0;
}
int BaseFuntonConfigJson::GetFunction(Json::Value value)
{
// std::cout << value << std::endl;
std::string strCode = value["itemCode"].asString();
// std::cout << strCode << std::endl;
// 读取UP 过滤功能
if ("AlignDet" == strCode)
{
auto value_f = value;
// std::cout << value_f << std::endl;
// getchar();
_config.markLine.bOpen = value_f["isOpen"].asBool();
if (_config.markLine.bOpen)
{
{
auto crop_roi = value_f["form"]["ALign_Config"]["Product_ROI"];
// 2、读取区域点
{
auto value_region = value_f["form"]["ALign_Config"]["Product_ROI"];
if (value_region.isArray())
{
for (int idx = 0; idx < value_region.size(); idx++)
{
cv::Point p;
p.x = value_region[idx][0].asInt();
p.y = value_region[idx][1].asInt();
_config.markLine.region.emplace_back(p);
}
if (_config.markLine.region.size() > 0)
{
_config.markLine.productROI = boundingRect(_config.markLine.region);
}
}
}
// printf(" pointArry1 size %d \n", function.f_ShieldRegion.pointArry1.size());
}
if (value_f["form"]["ALign_Config"]["bDraw"])
{
_config.markLine.bDraw = value_f["form"]["ALign_Config"]["bDraw"].asBool();
}
if (value_f["form"]["ALign_Config"]["badapt_region"])
{
_config.markLine.badapt_region = value_f["form"]["ALign_Config"]["badapt_region"].asBool();
}
{
auto value_circl = value_f["form"]["ALign_Config"]["mark_1_Local"]["path"];
if (value_circl.isArray())
{
if (value_circl[0][0])
{
_config.markLine.mark_local_1.x = value_circl[0][0].asInt();
}
if (value_circl[0][1])
{
_config.markLine.mark_local_1.y = value_circl[0][1].asInt();
}
}
}
{
auto value_circl = value_f["form"]["ALign_Config"]["mark_2_Local"]["path"];
if (value_circl.isArray())
{
if (value_circl[0][0])
{
_config.markLine.mark_local_2.x = value_circl[0][0].asInt();
}
if (value_circl[0][1])
{
_config.markLine.mark_local_2.y = value_circl[0][1].asInt();
}
}
}
// _config.markLine.print("dfe");
// getchar();
}
else
{
_config.markLine.Init();
}
}
// 存图项(2026-10 平台将 Det_Image_Save 改名为 BM_Image_Save,两个名称都兼容)
if ("Det_Image_Save" == strCode || "BM_Image_Save" == strCode)
{
auto value_f = value;
// std::cout << value_f << std::endl;
// getchar();
_config.saveImg.bOpen = value_f["isOpen"].asBool();
if (_config.saveImg.bOpen)
{
if (value_f["form"]["SaveImg_Config"]["Cls_Save"])
{
_config.saveImg.bSaveClsImg = value_f["form"]["SaveImg_Config"]["Cls_Save"].asBool();
}
if (value_f["form"]["SaveImg_Config"]["Align_Big_Save"])
{
_config.saveImg.bSaveAlginImg = value_f["form"]["SaveImg_Config"]["Align_Big_Save"].asBool();
}
if (value_f["form"]["SaveImg_Config"]["AI_Det_Save"])
{
_config.saveImg.bSaveAIDetImg = value_f["form"]["SaveImg_Config"]["AI_Det_Save"].asBool();
}
if (value_f["form"]["SaveImg_Config"]["BQ_Det_Save"])
{
_config.saveImg.bSaveBQDetImg = value_f["form"]["SaveImg_Config"]["BQ_Det_Save"].asBool();
}
}
else
{
_config.saveImg.Init();
}
// _config.edgeDet.print("edgeDet");
// getchar();
}
if ("Big_NG" == strCode)
{
auto value_f = value;
// std::cout << value_f << std::endl;
// getchar();
_config.bigNG.bOpen = value_f["isOpen"].asBool();
if (_config.bigNG.bOpen)
{
// 大缺陷参数按缺陷列表循环解析(表单键名与CONFIG_QX_NAME_Names一致)
for (int i = 0; i < CONFIG_QX_NAME_count; i++)
{
std::string strqx_name = CONFIG_QX_NAME_Names[i];
if (value_f["form"][strqx_name]["open"])
{
_config.bigNG.qx[i].bOpen = value_f["form"][strqx_name]["open"].asBool();
}
if (value_f["form"][strqx_name]["Area"])
{
_config.bigNG.qx[i].fArea = value_f["form"][strqx_name]["Area"].asFloat();
}
_config.bigNG.qx[i].strname = strqx_name;
}
}
else
{
_config.bigNG.Init();
}
// _config.edgeDet.print("edgeDet");
// getchar();
}
// 支架偏位检测(Support_Detect,2026-10 从通道层 Support_QX_Detect 移至Base层并拆分独立)
if ("Support_Detect" == strCode)
{
auto value_f = value;
// 检测项开关即支架偏位检测开关
_config.supportDet.bDetSupport = value_f["isOpen"].asBool();
if (_config.supportDet.bDetSupport)
{
auto value_param = value_f["form"]["support_param"];
// 支架绘制开关:控制结果图上是否绘制支架中心十字/距离线(默认关,兼容旧参数)
if (value_param["bDrawSupport"].isBool())
{
_config.supportDet.bDrawSupport = value_param["bDrawSupport"].asBool();
}
// 传统算法搜边开关
if (value_param["bUseTraditionEdge"].isBool())
{
_config.supportDet.bUseTraditionEdge = value_param["bUseTraditionEdge"].asBool();
}
if (value_param["x_standard"])
{
_config.supportDet.x_standard = value_param["x_standard"].asFloat();
}
if (value_param["y_standard"])
{
_config.supportDet.y_standard = value_param["y_standard"].asFloat();
}
if (value_param["x_offset"])
{
_config.supportDet.x_offset = value_param["x_offset"].asFloat();
}
if (value_param["y_offset"])
{
_config.supportDet.y_offset = value_param["y_offset"].asFloat();
}
if (value_param["r_offset"])
{
_config.supportDet.r_offset = value_param["r_offset"].asFloat();
}
if (value_param["support_min_area"])
{
_config.supportDet.support_min_area = value_param["support_min_area"].asFloat();
}
// 支架边缘原图精细化(可选):沿边缘采样,从边缘向内找第一个 255 像素作为新边缘点,
// edge_refine_search:最多向内搜索像素数(未配置默认 80)
// edge_refine_step :沿边采样步长(像素)(未配置默认 40,不需要每个点都找)
if (value_param["edge_refine_search"])
{
_config.supportDet.edge_refine_search = value_param["edge_refine_search"].asFloat();
}
if (value_param["edge_refine_step"])
{
_config.supportDet.edge_refine_step = value_param["edge_refine_step"].asFloat();
}
// 支架方向精细化(可选):模型 smallmask 精度低(1696×800 上采样回原图),
// minAreaRect 求支架方向角误差大,改为在 detImg 灰度原图上拟合支架长边求方向角。
// support_refine_search :取模型支架外接矩形最外侧多少列作为边缘搜索带(未配置默认 30)
// support_refine_step :沿支架长边采样步长(像素)(未配置默认 20)
// support_refine_segments:采样点分段数(每段稳健拟合一条线取角度中位数,未配置默认 6)
if (value_param["support_refine_search"])
{
_config.supportDet.support_refine_search = value_param["support_refine_search"].asFloat();
}
if (value_param["support_refine_step"])
{
_config.supportDet.support_refine_step = value_param["support_refine_step"].asFloat();
}
if (value_param["support_refine_segments"])
{
_config.supportDet.support_refine_segments = value_param["support_refine_segments"].asFloat();
}
auto value_qx = value_param["edge_select"];
if (value_qx.isArray())
{
for (int idx = 0; idx < value_qx.size(); idx++)
{
std::string strEdge = value_qx[idx].asString();
_config.supportDet.edge_select.push_back(strEdge);
}
}
}
}
// 把手检测(Handle_Detect,2026-10 从通道层 Support_QX_Detect 移至Base层并拆分独立)
if ("Handle_Detect" == strCode)
{
auto value_f = value;
// 检测项开关即把手缺失检测开关
_config.supportDet.bDetHandle = value_f["isOpen"].asBool();
if (_config.supportDet.bDetHandle)
{
auto handle_p = value_f["form"]["handle_param"];
// 把手差异阈值
if (handle_p["handle_diff"])
{
_config.supportDet.handle_diff = handle_p["handle_diff"].asFloat();
}
// 把手提取/匹配范围参数(均可选:未配置时用 ImgCheckAnalysisy.cpp 顶部宏的默认值)
// handle_size_min/max :凸起宽高与把手区域外接矩形宽高的比值允许区间(默认 0.8 ~ 1.2)
// handle_search_ratio :把手区域附近搜索范围外扩倍数(默认 5)
// handle_min_depth :凸起最小深度系数(× 定位模型量化步长)(默认 2)
// handle_min_area :凸起最小面积系数(× 最小深度²)(默认 2)
// handle_edge_margin :主体边缘线外扩系数(× 量化步长),0=按“最小深度一半”自动(默认 3)
// 含义/调整影响详见 ImgCheckAnalysisy.cpp 顶部参数注释
if (handle_p["handle_size_min"])
{
_config.supportDet.handle_size_min_ratio = handle_p["handle_size_min"].asFloat();
}
if (handle_p["handle_size_max"])
{
_config.supportDet.handle_size_max_ratio = handle_p["handle_size_max"].asFloat();
}
if (handle_p["handle_search_ratio"])
{
_config.supportDet.handle_search_ratio = handle_p["handle_search_ratio"].asFloat();
}
if (handle_p["handle_min_depth"])
{
_config.supportDet.handle_min_depth_coef = handle_p["handle_min_depth"].asFloat();
}
if (handle_p["handle_min_area"])
{
_config.supportDet.handle_min_area_coef = handle_p["handle_min_area"].asFloat();
}
if (handle_p["handle_edge_margin"])
{
_config.supportDet.handle_edge_margin_coef = handle_p["handle_edge_margin"].asFloat();
}
bool bNewFormat = handle_p["handle_region1"].isArray();
for (int idx = 0; idx < HANDLE_REGION_MAX_NUM; idx++)
{
std::string strKey = bNewFormat ? ("handle_region" + std::to_string(idx + 1))
: ((idx == 0) ? std::string("handle_region") : std::string(""));
if (strKey.empty())
{
break;
}
// 该把手区域被禁用时跳过
if (handle_p[strKey + "_disabled"].isBool() && handle_p[strKey + "_disabled"].asBool())
{
continue;
}
auto value_region = handle_p[strKey];
if (!value_region.isArray() || value_region.size() < 3)
{
continue; // 空区域:表示该处不需要检测把手
}
std::vector<cv::Point> region;
for (int ip = 0; ip < value_region.size(); ip++)
{
if (!value_region[ip].isArray() || value_region[ip].size() < 2)
{
continue;
}
cv::Point p;
p.x = value_region[ip][0].asInt();
p.y = value_region[ip][1].asInt();
region.emplace_back(p);
}
if (region.size() < 3)
{
continue;
}
_config.supportDet.handleRegions.push_back(region);
_config.supportDet.handleBoxes.push_back(cv::boundingRect(region));
}
}
}
// 标签检测(BQ_Detect,2026-10 从通道层 Support_QX_Detect 移至Base层并拆分独立)
if ("BQ_Detect" == strCode)
{
auto value_f = value;
// 检测项开关即标签检测开关
_config.supportDet.bDetTag = value_f["isOpen"].asBool();
if (_config.supportDet.bDetTag)
{
auto tag_p = value_f["form"]["tag_param"];
if (tag_p["BQ_area"])
{
_config.supportDet.BQ_area = tag_p["BQ_area"].asFloat();
}
if (tag_p["BQ_energy"])
{
_config.supportDet.BQ_energy = tag_p["BQ_energy"].asFloat();
}
if (tag_p["BQ_len"])
{
_config.supportDet.BQ_len = tag_p["BQ_len"].asFloat();
}
if (tag_p["BQ_hj"])
{
_config.supportDet.BQ_hj = tag_p["BQ_hj"].asFloat();
}
}
}
return 0;
}