diff --git a/AlgorithmModule/include/ImgCheckConfig.h b/AlgorithmModule/include/ImgCheckConfig.h index 023ee05..412209f 100644 --- a/AlgorithmModule/include/ImgCheckConfig.h +++ b/AlgorithmModule/include/ImgCheckConfig.h @@ -74,61 +74,9 @@ enum ERROR_TYPE_ ERROR_TYPE_LackPol, // 缺失Pol ERROR_TYPE_COUNT, }; -static const std::string QX_Result_Names[] = - { - "OK", - "AD_YX", - "X_Line", - "Y_Line", - "fangge", - "Rubbing_Mura", - "Broken_line", - "ZARA", - "MTX", - "POL_Cell", - "Bright_Point", - "Dark_Point", - "BLack_Point", - "White_Point", - "Scratch", - "Weak_Bright_Mura", - "No_Label", - "Bright_Mura_Exe", - "Sweak_Line_Dark", - "STEAM_POCKET", - "Dirty", - "other", - "Cell_W", - "Cell_B", - "LackPol"}; -static const std::string QX_Result_Code[] = - { - "P1153", - "P6873", - "P3351", - "P3452", - "P3453", - "P1550", - "P3379", - "P1153", - "P1164", - "P1101", - "P1112", - "P1111", - "P1104", - "P1103", - "P1557", - "P1654", - "P2833", - "P1549", - "P1204", - "P2534", - "P2534", - "P1101", - "P1103", - "P1104", - "P8001", -}; +extern std::vector QX_Result_Names; +extern std::vector QX_Result_Code; + // 检测检测参数类型 enum CHECK_CONFIG_TYPE_ { @@ -172,6 +120,20 @@ enum DET_MODE_ #define MAX_REGION_NUM 20 +struct ReadFlawCode +{ + std::string flaw_name; + std::string flaw_code; + std::vector config_flaw_name; + ReadFlawCode() + { + config_flaw_name.clear(); + flaw_name = ""; + flaw_code = ""; + } +}; +extern std::vector m_FlawCodeList; + // 一个检测项基本信息,包括图片序号,图片、开始时间 struct shareImage { diff --git a/AlgorithmModule/src/ALLImgCheckAnalysisy.cpp b/AlgorithmModule/src/ALLImgCheckAnalysisy.cpp index dad41e3..7fec72c 100644 --- a/AlgorithmModule/src/ALLImgCheckAnalysisy.cpp +++ b/AlgorithmModule/src/ALLImgCheckAnalysisy.cpp @@ -10,6 +10,126 @@ #include "CheckUtil.hpp" #include "Define.h" #include "AI_Factory.h" +#include + +std::vector m_FlawCodeList; + +std::vector QX_Result_Names = + { + "OK", + "AD_YX", + "X_Line", + "Y_Line", + "fangge", + "Rubbing_Mura", + "Broken_line", + "ZARA", + "MTX", + "POL_Cell", + "Bright_Point", + "Dark_Point", + "BLack_Point", + "White_Point", + "Scratch", + "Weak_Bright_Mura", + "No_Label", + "Bright_Mura_Exe", + "Sweak_Line_Dark", + "STEAM_POCKET", + "Dirty", + "other", + "Cell_W", + "Cell_B", + "LackPol"}; +std::vector QX_Result_Code = + { + "P1153", + "P6873", + "P3351", + "P3452", + "P3453", + "P1550", + "P3379", + "P1153", + "P1164", + "P1101", + "P1112", + "P1111", + "P1104", + "P1103", + "P1557", + "P1654", + "P2833", + "P1549", + "P1204", + "P2534", + "P2534", + "P1101", + "P1103", + "P1104", + "P8001", +}; + + +int ReadFlawCodeConfig(std::string json_path) +{ + m_FlawCodeList.erase(m_FlawCodeList.begin(), m_FlawCodeList.end()); + std::string strPath = json_path; + printf("ReadFlawCodeConfig path %s\n", strPath.c_str()); + Json::CharReaderBuilder builder; + builder["collectComments"] = true; + Json::Value root; + std::string err; + std::ifstream ifs(strPath); + if (!ifs.is_open()) + { + printf("error:file is open\n"); + return 0; + } + if (!Json::parseFromStream(builder, ifs, &root, &err)) + { + printf("error:parseFromStream\n"); + return 0; + } + + for (int i = 0; i < root.size(); i++) + { + // printf("Node idx %d /%d \n", i, root.size()); + + ReadFlawCode tem; + tem.flaw_name = root[i]["zh_name"].asString(); + tem.flaw_code = root[i]["en_name"].asString(); + string desc = root[i]["desc"].asString(); + { + + std::istringstream stream(desc); + std::string token; + + // 使用 getline 按照分号分割 + while (std::getline(stream, token, ';')) + { + tem.config_flaw_name.push_back(token); + } + } + m_FlawCodeList.push_back(tem); + } + for(int i = 0; i < m_FlawCodeList.size(); i++) + { + if(i >= QX_Result_Names.size()) { + QX_Result_Names.push_back(m_FlawCodeList.at(i).flaw_name); + QX_Result_Code.push_back(m_FlawCodeList.at(i).flaw_code); + } + else + { + QX_Result_Names.at(i) = m_FlawCodeList.at(i).flaw_name; + QX_Result_Code.at(i) = m_FlawCodeList.at(i).flaw_code; + } + + } + return 0; +} + + double calculateDistanceBetweenRectCenters(const cv::Rect &rect1, const cv::Rect &rect2, float fx, float fy) { // 计算矩形1的中心点 @@ -309,6 +429,7 @@ int ALLImgCheckAnalysisy::ExitSystem() int ALLImgCheckAnalysisy::InitCameraCheckAnalysisy() { + ReadFlawCodeConfig("/var/aidlux/efs/cell_aoi/model/defect_list.json"); m_pCameraCheckAnalysisyList.clear(); // m_pQX_Merge_Analysis->Clear(); for (const auto &config : m_pConfigManager->Config_instances_) diff --git a/AlgorithmModule/src/ImageResultJudge.cpp b/AlgorithmModule/src/ImageResultJudge.cpp index f5ed937..0301b80 100644 --- a/AlgorithmModule/src/ImageResultJudge.cpp +++ b/AlgorithmModule/src/ImageResultJudge.cpp @@ -590,6 +590,8 @@ int ImageResultJudge::ResultJudge(std::shared_ptr pImageResult) tem.strTypeName = QX_Result_Names[nqx_type]; tem.qx_Code = QX_Result_Code[nqx_type]; tem.srcImgroi = roi; + tem.srcImgroi.x += pDetResult->CutRoi.x; + tem.srcImgroi.y += pDetResult->CutRoi.y; tem.len = flen; tem.qx_type = 0; tem.fScore = 0; @@ -637,6 +639,9 @@ int ImageResultJudge::ResultJudge(std::shared_ptr pImageResult) m_CheckResult_shareP->YS_ImageResult.push_back(tem); } + + pQxLog->AddCheckstr(PrintLevel_4, DET_LOG_LEVEL_3, " result ", " name %s ---code %s", tem.strTypeName.c_str(), tem.qx_Code.c_str()); + } // 对于大面积 的zara和 异显NG ,可以不接着分析后续的数据了。应为后续估计有很多错误类别。 @@ -842,6 +847,8 @@ int ImageResultJudge::MergeResult(std::shared_ptr pImageResult, tem.strTypeName = QX_Result_Names[nqx_type]; tem.qx_Code = QX_Result_Code[nqx_type]; tem.srcImgroi = roi; + tem.srcImgroi.x += pDetResult->CutRoi.x; + tem.srcImgroi.y += pDetResult->CutRoi.y; tem.len = flen; tem.qx_type = ptemre->resultList.at(iqx).error_Type; tem.minDis_mm = ptemre->resultList.at(iqx).mindis; @@ -1246,137 +1253,116 @@ int ImageResultJudge::GetParamidx() int ImageResultJudge::ConfigTypeToResultType(int nconfigType) { - - // CONFIG_QX_NAME_ok_yisi, // 疑似 - // CONFIG_QX_NAME_AD_YX, // AD异显(P6873) - // CONFIG_QX_NAME_X_line, // X_line(P3351) - // CONFIG_QX_NAME_Y_line, // Y_line(P3452) - // CONFIG_QX_NAME_Broken_line, // 断线(P3379) - // CONFIG_QX_NAME_zara, // ZARA(P1153) - // CONFIG_QX_NAME_MTX, // MTX(P1164) - // CONFIG_QX_NAME_POL_Cell, // 异物(P1101) - // CONFIG_QX_NAME_LD, // 亮点(P1112) - // CONFIG_QX_NAME_AD, // 暗点(P1111) - // CONFIG_QX_NAME_Scratch_L1, // 一级 轻 划伤(P1557) - // CONFIG_QX_NAME_Scratch_L2, // 二级 严重 划伤(P1557) - // CONFIG_QX_NAME_Dirty_L0, // 疑似浅层脏污(P0000) - // CONFIG_QX_NAME_Dirty_L1, // 轻脏污(P0000) - // CONFIG_QX_NAME_Dirty_L2, // 严重脏污(P0000) - // CONFIG_QX_NAME_qipao, // 气泡(P0001) - // CONFIG_QX_NAME_PS, // ps(P0002) - // CONFIG_QX_NAME_Weak_Bright_Mura, // 白GAP(P1654) - // CONFIG_QX_NAME_No_Label, // 缺POL(P2833) - - // ERROR_TYPE_OK, // 0 疑是 - // ERROR_TYPE_AD_YX, // 1 AD-异常显示 - // ERROR_TYPE_Line_X, // 2 x line - // ERROR_TYPE_Line_Y, // 3 y line - // ERROR_TYPE_Rubbing_Mura, // 4 - // ERROR_TYPE_line_Broken, // 5 断线 - // ERROR_TYPE_ZARA, // 6 ZARA - // ERROR_TYPE_MTX, // 7 MTX - // ERROR_TYPE_POL_Cell, // 8 异物 - // ERROR_TYPE_LD, // 9 亮点 - // ERROR_TYPE_AD, // 10 暗点 - // ERROR_TYPE_BD, // 11 黑点 - // ERROR_TYPE_WD, // 12 白点 - // ERROR_TYPE_Scratch, // 13 划伤 - // ERROR_TYPE_Weak_Bright_Mura, // 14 白GAP - // ERROR_TYPE_No_Label, // 15 缺POL - // ERROR_TYPE_PS, // 16 PS - // ERROR_TYPE_GRID_LINE, // 17 方格线 - // ERROR_TYPE_STEAM_POCKET, // 19 气泡 - // ERROR_TYPE_Dirty, // 19 脏污 - + bool bdesc = false; int resultError_type = ERROR_TYPE_OK; - switch (nconfigType) + if(nconfigType < CONFIG_QX_NAME_Names.size()) { - case CONFIG_QX_NAME_ok_yisi: - resultError_type = ERROR_TYPE_OK; - break; - case CONFIG_QX_NAME_AD_YX: - resultError_type = ERROR_TYPE_AD_YX; - break; - case CONFIG_QX_NAME_Class_AD_YX: - resultError_type = ERROR_TYPE_AD_YX; - break; - case CONFIG_QX_NAME_X_line: - resultError_type = ERROR_TYPE_Line_X; - break; - case CONFIG_QX_NAME_Y_line: - resultError_type = ERROR_TYPE_Line_Y; - break; - case CONFIG_QX_NAME_Fangge: - resultError_type = ERROR_TYPE_Line_fangge; - break; - case CONFIG_QX_NAME_Broken_line: - resultError_type = ERROR_TYPE_line_Broken; - break; - case CONFIG_QX_NAME_zara: - resultError_type = ERROR_TYPE_ZARA; - break; - case CONFIG_QX_NAME_MTX: - resultError_type = ERROR_TYPE_MTX; - break; - case CONFIG_QX_NAME_POL_Cell: - resultError_type = ERROR_TYPE_POL_Cell; - break; - case CONFIG_QX_NAME_LD: - resultError_type = ERROR_TYPE_LD; - break; - case CONFIG_QX_NAME_AD: - resultError_type = ERROR_TYPE_AD; - break; - case CONFIG_QX_NAME_Scratch_L1: - resultError_type = ERROR_TYPE_Scratch; - break; - case CONFIG_QX_NAME_Scratch_L2: - resultError_type = ERROR_TYPE_Scratch; - break; - case CONFIG_QX_NAME_Dirty_L0: - resultError_type = ERROR_TYPE_Dirty; - break; - case CONFIG_QX_NAME_Dirty_L1: - resultError_type = ERROR_TYPE_Dirty; - break; - case CONFIG_QX_NAME_Dirty_L2: - resultError_type = ERROR_TYPE_Dirty; - break; - case CONFIG_QX_NAME_qipao: - resultError_type = ERROR_TYPE_STEAM_POCKET; - break; - case CONFIG_QX_NAME_PS: - resultError_type = ERROR_TYPE_PS; - break; - case CONFIG_QX_NAME_Weak_Bright_Mura: - resultError_type = ERROR_TYPE_Weak_Bright_Mura; - break; - case CONFIG_QX_NAME_No_Label: - resultError_type = ERROR_TYPE_No_Label; - break; - case CONFIG_QX_NAME_Other: - resultError_type = ERROR_TYPE_Other; - break; - case CONFIG_QX_NAME_Chess: - resultError_type = ERROR_TYPE_Other; - break; - case CONFIG_QX_NAME_127Cell: - resultError_type = ERROR_TYPE_POL_Cell; - break; - case CONFIG_QX_NAME_white_Cell: - resultError_type = ERROR_TYPE_Cell_W; - break; - case CONFIG_QX_NAME_black_Cell: - resultError_type = ERROR_TYPE_Cell_B; - break; - case CONFIG_QX_NAME_LackPOL: - resultError_type = ERROR_TYPE_LackPol; - break; - default: - break; + string cqn = CONFIG_QX_NAME_Names[nconfigType]; + for(int i = 0; i < m_FlawCodeList.size(); i++) + { + for(int j = 0; j < m_FlawCodeList.at(i).config_flaw_name.size(); j++) + { + if(cqn == m_FlawCodeList.at(i).config_flaw_name[j]) + { + resultError_type = i; + bdesc = true; + break; + } + } + } + } + // 如果描述没有配置,用默认值 + if(!bdesc) + { + int resultError_type = ERROR_TYPE_OK; + switch (nconfigType) + { + case CONFIG_QX_NAME_ok_yisi: + resultError_type = ERROR_TYPE_OK; + break; + case CONFIG_QX_NAME_AD_YX: + resultError_type = ERROR_TYPE_AD_YX; + break; + case CONFIG_QX_NAME_Class_AD_YX: + resultError_type = ERROR_TYPE_AD_YX; + break; + case CONFIG_QX_NAME_X_line: + resultError_type = ERROR_TYPE_Line_X; + break; + case CONFIG_QX_NAME_Y_line: + resultError_type = ERROR_TYPE_Line_Y; + break; + case CONFIG_QX_NAME_Fangge: + resultError_type = ERROR_TYPE_Line_fangge; + break; + case CONFIG_QX_NAME_Broken_line: + resultError_type = ERROR_TYPE_line_Broken; + break; + case CONFIG_QX_NAME_zara: + resultError_type = ERROR_TYPE_ZARA; + break; + case CONFIG_QX_NAME_MTX: + resultError_type = ERROR_TYPE_MTX; + break; + case CONFIG_QX_NAME_POL_Cell: + resultError_type = ERROR_TYPE_POL_Cell; + break; + case CONFIG_QX_NAME_LD: + resultError_type = ERROR_TYPE_LD; + break; + case CONFIG_QX_NAME_AD: + resultError_type = ERROR_TYPE_AD; + break; + case CONFIG_QX_NAME_Scratch_L1: + resultError_type = ERROR_TYPE_Scratch; + break; + case CONFIG_QX_NAME_Scratch_L2: + resultError_type = ERROR_TYPE_Scratch; + break; + case CONFIG_QX_NAME_Dirty_L0: + resultError_type = ERROR_TYPE_Dirty; + break; + case CONFIG_QX_NAME_Dirty_L1: + resultError_type = ERROR_TYPE_Dirty; + break; + case CONFIG_QX_NAME_Dirty_L2: + resultError_type = ERROR_TYPE_Dirty; + break; + case CONFIG_QX_NAME_qipao: + resultError_type = ERROR_TYPE_STEAM_POCKET; + break; + case CONFIG_QX_NAME_PS: + resultError_type = ERROR_TYPE_PS; + break; + case CONFIG_QX_NAME_Weak_Bright_Mura: + resultError_type = ERROR_TYPE_Weak_Bright_Mura; + break; + case CONFIG_QX_NAME_No_Label: + resultError_type = ERROR_TYPE_No_Label; + break; + case CONFIG_QX_NAME_Other: + resultError_type = ERROR_TYPE_Other; + break; + case CONFIG_QX_NAME_Chess: + resultError_type = ERROR_TYPE_Other; + break; + case CONFIG_QX_NAME_127Cell: + resultError_type = ERROR_TYPE_POL_Cell; + break; + case CONFIG_QX_NAME_white_Cell: + resultError_type = ERROR_TYPE_Cell_W; + break; + case CONFIG_QX_NAME_black_Cell: + resultError_type = ERROR_TYPE_Cell_B; + break; + case CONFIG_QX_NAME_LackPOL: + resultError_type = ERROR_TYPE_LackPol; + break; + default: + break; + } } return resultError_type; - return 0; } int ImageResultJudge::sendTask(std::shared_ptr task) diff --git a/ConfigModule/include/CheckConfigDefine.h b/ConfigModule/include/CheckConfigDefine.h index c70b52b..9cd5af7 100644 --- a/ConfigModule/include/CheckConfigDefine.h +++ b/ConfigModule/include/CheckConfigDefine.h @@ -74,7 +74,7 @@ enum CONFIG_QX_NAME_ CONFIG_QX_NAME_count, }; // 缺陷项对应在参数中的名称 -static const std::string CONFIG_QX_NAME_Names[] = +static std::vector CONFIG_QX_NAME_Names = { "ok_yisi", "AD_YX",