/* //实现对部分缺陷 需要进行 数量 和距离上分析的 */ #ifndef QX_Analysis_H_ #define QX_Analysis_H_ #include #include "CheckUtil.hpp" #include "CheckErrorCodeDefine.hpp" using namespace std; enum QX_ANALYSIS_NAME { QX_ANALYSIS_POL_CELL, // 异物 QX_ANALYSIS_AD, // 暗点 QX_ANALYSIS_Scratch, // 划伤 QX_ANALYSIS_LINE, // 线类 QX_ANALYSIS_MTX, // MTX QX_ANALYSIS_ALL, // MTX&异物 QX_ANALYSIS_COUNT, }; // 缺陷项对应在参数中的名称 static const std::string QX_ANALYSIS_NAME_Names[] = { "POL_Cell", "AD", "Scratch", "LINE", "MTX", "POL_Cell&MTX"}; // 预处理参数 struct Pre_Analysisy_Param { float fAreaMin = 0; // 面积最小值 float fHJMin = 0; // 灰度最小值 float fLenMin = 0; // 长度最小值 float fMdMin = 0; // 密度最小值 }; // 记录缺陷信息 struct QX_Info { std::string camera_name; std::string channel_name; float area; // 面积 float energy; // 能量 float hj; // 灰阶 float length; // 长度 float density; // 密度 cv::Point2f plocatin_mm; // 位置,mm cv::Point2f plocatin_pixel; // 位置 像素 cv::Point2f pLocation_Product_mm; // 位置,mm,相对于产品的。位置 int blobIdx; // blob idx; int result; float fmindis; int nmindis_BlobIdx; cv::Point mindis_locatin_pixel; // 位置 像素 int nstatus; int nqx_type; float tem_dis; float tem_dis_idx; cv::Rect roi; cv::Rect product_roi; QX_Info() { Init(); } void Init() { area = 0; energy = 0; hj = 0; length = 0; plocatin_mm = cv::Point2f(0, 0); plocatin_pixel = cv::Point(0, 0); blobIdx = 0; result = 0; fmindis = 0; mindis_locatin_pixel = cv::Point(0, 0); pLocation_Product_mm = cv::Point2f(0, 0); nstatus = 0; nqx_type = 0; nmindis_BlobIdx = 0; density = 0; camera_name = ""; channel_name = ""; tem_dis = 0; tem_dis_idx = 0; roi = cv::Rect(0, 0, 0, 0); product_roi = cv::Rect(0, 0, 0, 0); } void print(std::string str) { printf("%s blobIdx %d,result %d area %f energy %f hj %f length %f md %f x %f y %f x %f y %f \n", str.c_str(), blobIdx, result, area, energy, hj, length, density, plocatin_mm.x, plocatin_mm.y, plocatin_pixel.x, plocatin_pixel.y); printf("%s blobIdx %d,fmindis %f mindis_locatin_pixel x %d y %d \n", str.c_str(), blobIdx, fmindis, mindis_locatin_pixel.x, mindis_locatin_pixel.y); } std::string GetInfo() { char buffer[64]; sprintf(buffer, "idx:%d A:%0.2f,HJ:%0.2f,Len:%0.2f,md:%0.2f,dis:%0.2f", blobIdx, area, hj, length, density,tem_dis); std::string str123 = buffer; return str123; } }; struct QX_ALL_List { std::vector qxList; QX_ALL_List() { Init(); } void Init() { qxList.erase(qxList.begin(), qxList.end()); qxList.clear(); // config.Init(); } }; struct QX_channel_List { std::shared_ptr pChannelDetlog; std::shared_ptr pChannelDetlog2; std::string channel_name; std::vector qxList; QX_channel_List() { Init(); } void Init() { qxList.erase(qxList.begin(), qxList.end()); qxList.clear(); channel_name = ""; // config.Init(); } void Initstatus() { for (int i = 0; i < qxList.size(); i++) { qxList[i].nqx_type = 0; qxList[i].nstatus = 0; qxList[i].tem_dis = 0; qxList[i].tem_dis_idx = -1; } } bool preDet(int i, Pre_Analysisy_Param param, std::string &strinfo) { strinfo = ""; bool return_value = true; if (qxList[i].area < param.fAreaMin) { return_value = false; strinfo += "A:false"; } if (qxList[i].hj < param.fHJMin) { return_value = false; strinfo += "HJ:false"; } if (qxList[i].density < param.fMdMin) { return_value = false; strinfo += "md:false"; } if (qxList[i].length < param.fLenMin) { return_value = false; strinfo += "Len:false"; } return return_value; } void claDis() { for (int i = 0; i < qxList.size(); i++) { if (qxList[i].nstatus != 1) { continue; } double mindis = 99999999999; int mindix = -1; for (int j = 0; j < qxList.size(); j++) { if (i == j || qxList[j].nstatus != 1) { continue; } float dis = CheckUtil::calDis(qxList[i].pLocation_Product_mm, qxList[j].pLocation_Product_mm); if (dis < mindis) { mindis = dis; mindix = j; } } if (mindix != -1) { qxList[i].tem_dis = mindis; qxList[i].tem_dis_idx = mindix; } } } }; struct ALL_Qx_DataList { std::vector channelqxList; ALL_Qx_DataList() { Init(); } void Init() { channelqxList.erase(channelqxList.begin(), channelqxList.end()); channelqxList.clear(); } }; struct QXAnalysis_Config { bool bok; int num; float dis; float len; int hj; float density; float area; float sum_area; QXAnalysis_Config() { Init(); } void Init() { bok = false; num = 0; dis = 0; len = 0; area = 0; hj = 0; sum_area = 0; density = 0; } void print(std::string str) { printf("%s bok %d num %d area %f dis %f len %f hj %d md %f\n", str.c_str(), bok, num, area, dis, len, hj, density); } }; struct ALL_QX_ParamList { std::vector configlsit; ALL_QX_ParamList() { Init(); } void Init() { configlsit.erase(configlsit.begin(), configlsit.end()); configlsit.clear(); // config.Init(); } }; enum QX_ERROR_TYPE_ { QX_ERROR_TYPE_OK, QX_ERROR_TYPE_AREA, QX_ERROR_TYPE_NUM, QX_ERROR_TYPE_DIS, QX_ERROR_TYPE_Len, QX_ERROR_TYPE_NUM_RGB255, }; struct QX_RESULT { std::string camera_name; std::string channel_name; int blobIdx; // blob idx; int error_Type; // 错误原因 int qx_Num; // 缺陷的数量 float mindis; float flen; cv::Point qx_MisDis_point_pixel; // 缺陷 间的最小距离 QX_RESULT() { Init(); } void Init() { blobIdx = -1; error_Type = 0; qx_Num = 0; flen = 0; mindis = 0; qx_MisDis_point_pixel = cv::Point(0, 0); camera_name = ""; channel_name = ""; } void print(std::string str) { printf("%s blobIdx %d error_Type %d qx_Num %d min dis %f flen %f x %d y %d \n", str.c_str(), blobIdx, error_Type, qx_Num, mindis, flen, qx_MisDis_point_pixel.x, qx_MisDis_point_pixel.y); } }; struct QX_Analysis_Result_List { std::vector resultList; QX_Analysis_Result_List() { Init(); } void Init() { resultList.erase(resultList.begin(), resultList.end()); resultList.clear(); // config.Init(); } }; #endif