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.
198 lines
6.0 KiB
198 lines
6.0 KiB
#include "CheckResultJson.h"
|
|
|
|
Json::Value CheckResultJson::toJsonValue()
|
|
{
|
|
Json::Value root;
|
|
|
|
{
|
|
|
|
root["cutRoi"]["x"] = m_pOneImgDetResult->CutRoi.x;
|
|
root["cutRoi"]["y"] = m_pOneImgDetResult->CutRoi.y;
|
|
root["cutRoi"]["width"] = m_pOneImgDetResult->CutRoi.width;
|
|
root["cutRoi"]["height"] = m_pOneImgDetResult->CutRoi.height;
|
|
}
|
|
{
|
|
|
|
root["Param_CropRoi"]["x"] = m_pOneImgDetResult->Param_CropRoi.x;
|
|
root["Param_CropRoi"]["y"] = m_pOneImgDetResult->Param_CropRoi.y;
|
|
root["Param_CropRoi"]["width"] = m_pOneImgDetResult->Param_CropRoi.width;
|
|
root["Param_CropRoi"]["height"] = m_pOneImgDetResult->Param_CropRoi.height;
|
|
}
|
|
{
|
|
// 图像模糊度(清晰度)检测结果: 在 AI 检测之前计算
|
|
root["blurScore"] = m_pOneImgDetResult->fBlurScore;
|
|
root["isBlur"] = m_pOneImgDetResult->bBlurNG;
|
|
}
|
|
for (int i = 0; i < m_pOneImgDetResult->pQx_ErrorList->size(); i++)
|
|
{
|
|
QX_ERROR_INFO_ *p = &m_pOneImgDetResult->pQx_ErrorList->at(i);
|
|
Json::Value value;
|
|
{
|
|
|
|
value["Idx"] = p->Idx;
|
|
value["result"] = p->result;
|
|
value["result_Name"] = p->result_name;
|
|
value["roi"]["x"] = p->roi.x;
|
|
value["roi"]["y"] = p->roi.y;
|
|
value["roi"]["width"] = p->roi.width;
|
|
value["roi"]["height"] = p->roi.height;
|
|
value["area"] = p->area;
|
|
value["energy"] = p->energy;
|
|
value["JudgArea"] = p->JudgArea;
|
|
value["JudgArea_second"] = p->JudgArea_second;
|
|
value["flen"] = p->flen;
|
|
value["nconfig_qx_type"] = p->nconfig_qx_type;
|
|
value["qx_name"] = p->qx_name;
|
|
value["qx_level"] = p->qx_level;
|
|
value["det_model_name"] = p->strModelName;
|
|
value["maxValue"] = p->maxValue;
|
|
value["grayDis"] = p->grayDis;
|
|
value["fUpIou"] = p->fUpIou;
|
|
value["density"] = p->density;
|
|
// return root;
|
|
for (int jr = 0; jr < p->detRegionidxList.size(); jr++)
|
|
{
|
|
|
|
value["regionlist"].append(p->detRegionidxList[jr]);
|
|
}
|
|
}
|
|
root["Qx"].append(value);
|
|
}
|
|
|
|
return root;
|
|
}
|
|
|
|
void CheckResultJson::toObjectFromValue(Json::Value root)
|
|
{
|
|
|
|
m_pOneImgDetResult = std::make_shared<One_Image_CheckResult_>();
|
|
m_pOneImgDetResult->pQx_ErrorList = std::make_shared<std::vector<QX_ERROR_INFO_>>();
|
|
// std::cout << root << std::endl;
|
|
|
|
{
|
|
auto value = root["cutRoi"];
|
|
if (value.isObject())
|
|
{
|
|
|
|
m_pOneImgDetResult->CutRoi.x = root["cutRoi"]["x"].asInt();
|
|
m_pOneImgDetResult->CutRoi.y = root["cutRoi"]["y"].asInt();
|
|
m_pOneImgDetResult->CutRoi.width = root["cutRoi"]["width"].asInt();
|
|
m_pOneImgDetResult->CutRoi.height = root["cutRoi"]["height"].asInt();
|
|
}
|
|
}
|
|
{
|
|
auto value = root["Param_CropRoi"];
|
|
if (value.isObject())
|
|
{
|
|
|
|
m_pOneImgDetResult->Param_CropRoi.x = root["Param_CropRoi"]["x"].asInt();
|
|
m_pOneImgDetResult->Param_CropRoi.y = root["Param_CropRoi"]["y"].asInt();
|
|
m_pOneImgDetResult->Param_CropRoi.width = root["Param_CropRoi"]["width"].asInt();
|
|
m_pOneImgDetResult->Param_CropRoi.height = root["Param_CropRoi"]["height"].asInt();
|
|
}
|
|
}
|
|
{
|
|
// 图像模糊度(清晰度)检测结果; 旧版本 json 可能没有该字段
|
|
if (root.isMember("blurScore"))
|
|
{
|
|
m_pOneImgDetResult->fBlurScore = root["blurScore"].asFloat();
|
|
}
|
|
if (root.isMember("isBlur"))
|
|
{
|
|
m_pOneImgDetResult->bBlurNG = root["isBlur"].asBool();
|
|
}
|
|
}
|
|
{
|
|
if (root.isMember("Qx"))
|
|
{
|
|
|
|
const Json::Value &errorList = root["Qx"];
|
|
for (const auto &errorJson : errorList)
|
|
{
|
|
|
|
QX_ERROR_INFO_ tem;
|
|
tem.Idx = errorJson["Idx"].asInt();
|
|
|
|
// tem.result = errorJson["result"].asInt();
|
|
// tem.result_name = errorJson["result_Name"].asString();
|
|
|
|
tem.roi.x = errorJson["roi"]["x"].asInt();
|
|
tem.roi.y = errorJson["roi"]["y"].asInt();
|
|
tem.roi.width = errorJson["roi"]["width"].asInt();
|
|
tem.roi.height = errorJson["roi"]["height"].asInt();
|
|
tem.area = errorJson["area"].asInt();
|
|
tem.energy = errorJson["energy"].asInt();
|
|
tem.JudgArea = errorJson["JudgArea"].asFloat();
|
|
if (errorJson["JudgArea_second"])
|
|
{
|
|
tem.JudgArea_second = errorJson["JudgArea_second"].asFloat();
|
|
}
|
|
else
|
|
{
|
|
tem.JudgArea_second = tem.JudgArea;
|
|
}
|
|
|
|
tem.flen = errorJson["flen"].asFloat();
|
|
tem.nconfig_qx_type = errorJson["nconfig_qx_type"].asInt();
|
|
tem.qx_name = errorJson["qx_name"].asString();
|
|
// 旧版本 json 可能没有 qx_level 字段
|
|
if (errorJson.isMember("qx_level"))
|
|
{
|
|
tem.qx_level = errorJson["qx_level"].asString();
|
|
}
|
|
// 旧版本 json 可能没有该字段
|
|
if (errorJson.isMember("det_model_name"))
|
|
{
|
|
tem.strModelName = errorJson["det_model_name"].asString();
|
|
}
|
|
tem.maxValue = errorJson["maxValue"].asInt();
|
|
tem.grayDis = errorJson["grayDis"].asFloat();
|
|
tem.fUpIou = errorJson["fUpIou"].asFloat();
|
|
tem.density = errorJson["density"].asFloat();
|
|
|
|
const Json::Value ®ionvalue = errorJson["regionlist"];
|
|
|
|
if (regionvalue.isArray())
|
|
{
|
|
// std::cout<<regionvalue<<std::endl;
|
|
for (const auto ®ion : regionvalue)
|
|
{
|
|
tem.detRegionidxList.push_back(region.asInt());
|
|
}
|
|
}
|
|
|
|
m_pOneImgDetResult->pQx_ErrorList->push_back(tem);
|
|
|
|
// tem.print(std::to_string(m_pOneImgDetResult->pQx_ErrorList->size()));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
int CheckResultJson::GetConfig(std::string strJson, std::shared_ptr<One_Image_CheckResult_> &pOneImgDetResult)
|
|
{
|
|
Json::CharReader *reader = readerBuilder.newCharReader();
|
|
string errs;
|
|
bool parsingSuccessful = reader->parse(strJson.c_str(), strJson.c_str() + strJson.size(), &root, &errs);
|
|
delete reader;
|
|
if (!parsingSuccessful)
|
|
{
|
|
cout << "Failed to parse JSON string: " << errs << endl;
|
|
return 1;
|
|
}
|
|
toObjectFromValue(root);
|
|
pOneImgDetResult = m_pOneImgDetResult;
|
|
return 0;
|
|
}
|
|
|
|
std::string CheckResultJson::GetResultString(std::shared_ptr<One_Image_CheckResult_> &pOneImgDetResult)
|
|
{
|
|
m_pOneImgDetResult = pOneImgDetResult;
|
|
|
|
Json::Value root = toJsonValue();
|
|
Json::StreamWriterBuilder writerBuilder;
|
|
std::string jsonString = Json::writeString(writerBuilder, root);
|
|
|
|
return jsonString;
|
|
}
|