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.
1083 lines
47 KiB
1083 lines
47 KiB
#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;
|
|
// 大缺陷检测
|
|
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();
|
|
}
|
|
}
|
|
if ("Support_QX_Detect" == strCode)
|
|
{
|
|
auto value_f = value;
|
|
// std::cout << value_f << std::endl;
|
|
// getchar();
|
|
_config.supportDet.bOpen = value_f["isOpen"].asBool();
|
|
if (_config.supportDet.bOpen)
|
|
{
|
|
// 支架参数
|
|
{
|
|
auto value_region = value_f["form"]["support_param"]["support_region"];
|
|
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.supportDet.supportRegion.emplace_back(p);
|
|
}
|
|
if (_config.supportDet.supportRegion.size() > 0)
|
|
{
|
|
_config.supportDet.supportRect = minAreaRect(_config.supportDet.supportRegion);
|
|
}
|
|
}
|
|
}
|
|
if (value_f["form"]["support_param"]["x_offset"])
|
|
{
|
|
_config.supportDet.x_offset = value_f["form"]["support_param"]["x_offset"].asFloat();
|
|
}
|
|
if (value_f["form"]["support_param"]["y_offset"])
|
|
{
|
|
_config.supportDet.y_offset = value_f["form"]["support_param"]["y_offset"].asFloat();
|
|
}
|
|
if (value_f["form"]["support_param"]["r_offset"])
|
|
{
|
|
_config.supportDet.r_offset = value_f["form"]["support_param"]["r_offset"].asFloat();
|
|
}
|
|
|
|
// 把手参数
|
|
{
|
|
auto value_region = value_f["form"]["handle_param"]["handle_region"];
|
|
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.supportDet.handleRegion.emplace_back(p);
|
|
}
|
|
if (_config.supportDet.handleRegion.size() > 0)
|
|
{
|
|
_config.supportDet.handleRect = minAreaRect(_config.supportDet.handleRegion);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_config.supportDet.Init();
|
|
}
|
|
}
|
|
if ("Det_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"]["Mark_Save"])
|
|
{
|
|
_config.saveImg.bSaveMarkImg = value_f["form"]["SaveImg_Config"]["Mark_Save"].asBool();
|
|
}
|
|
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();
|
|
}
|
|
}
|
|
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)
|
|
{
|
|
if (value_f["form"]["aotudian"]["open"])
|
|
{
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_aotudian].bOpen = value_f["form"]["aotudian"]["open"].asBool();
|
|
}
|
|
if (value_f["form"]["aotudian"]["Area"])
|
|
{
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_aotudian].fArea = value_f["form"]["aotudian"]["Area"].asFloat();
|
|
}
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_aotudian].strname = "aotudian";
|
|
|
|
if (value_f["form"]["other"]["open"])
|
|
{
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_other].bOpen = value_f["form"]["other"]["open"].asBool();
|
|
}
|
|
if (value_f["form"]["other"]["Area"])
|
|
{
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_other].fArea = value_f["form"]["other"]["Area"].asFloat();
|
|
}
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_other].strname = "other";
|
|
|
|
if (value_f["form"]["line"]["open"])
|
|
{
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_line].bOpen = value_f["form"]["line"]["open"].asBool();
|
|
}
|
|
if (value_f["form"]["line"]["Area"])
|
|
{
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_line].fArea = value_f["form"]["line"]["Area"].asFloat();
|
|
}
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_line].strname = "line";
|
|
|
|
if (value_f["form"]["zangwu"]["open"])
|
|
{
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_zangwu].bOpen = value_f["form"]["zangwu"]["open"].asBool();
|
|
}
|
|
if (value_f["form"]["zangwu"]["Area"])
|
|
{
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_zangwu].fArea = value_f["form"]["zangwu"]["Area"].asFloat();
|
|
}
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_zangwu].strname = "zangwu";
|
|
|
|
if (value_f["form"]["edge"]["open"])
|
|
{
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_edge].bOpen = value_f["form"]["edge"]["open"].asBool();
|
|
}
|
|
if (value_f["form"]["edge"]["Area"])
|
|
{
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_edge].fArea = value_f["form"]["edge"]["Area"].asFloat();
|
|
}
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_edge].strname = "edge";
|
|
|
|
if (value_f["form"]["ymhs"]["open"])
|
|
{
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_ymhs].bOpen = value_f["form"]["ymhs"]["open"].asBool();
|
|
}
|
|
if (value_f["form"]["ymhs"]["Area"])
|
|
{
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_ymhs].fArea = value_f["form"]["ymhs"]["Area"].asFloat();
|
|
}
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_ymhs].strname = "ymhs";
|
|
|
|
if (value_f["form"]["dianzhuang"]["open"])
|
|
{
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_dianzhuang].bOpen = value_f["form"]["dianzhuang"]["open"].asBool();
|
|
}
|
|
if (value_f["form"]["dianzhuang"]["Area"])
|
|
{
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_dianzhuang].fArea = value_f["form"]["dianzhuang"]["Area"].asFloat();
|
|
}
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_dianzhuang].strname = "dianzhuang";
|
|
|
|
if (value_f["form"]["posun"]["open"])
|
|
{
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_posun].bOpen = value_f["form"]["posun"]["open"].asBool();
|
|
}
|
|
if (value_f["form"]["posun"]["Area"])
|
|
{
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_posun].fArea = value_f["form"]["posun"]["Area"].asFloat();
|
|
}
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_posun].strname = "posun";
|
|
|
|
if (value_f["form"]["xianwei"]["open"])
|
|
{
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_xianwei].bOpen = value_f["form"]["xianwei"]["open"].asBool();
|
|
}
|
|
if (value_f["form"]["xianwei"]["Area"])
|
|
{
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_xianwei].fArea = value_f["form"]["xianwei"]["Area"].asFloat();
|
|
}
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_xianwei].strname = "xianwei";
|
|
|
|
if (value_f["form"]["shuizi"]["open"])
|
|
{
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_shuizi].bOpen = value_f["form"]["shuizi"]["open"].asBool();
|
|
}
|
|
if (value_f["form"]["shuizi"]["Area"])
|
|
{
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_shuizi].fArea = value_f["form"]["shuizi"]["Area"].asFloat();
|
|
}
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_shuizi].strname = "shuizi";
|
|
|
|
if (value_f["form"]["danban"]["open"])
|
|
{
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_danban].bOpen = value_f["form"]["danban"]["open"].asBool();
|
|
}
|
|
if (value_f["form"]["danban"]["Area"])
|
|
{
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_danban].fArea = value_f["form"]["danban"]["Area"].asFloat();
|
|
}
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_danban].strname = "danban";
|
|
|
|
if (value_f["form"]["fuchen"]["open"])
|
|
{
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_fuchen].bOpen = value_f["form"]["fuchen"]["open"].asBool();
|
|
}
|
|
if (value_f["form"]["fuchen"]["Area"])
|
|
{
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_fuchen].fArea = value_f["form"]["fuchen"]["Area"].asFloat();
|
|
}
|
|
_config.bigNG.qx[CONFIG_QX_NAME_cell_fuchen].strname = "fuchen";
|
|
}
|
|
else
|
|
{
|
|
_config.bigNG.Init();
|
|
}
|
|
// _config.edgeDet.print("edgeDet");
|
|
// getchar();
|
|
}
|
|
return 0;
|
|
}
|