From a0c5684f11c0c51697f7bbc84cee478d2d10231b Mon Sep 17 00:00:00 2001 From: liusiyang Date: Fri, 8 May 2026 14:05:32 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E6=B7=BB=E5=8A=A0=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E5=B1=8F=E8=94=BD(=E4=BC=A0=E7=BB=9F=E7=AE=97=E6=B3=95)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../include/CameraCheckAnalysisy.hpp | 3 + AlgorithmModule/include/ImageDetConfig.h | 9 ++ AlgorithmModule/src/CameraCheckAnalysisy.cpp | 100 ++++++++++++++++++ AlgorithmModule/src/ImageResultJudge.cpp | 1 - ConfigModule/include/CheckConfigDefine.h | 1 + 5 files changed, 113 insertions(+), 1 deletion(-) diff --git a/AlgorithmModule/include/CameraCheckAnalysisy.hpp b/AlgorithmModule/include/CameraCheckAnalysisy.hpp index 3a3f1ee..4a14680 100644 --- a/AlgorithmModule/include/CameraCheckAnalysisy.hpp +++ b/AlgorithmModule/include/CameraCheckAnalysisy.hpp @@ -91,6 +91,9 @@ private: // 预处理 字符检测 int preDet_ZF(const cv::Mat &L255CutImg, std::shared_ptr L255); + // 预处理 标签检测 + int preDet_BQ(const cv::Mat &L255CutImg, std::shared_ptr L255); + // 边缘处理 int ImgEdge(cv::Mat img, cv::Mat &detMaskImg, cv::Rect &roi, int productIdx); diff --git a/AlgorithmModule/include/ImageDetConfig.h b/AlgorithmModule/include/ImageDetConfig.h index 8c5632c..d45b670 100644 --- a/AlgorithmModule/include/ImageDetConfig.h +++ b/AlgorithmModule/include/ImageDetConfig.h @@ -340,6 +340,13 @@ struct ZF_Result std::vector pZF_roiList; // 字符的区域 std::vector ZF_centerPoint; // 字符的中心点位置 }; +struct BQ_Result +{ + int nresult = 1; + bool bShield_BQ = false; // 是否屏蔽标签 + std::vector pBQ_roiList; // 标签的区域 + std::vector BQ_centerPoint; // 标签的中心点位置 +}; struct CameraBaseResult { enum ImageDet_Status @@ -352,6 +359,7 @@ struct CameraBaseResult std::shared_ptr pEdgeDetResult; // 边缘检测结果 std::shared_ptr pMarkLineResult; // MarkLine检测结果 std::shared_ptr pZF_Result; // zf 检测结果 + std::shared_ptr pBQ_Result; // bq 检测结果 ImageDet_Status UpImg_Status = ImageDet_Status_None; // Up 画面 ImageDet_Status DPImg_Status = ImageDet_Status_None; // DP 画面 @@ -408,6 +416,7 @@ struct ImageDetResult int Yx_result; // 异显检测状态 float fUP_IOU; // UP 画面 使用的 iou std::shared_ptr> pZF_roiList; // 字符的区域 + std::shared_ptr> pBQ_roiList; // 标签的区域 std::shared_ptr pOneImgDetResult; // 单图检测结果 std::shared_ptr pBaseImgCheckResult; ImageDetResult() diff --git a/AlgorithmModule/src/CameraCheckAnalysisy.cpp b/AlgorithmModule/src/CameraCheckAnalysisy.cpp index 321541f..7b3c8dd 100644 --- a/AlgorithmModule/src/CameraCheckAnalysisy.cpp +++ b/AlgorithmModule/src/CameraCheckAnalysisy.cpp @@ -157,6 +157,13 @@ int CameraCheckAnalysisy::Detect_Pre() } long te = CheckUtil::getcurTime(); m_pdetlog->AddCheckstr(PrintLevel_0, "Detect_Pre", "==================End time %ld ms ", te - ts); + + re = preDet_BQ(L255CutImg, L255); + if (re != 0) + { + m_pdetlog->AddCheckstr(PrintLevel_1, "Detect_Pre", "%s --preDet_BQ error ", strBasic.c_str()); + } + // getchar(); // return 1; @@ -564,6 +571,40 @@ int CameraCheckAnalysisy::Det_MarkLine(const cv::Mat &L255CutImg, std::shared_pt return 0; } +int BQ_Det(cv::Mat detimg, shared_ptr pBQ_Result) +{ + cv::resize(detimg, detimg, cv::Size(), 0.1, 0.1); + cv::Mat detimg_bin; + cv::GaussianBlur(detimg, detimg, cv::Size(3, 3), 0); + cv::threshold(detimg, detimg_bin, 25, 255, cv::THRESH_BINARY_INV); + vector> contours; + cv::Rect result_roi; + findContours(detimg_bin, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE); + // 找到最大轮廓 + double max_area = 0; + int max_contour_index = 0; + for (int i = 0; i < contours.size(); i++) + { + double area = contourArea(contours[i]); + if (area > max_area) + { + max_area = area; + max_contour_index = i; + } + } + if (max_contour_index < 0) + { + cerr << "No contours found!" << endl; + return 7; + } + cv::Rect r_rect = boundingRect(contours[max_contour_index]); + cv::Rect rect(r_rect.x*10, r_rect.y*10, r_rect.width*10, r_rect.height*10); + if (max_contour_index >= 0) + { + pBQ_Result->pBQ_roiList.push_back(rect); + } + return 0; +} int CameraCheckAnalysisy::preDet_ZF(const cv::Mat &L255CutImg, std::shared_ptr L255) { long ts = CheckUtil::getcurTime(); @@ -637,6 +678,65 @@ int CameraCheckAnalysisy::preDet_ZF(const cv::Mat &L255CutImg, std::shared_ptrAddCheckstr(PrintLevel_1, "preDet_ZF", "==================End zf num %ld re = %d time %ld ms ", m_pCheck_Result->cameraBaseResult->pZF_Result->pZF_roiList.size(), re, te - ts); return 0; } +int CameraCheckAnalysisy::preDet_BQ(const cv::Mat &L255CutImg, std::shared_ptr L255) +{ + long ts = CheckUtil::getcurTime(); + m_pCheck_Result->cameraBaseResult->pBQ_Result = std::make_shared(); + m_pCheck_Result->cameraBaseResult->pBQ_Result->bShield_BQ = m_AnalysisyConfig.commonCheckConfig.baseConfig.bShield_BQ; + + cv::Rect Det_CropRoi = m_pCheck_Result->cameraBaseResult->pEdgeDetResult->cutRoi; + + cv::Mat detimg = L255CutImg; + int re = BQ_Det(detimg, m_pCheck_Result->cameraBaseResult->pBQ_Result); + // 屏蔽标签 + { + m_pdetlog->AddCheckstr(PrintLevel_2, "preDet_BQ", "shieldBQ is Open"); + cv::Mat detImg_mask = m_pCheck_Result->cameraBaseResult->pEdgeDetResult->shieldMask; + for (int i = 0; i < m_pCheck_Result->cameraBaseResult->pBQ_Result->pBQ_roiList.size(); i++) + { + cv::Rect boundingRect = m_pCheck_Result->cameraBaseResult->pBQ_Result->pBQ_roiList.at(i); + boundingRect.x -= 50; + boundingRect.y -= 50; + boundingRect.width += 100; + boundingRect.height += 100; + if(CheckUtil::JudgRect(boundingRect, detimg.cols, detimg.rows)) + detImg_mask(boundingRect).setTo(255); + else + m_pdetlog->AddCheckstr(PrintLevel_2, "preDet_BQ", "detImg_mask fail !!!"); + // cv::imwrite("BQ_sheildImg.png", m_pCheck_Result->cameraBaseResult->pEdgeDetResult->shieldMask); + } + if (L255->result->in_shareImage->bDebugsaveImg) + { + // cv::imwrite("sheildImg.png", m_pCheck_Result->cameraBaseResult->pEdgeDetResult->shieldMask); + } + } + std::shared_ptr pBQ_Result = m_pCheck_Result->cameraBaseResult->pBQ_Result; // BQ 检测结果 + pBQ_Result->BQ_centerPoint.erase(pBQ_Result->BQ_centerPoint.begin(), pBQ_Result->BQ_centerPoint.end()); + for (int i = 0; i < pBQ_Result->pBQ_roiList.size(); i++) + { + // 获取当前轮廓的边界矩形 + cv::Rect boundingRect = pBQ_Result->pBQ_roiList.at(i); + cv::Point p; + p.x = boundingRect.x + boundingRect.width * 0.5f; + p.y = boundingRect.y + boundingRect.height * 0.5f; + // printf("--- bq %d %d %d %d \n", boundingRect.x, boundingRect.y, boundingRect.width, boundingRect.height); + pBQ_Result->BQ_centerPoint.push_back(p); + } + if (L255->result->in_shareImage->bDebugsaveImg) + { + cv::Mat showimg = detimg.clone(); + for (int i = 0; i < m_pCheck_Result->cameraBaseResult->pBQ_Result->pBQ_roiList.size(); i++) + { + cv::Rect boundingRect = m_pCheck_Result->cameraBaseResult->pBQ_Result->pBQ_roiList.at(i); + cv::rectangle(showimg, boundingRect, cv::Scalar(200), 5); + } + cv::imwrite("bq_result.png", showimg); + } + m_pCheck_Result->cameraBaseResult->pBQ_Result->nresult = 0; + long te = CheckUtil::getcurTime(); + m_pdetlog->AddCheckstr(PrintLevel_1, "preDet_BQ", "==================End bq num %ld re = %d time %ld ms ", m_pCheck_Result->cameraBaseResult->pBQ_Result->pBQ_roiList.size(), re, te - ts); + return 0; +} int CameraCheckAnalysisy::Init(std::string strcameraName) { m_strcameraName = strcameraName; diff --git a/AlgorithmModule/src/ImageResultJudge.cpp b/AlgorithmModule/src/ImageResultJudge.cpp index 0301b80..0cc25cd 100644 --- a/AlgorithmModule/src/ImageResultJudge.cpp +++ b/AlgorithmModule/src/ImageResultJudge.cpp @@ -1274,7 +1274,6 @@ int ImageResultJudge::ConfigTypeToResultType(int nconfigType) // 如果描述没有配置,用默认值 if(!bdesc) { - int resultError_type = ERROR_TYPE_OK; switch (nconfigType) { case CONFIG_QX_NAME_ok_yisi: diff --git a/ConfigModule/include/CheckConfigDefine.h b/ConfigModule/include/CheckConfigDefine.h index e37f825..bf540fe 100644 --- a/ConfigModule/include/CheckConfigDefine.h +++ b/ConfigModule/include/CheckConfigDefine.h @@ -443,6 +443,7 @@ struct BasicConfig int height_max; // 20231122xls-add bool bDrawShieldRoi; // 绘制屏蔽区域 bool bShield_ZF; // 屏蔽字符区域,不检测 + bool bShield_BQ; // 屏蔽标签区域,不检测 bool bDrawPreRoi; // 绘制弱化区域 float fUP_IOU; bool bCal_ImageScale; // 是否自动计算成像精度