From 415952f0bc399294969b7e39b4c836e82ed99a17 Mon Sep 17 00:00:00 2001 From: liusiyang Date: Thu, 15 Oct 2026 22:15:01 +0800 Subject: [PATCH] =?UTF-8?q?update=20=E5=BC=B1=E7=BA=BF=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E5=90=88=E5=B9=B6=E8=BE=B9=E7=BC=98=E6=A8=A1=E5=9E=8B=E7=BB=93?= =?UTF-8?q?=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AlgorithmModule/include/AI_Edge_QX_Det.h | 8 ++- AlgorithmModule/include/ImgCheckAnalysisy.hpp | 2 + AlgorithmModule/src/AI_Edge_QX_Det.cpp | 23 ++++++- AlgorithmModule/src/ImgCheckAnalysisy.cpp | 63 ++++++++++++++++++- 4 files changed, 93 insertions(+), 3 deletions(-) diff --git a/AlgorithmModule/include/AI_Edge_QX_Det.h b/AlgorithmModule/include/AI_Edge_QX_Det.h index 412694c..c8a963c 100644 --- a/AlgorithmModule/include/AI_Edge_QX_Det.h +++ b/AlgorithmModule/include/AI_Edge_QX_Det.h @@ -45,7 +45,13 @@ public: AI_Edge_QX_Det(/* args */); ~AI_Edge_QX_Det(); - int Detect(const cv::Mat &img, cv::Mat &detmask, DetConfig *pDetConfig,std::shared_ptr pdetlog); + /// @brief 边缘缺陷检测,检测结果根据配置参数合并到 mask + /// @param img 检测原图 + /// @param detmask 合并目标 mask(主检测) + /// @param pDetConfig 检测参数 + /// @param pdetlog 日志 + /// @param pDetmask2 可选:第二个合并目标 mask(如弱线检测mask),按与主检测相同规则合并 + int Detect(const cv::Mat &img, cv::Mat &detmask, DetConfig *pDetConfig, std::shared_ptr pdetlog, cv::Mat *pDetmask2 = nullptr); private: int SaveProcessImg(const cv::Mat &inImg, const cv::Mat &outImg, bool isALLzeros, DetConfig *pDetConfig, int idx = 0, int nruntype = 0); diff --git a/AlgorithmModule/include/ImgCheckAnalysisy.hpp b/AlgorithmModule/include/ImgCheckAnalysisy.hpp index 874f9c9..ce868c7 100644 --- a/AlgorithmModule/include/ImgCheckAnalysisy.hpp +++ b/AlgorithmModule/include/ImgCheckAnalysisy.hpp @@ -195,6 +195,8 @@ private: int GetBlob_127cell(); // 获得 RLine_512 blob int GetBlob_RLine_512(); + // 更新 RLine_512 mask 的 blob 行标记(合并边缘检测结果后刷新) + int UpdateBlobHFlag_RLine_512(); // 获得 BQ标签 blob int GetBlob_BQ(); diff --git a/AlgorithmModule/src/AI_Edge_QX_Det.cpp b/AlgorithmModule/src/AI_Edge_QX_Det.cpp index 6b8a6ba..ab44e79 100644 --- a/AlgorithmModule/src/AI_Edge_QX_Det.cpp +++ b/AlgorithmModule/src/AI_Edge_QX_Det.cpp @@ -122,7 +122,7 @@ std::string AI_Edge_QX_Det::GetImgSaveName(int flag) return str_root; } -int AI_Edge_QX_Det::Detect(const cv::Mat &img, cv::Mat &detmask, DetConfig *pDetConfig, std::shared_ptr pdetlog) +int AI_Edge_QX_Det::Detect(const cv::Mat &img, cv::Mat &detmask, DetConfig *pDetConfig, std::shared_ptr pdetlog, cv::Mat *pDetmask2) { static int n_count = 0; int nRuntype = 0; // 0:检测 1:测试。。。。。 @@ -169,6 +169,14 @@ int AI_Edge_QX_Det::Detect(const cv::Mat &img, cv::Mat &detmask, DetConfig *pDet m_pdetlog->AddCheckstr(PrintLevel_2, DET_LOG_LEVEL_3, "AI_Edge_QX_Det ", "nruntype %d %d\n", pDetConfig->pdege_Det_config->bsave_all, pDetConfig->pdege_Det_config->bsave_qx); + // 第二个合并目标(如弱线检测mask):尺寸与主检测mask一致时才参与合并 + bool bMergeDetmask2 = false; + if (pDetmask2 != nullptr && !pDetmask2->empty() && pDetmask2->size() == detmask.size()) + { + bMergeDetmask2 = true; + m_pdetlog->AddCheckstr(PrintLevel_2, DET_LOG_LEVEL_3, "AI_Edge_QX_Det ", "extra detmask merge on %s", pDetConfig->strCamChannel.c_str()); + } + if (bdege || nRuntype != 0) { showImg = img.clone(); @@ -305,14 +313,27 @@ int AI_Edge_QX_Det::Detect(const cv::Mat &img, cv::Mat &detmask, DetConfig *pDet if (pDetConfig->pdege_Det_config->type == Function_Edge_Det::Edge_type_Add) { outMask(smallImg_roi).copyTo(detmask(mask_roi), outMask(smallImg_roi)); + // 第二个合并目标(如弱线检测mask):与主检测mask相同规则合并 + if (bMergeDetmask2) + { + outMask(smallImg_roi).copyTo((*pDetmask2)(mask_roi), outMask(smallImg_roi)); + } } else if (pDetConfig->pdege_Det_config->type == Function_Edge_Det::Edge_type_And) { cv::bitwise_and(detmask(mask_roi), outMask(smallImg_roi), detmask(mask_roi)); + if (bMergeDetmask2) + { + cv::bitwise_and((*pDetmask2)(mask_roi), outMask(smallImg_roi), (*pDetmask2)(mask_roi)); + } } else { outMask(smallImg_roi).copyTo(detmask(mask_roi)); + if (bMergeDetmask2) + { + outMask(smallImg_roi).copyTo((*pDetmask2)(mask_roi)); + } } } } diff --git a/AlgorithmModule/src/ImgCheckAnalysisy.cpp b/AlgorithmModule/src/ImgCheckAnalysisy.cpp index 23779fe..9612f10 100644 --- a/AlgorithmModule/src/ImgCheckAnalysisy.cpp +++ b/AlgorithmModule/src/ImgCheckAnalysisy.cpp @@ -3889,9 +3889,26 @@ int ImgCheckAnalysisy::Edge_Det() // cv::Mat temMask = cv::Mat::zeros(m_TemCheck.temImgList[TEM_IMG_IDX_AImask].size(), CV_8UC1); if (m_pFuntion->function.f_dege_Det.bOpen) { + // 弱线检测(512模型)的mask:与主检测mask一样,根据 f_dege_Det 参数合并边缘检测结果 + cv::Mat *pRLineDetMask = nullptr; + if (m_pFuntion->function.f_RLineDet.bOpen && + m_pFuntion->function.f_RLineDet.bOpen_512 && + m_pImageAllResult->RLine_512_DetAIResult && + !m_pImageAllResult->RLine_512_DetAIResult->AI_MaskImg.empty()) + { + pRLineDetMask = &m_pImageAllResult->RLine_512_DetAIResult->AI_MaskImg; + m_pdetlog->AddCheckstr(PrintLevel_1, DET_LOG_LEVEL_3, strBaseLog, " RLine_512 mask merge enable"); + } + if (m_pFuntion->function.f_dege_Det.bdetUse) { - m_AIEdge_QX_Det.Detect(m_CheckResult_shareP->in_shareImage->img, m_pImageAllResult->qx_DetAIResult->AI_MaskImg, &detconfig, m_pdetlog); + m_AIEdge_QX_Det.Detect(m_CheckResult_shareP->in_shareImage->img, m_pImageAllResult->qx_DetAIResult->AI_MaskImg, &detconfig, m_pdetlog, pRLineDetMask); + + // 合并后刷新弱线mask的blob行标记,保证合并进来的像素参与blob分析 + if (pRLineDetMask != nullptr) + { + UpdateBlobHFlag_RLine_512(); + } } else { @@ -3909,6 +3926,50 @@ int ImgCheckAnalysisy::Edge_Det() return 0; } +// 弱线检测mask合并边缘检测结果后,刷新blob行标记,保证合并进来的像素参与blob分析 +int ImgCheckAnalysisy::UpdateBlobHFlag_RLine_512() +{ + std::shared_ptr pDetAIResult = m_pImageAllResult->RLine_512_DetAIResult; + if (!pDetAIResult || !pDetAIResult->blobDetParam) + { + return 1; + } + unsigned char *imgBlobHFlagData = pDetAIResult->blobDetParam->imgBlobHFlagData; + cv::Mat maskimg = pDetAIResult->AI_MaskImg; + if (imgBlobHFlagData == NULL || maskimg.empty()) + { + return 1; + } + + int nRows = pDetAIResult->blobDetParam->ndatalen; + if (nRows > maskimg.rows) + { + nRows = maskimg.rows; + } + int width = maskimg.cols; + int nSetNum = 0; + for (int y = 0; y < nRows; y++) + { + if (imgBlobHFlagData[y] != 0) + { + continue; + } + const unsigned char *p = maskimg.ptr(y); + for (int x = 0; x < width; x++) + { + if (p[x] != 0) + { + imgBlobHFlagData[y] = 1; + nSetNum++; + break; + } + } + } + m_pdetlog->AddCheckstr(PrintLevel_1, DET_LOG_LEVEL_3, "UpdateBlobHFlag_RLine_512", " RLine_512 blob HFlag update rows %d", nSetNum); + + return 0; +} + int ImgCheckAnalysisy::DrawResult_Step_1() { m_pdetlog->AddCheckstr(PrintLevel_0, "DrawResult_Step_1", "=======start");