From 92c603b2a60c3068c32db65ac543c893703b6d1b Mon Sep 17 00:00:00 2001 From: liusiyang Date: Thu, 10 Sep 2026 17:34:52 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E6=94=AF=E6=9E=B6=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E7=A7=BB=E8=87=B3=E6=A3=80=E6=B5=8B=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AIEngineModule/src/AI_Factory.cpp | 12 +- AlgorithmModule/src/ImgCheckAnalysisy.cpp | 22 +++- ConfigModule/include/CheckConfigDefine.h | 119 +++++++++---------- ConfigModule/src/JsonConfig.cpp | 133 +++++++++++----------- 4 files changed, 152 insertions(+), 134 deletions(-) diff --git a/AIEngineModule/src/AI_Factory.cpp b/AIEngineModule/src/AI_Factory.cpp index e7c9f1e..bcb46a8 100644 --- a/AIEngineModule/src/AI_Factory.cpp +++ b/AIEngineModule/src/AI_Factory.cpp @@ -43,7 +43,7 @@ int AIFactory::InitALLAIModle(GPU_Config gupconfig) AIModel_Base::AIModelRun_Config edge_config; edge_config.gpuconfig.copy(gupconfig); edge_config.strPath = "/home/aidlux/BOE/UseModel_ZB/BM/DefectLight.engine"; - edge_config.strName = "CA_Det"; + edge_config.strName = "Defect"; edge_config.inputType = AIModel_Base::Input_CHW; edge_config.Stream_num = 2; Defect->Init(edge_config); @@ -53,9 +53,9 @@ int AIFactory::InitALLAIModle(GPU_Config gupconfig) Class = AIModel_Base::GetInstance(); AIModel_Base::AIModelRun_Config jbl_config; jbl_config.gpuconfig.copy(gupconfig); - jbl_config.strPath = "/home/aidlux/BOE/UseModel_ZB/Class_10.engine"; + jbl_config.strPath = "/home/aidlux/BOE/UseModel_ZB/BM/Class.engine"; jbl_config.inputType = AIModel_Base::Input_CHW; - jbl_config.strName = "CA_Class"; + jbl_config.strName = "Class"; jbl_config.IsClass = true; Class->Init(jbl_config); } @@ -65,7 +65,7 @@ int AIFactory::InitALLAIModle(GPU_Config gupconfig) AIModel_Base::AIModelRun_Config edge_config; edge_config.gpuconfig.copy(gupconfig); edge_config.strPath = "/home/aidlux/BOE/UseModel_ZB/BM/BadLabel.engine"; - edge_config.strName = "TA_Det"; + edge_config.strName = "Tag_Loc"; edge_config.inputType = AIModel_Base::Input_CHW; edge_config.Stream_num = 2; Tag_Loc->Init(edge_config); @@ -76,7 +76,7 @@ int AIFactory::InitALLAIModle(GPU_Config gupconfig) AIModel_Base::AIModelRun_Config edge_config; edge_config.gpuconfig.copy(gupconfig); edge_config.strPath = "/home/aidlux/BOE/UseModel_ZB/BM/ProductLoc.engine"; - edge_config.strName = "Align"; + edge_config.strName = "Align_Outer"; edge_config.inputType = AIModel_Base::Input_CHW; Align_Outer->Init(edge_config); } @@ -86,7 +86,7 @@ int AIFactory::InitALLAIModle(GPU_Config gupconfig) AIModel_Base::AIModelRun_Config edge_config; edge_config.gpuconfig.copy(gupconfig); edge_config.strPath = "/home/aidlux/BOE/UseModel_ZB/BM/ClampLoc.engine"; - edge_config.strName = "Mark"; + edge_config.strName = "Align_Inner"; edge_config.inputType = AIModel_Base::Input_CHW; Align_Inner->Init(edge_config); } diff --git a/AlgorithmModule/src/ImgCheckAnalysisy.cpp b/AlgorithmModule/src/ImgCheckAnalysisy.cpp index c266574..60efa66 100644 --- a/AlgorithmModule/src/ImgCheckAnalysisy.cpp +++ b/AlgorithmModule/src/ImgCheckAnalysisy.cpp @@ -454,6 +454,22 @@ int ImgCheckAnalysisy::CheckRun() } long time_edge_s = CheckUtil::getcurTime(); + m_pFuntion = GetChannelFuntion(m_strCurDetChannel); + int nfunction = 0; + if (m_pFuntion != NULL) + { + m_pdetlog->AddCheckstr(PrintLevel_0, "Detect function", "%s", + m_pFuntion->GetInfo("").c_str()); + } + else + { + nfunction = 1; + m_pdetlog->AddCheckstr(PrintLevel_0, "Error", "m_pFuntion is NULL"); + m_nErrorCode = 22; + m_nCheckResultErrorCode = m_nErrorCode; + return m_nErrorCode; + } + /*AI 边缘定位(内外边缘)*/ // 模型定位内外边缘 int reedge = AI_Edge(m_CheckResult_shareP->in_shareImage->img, m_outer_rroi, m_inner_rroi, m_tag_roiList); @@ -503,7 +519,7 @@ int ImgCheckAnalysisy::CheckRun() /* 检测支架偏移 */ { - Base_Function_Support_Det &supportDet = m_pbaseCheckFunction->supportDet; + Function_Support_Det &supportDet = m_pFuntion->function.f_supportDet; if (supportDet.bOpen && supportDet.supportRect.size.width > 0 && supportDet.supportRect.size.height > 0) { cv::RotatedRect &inner = m_inner_rroi; @@ -2050,7 +2066,7 @@ int ImgCheckAnalysisy::AI_Edge(const cv::Mat &img, cv::RotatedRect &outerRoi, cv /*使用m_pEdge_Align_Result->bigmask检测把手是否缺失*/ // 截取把手大致区域 - RotatedRect tpl_handle_rroi = m_pbaseCheckFunction->supportDet.handleRect; + RotatedRect tpl_handle_rroi = m_pFuntion->function.f_supportDet.handleRect; Rect handle_rect = Rect(tpl_handle_rroi.boundingRect().x, 0, tpl_handle_rroi.boundingRect().width, m_pEdge_Align_Result->bigmask.rows); Mat handle_roi = m_pEdge_Align_Result->bigmask(handle_rect & Rect(0, 0, m_pEdge_Align_Result->bigmask.cols, m_pEdge_Align_Result->bigmask.rows)).clone(); @@ -2062,7 +2078,7 @@ int ImgCheckAnalysisy::AI_Edge(const cv::Mat &img, cv::RotatedRect &outerRoi, cv // handle_roi找到最大连通域,和tpl_handle_rroi做面积形状比较,差异过大判为把手缺失,添加到缺陷并NG { - Base_Function_Support_Det &handleDet = m_pbaseCheckFunction->supportDet; + Function_Support_Det &handleDet = m_pFuntion->function.f_supportDet; if (handleDet.bOpen && tpl_handle_rroi.size.width > 0 && tpl_handle_rroi.size.height > 0 && !handle_roi.empty()) { std::vector> handle_contours; diff --git a/ConfigModule/include/CheckConfigDefine.h b/ConfigModule/include/CheckConfigDefine.h index 97f1cb3..74c476e 100644 --- a/ConfigModule/include/CheckConfigDefine.h +++ b/ConfigModule/include/CheckConfigDefine.h @@ -932,6 +932,60 @@ struct Function_Image_Align return str123; } }; +// 支架检测 +struct Function_Support_Det +{ + bool bOpen; // 是否开启 + std::vector supportRegion; + cv::RotatedRect supportRect; + float x_offset; + float y_offset; + float r_offset; + std::vector handleRegion; + cv::RotatedRect handleRect; + + Function_Support_Det () + { + Init(); + } + + void Init() + { + bOpen = false; + supportRegion.clear(); + supportRect = cv::RotatedRect(); + x_offset = 0; + y_offset = 0; + r_offset = 0; + handleRegion.clear(); + handleRect = cv::RotatedRect(); + } + void copy(Function_Support_Det tem) + { + this->bOpen = tem.bOpen; + this->supportRegion.assign(tem.supportRegion.begin(), tem.supportRegion.end()); + this->supportRect = tem.supportRect; + this->x_offset = tem.x_offset; + this->y_offset = tem.y_offset; + this->r_offset = tem.r_offset; + this->handleRegion.assign(tem.handleRegion.begin(), tem.handleRegion.end()); + this->handleRect = tem.handleRect; + } + void print(std::string str) + { + printf("%s>>bOpen %d x_offset %f y_offset %f r_offset %f\n", str.c_str(), + bOpen, x_offset, y_offset, r_offset); + } + std::string GetInfo(std::string str) + { + char buffer[256]; + sprintf(buffer, "%s>>bOpen %d x_offset %f y_offset %f r_offset %f\n", str.c_str(), + bOpen, x_offset, y_offset, r_offset); + std::string str123 = buffer; + return str123; + } + +}; // 检测功能 struct CheckFunction @@ -942,6 +996,7 @@ struct CheckFunction Function_ShieldRegion f_ShieldRegion; Function_EdgeROI f_EdgeROI; Function_Image_Align f_Image_Align; // 图片特征对齐 + Function_Support_Det f_supportDet; CheckFunction() { Init(); @@ -954,6 +1009,7 @@ struct CheckFunction f_ShieldRegion.Init(); f_EdgeROI.Init(); f_Image_Align.Init(); + f_supportDet.Init(); } void copy(CheckFunction tem) { @@ -964,6 +1020,7 @@ struct CheckFunction this->f_ShieldRegion.copy(tem.f_ShieldRegion); this->f_EdgeROI.copy(tem.f_EdgeROI); this->f_Image_Align.copy(tem.f_Image_Align); + this->f_supportDet.copy(tem.f_supportDet); } void print(std::string str) { @@ -974,6 +1031,7 @@ struct CheckFunction f_ShieldRegion.print("ShieldRegion"); f_EdgeROI.print("EdgeROI"); f_Image_Align.print("Image_Align"); + f_supportDet.print("supportDet"); } std::string GetInfo(std::string str) { @@ -985,9 +1043,11 @@ struct CheckFunction str123 += f_ShieldRegion.GetInfo("ShieldRegion"); str123 += f_EdgeROI.GetInfo("EdgeROI"); str123 += f_Image_Align.GetInfo("Image_Align"); + str123 += f_supportDet.GetInfo("supportDet"); return str123; } }; + // 单通道检测功能 struct ChannelCheckFunction { @@ -1302,60 +1362,6 @@ struct Base_Function_Edge_Det } }; -// 支架检测 -struct Base_Function_Support_Det -{ - bool bOpen; // 是否开启 - std::vector supportRegion; - cv::RotatedRect supportRect; - float x_offset; - float y_offset; - float r_offset; - std::vector handleRegion; - cv::RotatedRect handleRect; - - Base_Function_Support_Det() - { - Init(); - } - - void Init() - { - bOpen = false; - supportRegion.clear(); - supportRect = cv::RotatedRect(); - x_offset = 0; - y_offset = 0; - r_offset = 0; - handleRegion.clear(); - handleRect = cv::RotatedRect(); - } - void copy(Base_Function_Support_Det tem) - { - this->bOpen = tem.bOpen; - this->supportRegion.assign(tem.supportRegion.begin(), tem.supportRegion.end()); - this->supportRect = tem.supportRect; - this->x_offset = tem.x_offset; - this->y_offset = tem.y_offset; - this->r_offset = tem.r_offset; - this->handleRegion.assign(tem.handleRegion.begin(), tem.handleRegion.end()); - this->handleRect = tem.handleRect; - } - void print(std::string str) - { - printf("%s>>bOpen %d x_offset %f y_offset %f r_offset %f\n", str.c_str(), - bOpen, x_offset, y_offset, r_offset); - } - std::string GetInfo(std::string str) - { - char buffer[256]; - sprintf(buffer, "%s>>bOpen %d x_offset %f y_offset %f r_offset %f\n", str.c_str(), - bOpen, x_offset, y_offset, r_offset); - std::string str123 = buffer; - return str123; - } - -}; // 基础检测功能 struct BaseCheckFunction { @@ -1363,7 +1369,6 @@ struct BaseCheckFunction Base_Function_Edge_Det edgeDet; Base_Function_SaveImg saveImg; Base_Function_BigNG bigNG; - Base_Function_Support_Det supportDet; BaseCheckFunction() { @@ -1375,7 +1380,6 @@ struct BaseCheckFunction edgeDet.Init(); saveImg.Init(); bigNG.Init(); - supportDet.Init(); } void copy(BaseCheckFunction tem) { @@ -1383,7 +1387,6 @@ struct BaseCheckFunction this->edgeDet.copy(tem.edgeDet); this->saveImg.copy(tem.saveImg); this->bigNG.copy(tem.bigNG); - this->supportDet.copy(tem.supportDet); } void print(std::string str) { @@ -1392,7 +1395,6 @@ struct BaseCheckFunction edgeDet.print("edgeDet"); saveImg.print("saveImg"); bigNG.print("bigNG"); - supportDet.print("supportDet"); } std::string GetInfo(std::string str) { @@ -1401,7 +1403,6 @@ struct BaseCheckFunction str123 += edgeDet.GetInfo("edgeDet"); str123 += saveImg.GetInfo("saveImg"); str123 += bigNG.GetInfo("bigNG"); - str123 += supportDet.GetInfo("supportDet"); // str123 += "\n"; return str123; } diff --git a/ConfigModule/src/JsonConfig.cpp b/ConfigModule/src/JsonConfig.cpp index 8450518..bcdba98 100644 --- a/ConfigModule/src/JsonConfig.cpp +++ b/ConfigModule/src/JsonConfig.cpp @@ -410,7 +410,73 @@ int ChannelFuntonConfigJson::GetFunction(Json::Value value, CheckFunction &funct { std::string strCode = value[i]["itemCode"].asString(); - // std::cout << strCode << std::endl; + // std::cout << strCode << std::endl; + // 支架偏移缺失检测 + if ("Support_QX_Detect" == strCode) + { + auto value_f = value[i]; + // std::cout << value_f << std::endl; + function.f_supportDet.bOpen = value_f["isOpen"].asBool(); + if (function.f_supportDet.bOpen) + { + // 支架参数 + { + auto value_region = value_f["form"]["support_param"]["support_region"]; + if (value_region.isArray()) + { + for (int idx = 0; idx < value_region.size(); idx++) + { + cv::Point p; + p.x = value_region[idx][0].asInt(); + p.y = value_region[idx][1].asInt(); + + function.f_supportDet.supportRegion.emplace_back(p); + } + if (function.f_supportDet.supportRegion.size() > 0) + { + function.f_supportDet.supportRect = minAreaRect(function.f_supportDet.supportRegion); + } + } + } + if (value_f["form"]["support_param"]["x_offset"]) + { + function.f_supportDet.x_offset = value_f["form"]["support_param"]["x_offset"].asFloat(); + } + if (value_f["form"]["support_param"]["y_offset"]) + { + function.f_supportDet.y_offset = value_f["form"]["support_param"]["y_offset"].asFloat(); + } + if (value_f["form"]["support_param"]["r_offset"]) + { + function.f_supportDet.r_offset = value_f["form"]["support_param"]["r_offset"].asFloat(); + } + + // 把手参数 + { + auto value_region = value_f["form"]["handle_param"]["handle_region"]; + if (value_region.isArray()) + { + for (int idx = 0; idx < value_region.size(); idx++) + { + cv::Point p; + p.x = value_region[idx][0].asInt(); + p.y = value_region[idx][1].asInt(); + + function.f_supportDet.handleRegion.emplace_back(p); + } + if (function.f_supportDet.handleRegion.size() > 0) + { + function.f_supportDet.handleRect = minAreaRect(function.f_supportDet.handleRegion); + } + } + } + } + else + { + function.f_supportDet.Init(); + } + } + // 大缺陷检测 if ("BigQX_Detect" == strCode) { @@ -849,71 +915,6 @@ int BaseFuntonConfigJson::GetFunction(Json::Value value) _config.markLine.Init(); } } - if ("Support_QX_Detect" == strCode) - { - auto value_f = value; - // std::cout << value_f << std::endl; - // getchar(); - _config.supportDet.bOpen = value_f["isOpen"].asBool(); - if (_config.supportDet.bOpen) - { - // 支架参数 - { - auto value_region = value_f["form"]["support_param"]["support_region"]; - if (value_region.isArray()) - { - for (int idx = 0; idx < value_region.size(); idx++) - { - cv::Point p; - p.x = value_region[idx][0].asInt(); - p.y = value_region[idx][1].asInt(); - - _config.supportDet.supportRegion.emplace_back(p); - } - if (_config.supportDet.supportRegion.size() > 0) - { - _config.supportDet.supportRect = minAreaRect(_config.supportDet.supportRegion); - } - } - } - if (value_f["form"]["support_param"]["x_offset"]) - { - _config.supportDet.x_offset = value_f["form"]["support_param"]["x_offset"].asFloat(); - } - if (value_f["form"]["support_param"]["y_offset"]) - { - _config.supportDet.y_offset = value_f["form"]["support_param"]["y_offset"].asFloat(); - } - if (value_f["form"]["support_param"]["r_offset"]) - { - _config.supportDet.r_offset = value_f["form"]["support_param"]["r_offset"].asFloat(); - } - - // 把手参数 - { - auto value_region = value_f["form"]["handle_param"]["handle_region"]; - if (value_region.isArray()) - { - for (int idx = 0; idx < value_region.size(); idx++) - { - cv::Point p; - p.x = value_region[idx][0].asInt(); - p.y = value_region[idx][1].asInt(); - - _config.supportDet.handleRegion.emplace_back(p); - } - if (_config.supportDet.handleRegion.size() > 0) - { - _config.supportDet.handleRect = minAreaRect(_config.supportDet.handleRegion); - } - } - } - } - else - { - _config.supportDet.Init(); - } - } if ("Det_Image_Save" == strCode) { auto value_f = value;