#include "CheckBaseParam.hpp" Json::Value CheckBaseParamJson::toJsonValue() { return Json::Value(); } void CheckBaseParamJson::toObjectFromValue(Json::Value root) { m_pconfig = std::make_shared(); // std::cout << root << std::endl; std::string value = root["value"].asString(); std::cout << value << std::endl; { auto strJson = value; Json::CharReaderBuilder builder; std::unique_ptr 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"]; if (value.isObject()) { m_pconfig->imageScaleParam.fScale_X = value["fScale_X"].asFloat(); if (m_pconfig->imageScaleParam.fScale_X <= 0) { m_pconfig->imageScaleParam.fScale_X = 0.0333; /* code */ } m_pconfig->imageScaleParam.fScale_Y = value["fScale_Y"].asFloat(); if (m_pconfig->imageScaleParam.fScale_Y <= 0) { m_pconfig->imageScaleParam.fScale_Y = 0.0333; /* code */ } m_pconfig->imageScaleParam.print("dfdf"); } } // // 和节点无关参数提取 // { // auto value = rootvalue["customs"]; // if (value.isObject()) // { // m_pconfig->crop.x = value["Crop"]["x"].asInt(); // m_pconfig->crop.y = value["Crop"]["y"].asInt(); // m_pconfig->crop.width = value["Crop"]["width"].asInt(); // m_pconfig->crop.height = value["Crop"]["height"].asInt(); // } // } { // 和节点无关参数提取 auto valuefunction = rootvalue["baseCheckData"]; if (valuefunction.isArray()) { for (int idx = 0; idx < valuefunction.size(); idx++) { GetFunction(valuefunction[idx]); } // _config.print("channelFunction"); m_pconfig->crop = m_pconfig->baseCheckFunction.detconfig.cropROI; } } // 读取每个节点的参数 { 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< 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]["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); } } } m_pconfig->nodeConfigArr.push_back(tem_node); } } // // 读取每个节点的参数 // { // auto value_node = rootvalue["node"]; // // 读取每个节点的参数 // for (int i = 0; i < value_node.size(); i++) // { // // printf("Node idx %d /%d \n", i, value_node.size()); // // 读取当前节点下 的每张图片 一般只读第一张图 // { // auto value_node_imgs = value_node[i]["node_images"]; // if (value_node_imgs.size() > 0) // { // int img_idx = 0; // auto value_node_imgs_region = value_node_imgs[img_idx]["params"]; // if (value_node_imgs_region.size() > 0) // { // std::cout << value_node_imgs_region << std::endl; // for (int region_idx = 0; region_idx < value_node_imgs_region.size(); region_idx++) // { // RegionCheckConfig temregion; // if (value_node_imgs_region[region_idx]["Check"]["zangwu"][0]["state"]) // { // temregion.qxSegParam.buse = value_node_imgs_region[region_idx]["Check"]["zangwu"][0]["state"].asBool(); // } // if (value_node_imgs_region[region_idx]["Check"]["zangwu"][0]["area"]) // { // temregion.qxSegParam.Area = value_node_imgs_region[region_idx]["Check"]["zangwu"][0]["area"].asFloat(); // } // if (value_node_imgs_region[region_idx]["Check"]["zangwu"][0]["hj"]) // { // temregion.qxSegParam.GrayDis = value_node_imgs_region[region_idx]["Check"]["zangwu"][0]["hj"].asFloat(); // } // if (value_node_imgs_region[region_idx]["YS_Config"]["zangwu"][0]["state"]) // { // temregion.ysSegParam.buse = value_node_imgs_region[region_idx]["YS_Config"]["zangwu"][0]["state"].asBool(); // } // if (value_node_imgs_region[region_idx]["YS_Config"]["zangwu"][0]["area"]) // { // temregion.ysSegParam.Area = value_node_imgs_region[region_idx]["YS_Config"]["zangwu"][0]["area"].asFloat(); // } // if (value_node_imgs_region[region_idx]["YS_Config"]["zangwu"][0]["hj"]) // { // temregion.ysSegParam.GrayDis = value_node_imgs_region[region_idx]["YS_Config"]["zangwu"][0]["hj"].asFloat(); // } // // 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() - m_pconfig->crop.x; // p.y = value_node_imgs_region_coord[idx][1].asInt() - m_pconfig->crop.y; // if (p.x < 0) // { // p.x = 0; // } // if (p.y < 0) // { // p.y = 0; // } // temregion.pointArry.push_back(p); // } // temregion.Det_Roi = cv::boundingRect(m_pconfig->pointArry); // } // } // m_pconfig->regionCheckConfig.push_back(temregion); // } // if (value_node_imgs_region[0]["Check"]["zangwu"][0]["state"]) // { // m_pconfig->qxSegParam.buse = value_node_imgs_region[0]["Check"]["zangwu"][0]["state"].asBool(); // } // if (value_node_imgs_region[0]["Check"]["zangwu"][0]["area"]) // { // m_pconfig->qxSegParam.Area = value_node_imgs_region[0]["Check"]["zangwu"][0]["area"].asFloat(); // } // if (value_node_imgs_region[0]["Check"]["zangwu"][0]["hj"]) // { // m_pconfig->qxSegParam.GrayDis = value_node_imgs_region[0]["Check"]["zangwu"][0]["hj"].asFloat(); // } // if (value_node_imgs_region[0]["YS_Config"]["zangwu"][0]["state"]) // { // m_pconfig->ysSegParam.buse = value_node_imgs_region[0]["YS_Config"]["zangwu"][0]["state"].asBool(); // } // if (value_node_imgs_region[0]["YS_Config"]["zangwu"][0]["area"]) // { // m_pconfig->ysSegParam.Area = value_node_imgs_region[0]["YS_Config"]["zangwu"][0]["area"].asFloat(); // } // if (value_node_imgs_region[0]["YS_Config"]["zangwu"][0]["hj"]) // { // m_pconfig->ysSegParam.GrayDis = value_node_imgs_region[0]["YS_Config"]["zangwu"][0]["hj"].asFloat(); // } // // 2、读取区域点 // { // auto value_node_imgs_region_coord = value_node_imgs_region[0]["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() - m_pconfig->crop.x; // p.y = value_node_imgs_region_coord[idx][1].asInt() - m_pconfig->crop.y; // if (p.x < 0) // { // p.x = 0; // } // if (p.y < 0) // { // p.y = 0; // } // m_pconfig->pointArry.push_back(p); // } // m_pconfig->Det_Roi = cv::boundingRect(m_pconfig->pointArry); // } // } // // m_pconfig->print("dfeffff"); // } // } // } // } // } // getchar(); m_pconfig->print("dfeffff"); } else { printf("--- ******error json*** \n"); } } // getchar(); } int CheckBaseParamJson::GetConfig(std::shared_ptr &pconfig) { pconfig = m_pconfig; return 0; } int CheckBaseParamJson::GetFunction(Json::Value value) { std::string strCode = value["itemCode"].asString(); // std::cout << strCode << std::endl; // 读取UP 过滤功能 if ("DetConfig" == strCode) { auto value_f = value; // std::cout << value_f << std::endl; // getchar(); Base_Function_DetConfig *pdetConfig = &m_pconfig->baseCheckFunction.detconfig; pdetConfig->bOpen = value_f["isOpen"].asBool(); if (pdetConfig->bOpen) { { auto crop_roi = value_f["form"]["Crop_Config"]["ROI"]; { if (crop_roi["x"]) { pdetConfig->cropROI.x = crop_roi["x"].asInt(); } if (crop_roi["y"]) { pdetConfig->cropROI.y = crop_roi["y"].asInt(); } if (crop_roi["width"]) { pdetConfig->cropROI.width = crop_roi["width"].asInt(); } if (crop_roi["height"]) { pdetConfig->cropROI.height = crop_roi["height"].asInt(); } } // //测试 // auto test_param = value_f["form"]["Crop_Config"]["DD"].asInt(); // 1020-add // bool dd_disabled = value_f["form"]["Crop_Config"]["DD_disabled"].asBool(); // 1020-add // auto LablCircleradius = value_f["form"]["Test_Data"]["CenterP"]["radius"].asInt(); // auto LablCircleCoordinate = value_f["form"]["Test_Data"]["CenterP"]["path"]; // cv::Point CircleP = cv::Point(0, 0); // if (LablCircleCoordinate.isArray()) // { // CircleP.x = LablCircleCoordinate[0][0].asInt(); // CircleP.y = LablCircleCoordinate[0][1].asInt(); // } // std::vector lablPoints; // auto test_area = value_f["form"]["Test_Data"]["test_area"]; // if (test_area.isArray()) // { // for (auto it: test_area) { // lablPoints.emplace_back(cv::Point(it[0].asInt(), it[1].asInt())); // } // } auto rotate = value_f["form"]["RotateConfig"]["Rotate"].asInt(); // 1020-add if (rotate == 0) { pdetConfig->rotate = Ratio_0; } else if (rotate == 90) { pdetConfig->rotate = Ratio_90; } else if (rotate == 180) { pdetConfig->rotate = Ratio_180; } else if (rotate == 270) { pdetConfig->rotate = Ratio_270; } else { pdetConfig->rotate = Ratio_0; } } } else { pdetConfig->Init(); } } if ("ChipOffset" == strCode) // 1009-add { auto value_f = value; std::cout << value_f << std::endl; // std::cout << "m_pconfig->baseCheckFunction.bChipOffsetOpen=" << m_pconfig->baseCheckFunction.bChipOffsetOpen << std::endl; // 1009-add Base_Function_DetConfig *pdetConfig = &m_pconfig->baseCheckFunction.detconfig; pdetConfig->bOpen = value_f["isOpen"].asBool(); // std::cout << "pdetConfig->bOpen--isOpenFlag=" << pdetConfig->bOpen << std::endl; // 1009-add // getchar();//1020-add if (pdetConfig->bOpen) { // auto crop_roi = value_f["form"]["Crop_Config"]["ROI"]; // { // if (crop_roi["x"]) // { // pdetConfig->cropROI.x = crop_roi["x"].asInt(); // } // if (crop_roi["y"]) // { // pdetConfig->cropROI.y = crop_roi["y"].asInt(); // } // if (crop_roi["width"]) // { // pdetConfig->cropROI.width = crop_roi["width"].asInt(); // } // if (crop_roi["height"]) // { // pdetConfig->cropROI.height = crop_roi["height"].asInt(); // } // } auto LabelPolygon = value_f["form"]["Crop_Config"]["Polygon"]; if (LabelPolygon.isArray()) { for (int i = 0; i < LabelPolygon.size(); i++) { cv::Point p; p.x = LabelPolygon[i][0].asInt(); p.y = LabelPolygon[i][1].asInt(); if (p.x < 0) { p.x = 0; } if (p.y < 0) { p.y = 0; } // std::cout << i << "------p.x=" << p.x << std::endl; // std::cout << i << "------p.y=" << p.y << std::endl; pdetConfig->pointArry.push_back(p); } pdetConfig->LabelPolygonBoundingRect = cv::boundingRect(pdetConfig->pointArry); // 获取芯片区域的标记多边形最大外接矩形 } } else { pdetConfig->Init(); } } return 0; }