/* * @Descripttion: * @version: * @Author: sueRimn * @Date: 2022-03-16 17:09:11 * @LastEditors: xiewenji 527774126@qq.com * @LastEditTime: 2025-09-24 17:48:07 */ /***********************************************/ /************ ***************/ /************金佰利检测算法参数定义**************/ /************ **************/ /**********************************************/ #ifndef _ImgCheckConfig_HPP_ #define _ImgCheckConfig_HPP_ #include #include #include // unordered_map #define RESULT_VERSION 31 #define MAX_BLOB_NUM 200 // 输入模型图片尺寸 #define SRCIMG_WIDTH 14200 #define SRCIMG_HEIGHT 10640 #define CHECKIMG_HEIGHT 2000 #define CHECKIMG_WIDTH 4000 #define MASK_IMG_STEP 16 #define MASK_IMG_STARTVALUE 48 // 检测日志 等级 enum DET_LOG_LEVEL_ { DET_LOG_LEVEL_0, // 极简信息 DET_LOG_LEVEL_1, // 包含检测关键信息 DET_LOG_LEVEL_2, // 关键信息+ 一般节点信息 DET_LOG_LEVEL_3, // 详细信息 }; struct VERSION_INFO { int ConfigVersion = 0; int ResultVersion = RESULT_VERSION; int InterfaceVersion = 0; }; // 检测错误代码 enum ERROR_TYPE_ { 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_Line_fangge, // 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 脏污 ERROR_TYPE_Other, // 19 other ERROR_TYPE_Cell_W, // 19 other ERROR_TYPE_Cell_B, // 19 other ERROR_TYPE_LackPol, // 缺失Pol ERROR_TYPE_COUNT, }; extern std::vector QX_Result_Names; extern std::vector QX_Result_Code; // 检测检测参数类型 enum CHECK_CONFIG_TYPE_ { CHECK_CONFIG_Run, // 运行参数 CHECK_CONFIG_Module, // 参数模块 CHECK_CONFIG_COUNT, }; // 输入检测图片的 enum IMG_INPUT_ { IMG_INPUT_SRC, IMG_INPUT_COUNT, }; // 输入检测缺陷小图 enum IMG_OUTPUT_ { IMG_OUTPUT_RESIZE, IMG_OUTPUT_COUNT, }; // 输入图片的状态 enum IN_IMG_Status_ { IN_IMG_Status_Start, IN_IMG_Status_Other, IN_IMG_Status_End, IN_IMG_Status_OneImg, }; // 检测模式 enum DET_MODE_ { DET_MODE_NULL, DET_MODE_EDGE, DET_MODE_MergeImg, DET_MODE_ZF, DET_MODE_YX, DET_MODE_UP, DET_MODE_Det, DET_MODE_MarkLine, DET_MODE_ReJson, }; #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 { int Det_Mode; // 检测模式 int Status; bool bmergeImg; /// 是否合并图片 int camera_ID; // 相机ID int img_id; cv::Mat img; cv::Mat img_B; cv::Mat other_channel_Result_mask; cv::Mat AI_maskImg; // 推理图片 std::string strSnowID; // 相机发古来的雪花码 long getImgTimeMs; // 获取图片的时间点 long readImg_start; long readImg_end; long time_PushIn; long time_sendCheck; long time_startCheck; long time_EndCheck; int imgtype; cv::Rect cutRoi; int ninstruct; // 运行指令 int nlogLevel; // 日志等级 std::string strCameraName; // 相机名称 std::string strImgProductID; // 产品名称 std::string strChannel; // 通道名称 std::string strImgName; // 图片名称 std::string imgstr; std::string strParm_WorkCamName; // 对应的界面参数 的工位相机名称。 ==等价于 相机管理的 CODE int nImgBigIdx; int otherValue; int otherValue_1; std::string resultJson; // 检测结果 json 字符串 bool bDebugsaveImg; // 保存处理图片 std::unordered_map runCommand; // 运行命令 map shareImage() { Init(); } ~shareImage() { } void Init() { if (!img.empty()) { img.release(); } if (!img_B.empty()) { img_B.release(); } if (!other_channel_Result_mask.empty()) { other_channel_Result_mask.release(); } if (!AI_maskImg.empty()) { AI_maskImg.release(); } Det_Mode = 0; Status = 0; nlogLevel = DET_LOG_LEVEL_0; img_id = -1; getImgTimeMs = 0; time_PushIn = 0; time_sendCheck = 0; time_startCheck = 0; time_EndCheck = 0; readImg_start = 0; readImg_end = 0; imgtype = 0; imgstr = ""; strSnowID = ""; camera_ID = 0; strImgName = ""; strCameraName = ""; strImgProductID = ""; strChannel = ""; nImgBigIdx = 0; cutRoi = cv::Rect(0, 0, 0, 0); otherValue = 0; ninstruct = 0; resultJson = ""; strParm_WorkCamName = ""; bDebugsaveImg = false; bmergeImg = false; } void InitImg(int ImgW, int imgH, bool Isgray = true) { if (Isgray) { img = cv::Mat(imgH, ImgW, CV_8UC1); } else { img = cv::Mat(imgH, ImgW, CV_8UC3); } } }; // 检测结果基本信息 struct BasicResult { int img_id; long checkUseTimeMs; // 所有时间 int64_t snowId; // 雪花ID int imgtype; std::string imgstr; std::string strChannel; void Init() { img_id = 0; checkUseTimeMs = 0; snowId = 0; imgtype = 0; imgstr = ""; strChannel = ""; } void copy(BasicResult tem) { this->img_id = tem.img_id; this->checkUseTimeMs = tem.checkUseTimeMs; this->snowId = tem.snowId; this->imgtype = tem.imgtype; this->imgstr = tem.imgstr; this->strChannel = tem.strChannel; } }; struct DetectInfo { int nresult; std::string keyName; std::string keyCode; int num; DetectInfo() { Init(); } void Init() { nresult = 0; num = 0; keyName = ""; keyCode = ""; } void copy(DetectInfo tem) { this->nresult = tem.nresult; this->num = tem.num; this->keyName = tem.keyName; this->keyCode = tem.keyCode; } }; struct QXImageResult { int type; // 缺陷类型 std::string qx_Code; // 缺陷code std::string strTypeName; // 缺陷名称 cv::Mat srcImg; // 缺陷原始图片 cv::Mat resizeImg; // 缺陷缩略图 cv::Mat AI_in_Img; cv::Mat AI_out_img; cv::Rect srcImgroi; // 相对原图的 框坐标; cv::Rect CutImgroi; // 裁剪原图 框坐标; cv::Rect resizeImgroi; // 相对相对小图 框坐标; float x_pixel; // 缺陷坐标 像素 float y_pixel; // 缺陷坐标 像素 float x_mm; // 缺陷坐标 mm float y_mm; // 缺陷坐标 mm int idx; float area; float energy; float hj; float max_v; float len; float fScore; int qx_type; // 缺陷的原因 float minDis_mm; int qx_num; float density; // 密度 QXImageResult() { Init(); } void Init() { if (!srcImg.empty()) { srcImg.release(); } if (!resizeImg.empty()) { resizeImg.release(); } if (!AI_in_Img.empty()) { AI_in_Img.release(); /* code */ } if (!AI_out_img.empty()) { AI_out_img.release(); /* code */ } x_pixel = 0; y_pixel = 0; x_mm = 0; y_mm = 0; type = 0; area = 0; energy = 0; hj = 0; max_v = 0; strTypeName = ""; qx_Code = ""; len = 0; idx = 0; fScore = 0; qx_type = 0; minDis_mm = 0; qx_num = 0; density = 0; srcImgroi = cv::Rect(0, 0, 0, 0); CutImgroi = cv::Rect(0, 0, 0, 0); resizeImgroi = cv::Rect(0, 0, 0, 0); } }; // 结果信息 struct CheckResult { // 原始图片,输入检测的图片 int checkStatus; int nDetStep; // 处理步骤 int nresult; int nProductResult; // 产品结果 int nYS_result; float productWidht_mm; // 产品宽度 毫米 float productHeight_mm; // 产品 高度 毫米 cv::Mat cutSrcimg; cv::Mat resultimg; cv::Mat SrcResultImg; // 结果 cv::Mat resultMaskImg; // AI mask Result std::shared_ptr in_shareImage; // 输入图片信息 DetectInfo defectResultList[ERROR_TYPE_COUNT]; // 缺陷检测结果list BasicResult basicResult; // 基本检测结果信息 std::vector qxImageResult; // 缺陷小图结果 std::vector YS_ImageResult; // 疑似小图结果 std::vector det_LogList; // 检测日志 std::string strResultJson; // 缺陷结果 jason bool bSaveALL; int nflage1; int nflage2; CheckResult() { Init(); } ~CheckResult() { release(); } void Init() { nProductResult = 0; checkStatus = 0; nDetStep = 0; nresult = ERROR_TYPE_OK; nYS_result = ERROR_TYPE_OK; bSaveALL = false; nflage1 = 0; nflage2 = 0; productWidht_mm = 0; productHeight_mm = 0; basicResult.Init(); strResultJson = ""; if (!resultimg.empty()) { resultimg.release(); } if (!cutSrcimg.empty()) { cutSrcimg.release(); } if (!SrcResultImg.empty()) { SrcResultImg.release(); } if (!resultMaskImg.empty()) { resultMaskImg.release(); } for (int i = 0; i < ERROR_TYPE_COUNT; i++) { defectResultList[i].Init(); } std::vector tmp; qxImageResult.swap(tmp); YS_ImageResult.swap(tmp); qxImageResult.erase(qxImageResult.begin(), qxImageResult.end()); YS_ImageResult.erase(YS_ImageResult.begin(), YS_ImageResult.end()); det_LogList.erase(det_LogList.begin(), det_LogList.end()); } void release() { if (!resultimg.empty()) { resultimg.release(); } if (!cutSrcimg.empty()) { cutSrcimg.release(); } if (!SrcResultImg.empty()) { SrcResultImg.release(); } if (!resultMaskImg.empty()) { resultMaskImg.release(); } strResultJson = ""; std::vector tmp; qxImageResult.swap(tmp); YS_ImageResult.swap(tmp); det_LogList.erase(det_LogList.begin(), det_LogList.end()); } }; #endif //_CORELOGICFACTORY_HPP_