From f1b4ee142b56237f3443d0b0bac2f3955062e0e5 Mon Sep 17 00:00:00 2001 From: xiewenji <527774126@qq.com> Date: Mon, 1 Dec 2025 11:19:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96NG=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Down_Det/src/Down_Detect.cpp | 16 ++++++++++------ Side_Det/src/Side_Detect.cpp | 4 ++++ TOP_Det/src/Top_Detect.cpp | 34 +++++++++++++++++++--------------- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/Down_Det/src/Down_Detect.cpp b/Down_Det/src/Down_Detect.cpp index 97ba997..b50ecef 100644 --- a/Down_Det/src/Down_Detect.cpp +++ b/Down_Det/src/Down_Detect.cpp @@ -87,7 +87,7 @@ int Down_Detect::CheckRun() t1 = CheckUtil::getcurTime(); CheckImgInit(); cv::Mat detimg = DetImgInfo_shareP->img; - //准备结果图 + // 准备结果图 cv::resize(detimg.clone(), m_CheckResult_shareP->resultImg, cv::Size(800, 600)); if (detimg.empty()) { @@ -115,12 +115,16 @@ int Down_Detect::CheckRun() re = ImgAlinRotate(detimg, AlignImg); if (0 != re) { + // 失败NG + m_CheckResult_shareP->nresult = 1; return re; } // 缺陷检测 re = DetectImg(AlignImg); if (0 != re) { + // 失败NG + m_CheckResult_shareP->nresult = 1; return re; } t2 = CheckUtil::getcurTime(); @@ -309,15 +313,15 @@ int Down_Detect::Draw(const cv::Mat &img, cv::Mat &resultimg) // int x = center.x - w / 2; // int y = center.y - h / 2; - + // // 确保裁剪区域不超出图像边界 // x = std::max(0, x); // y = std::max(0, y); // x = std::min(x, img.cols - w); // y = std::min(y, img.rows - h); - + // // 创建裁剪区域 - // cv::Rect cropRoi(x, y, w, h); + // cv::Rect cropRoi(x, y, w, h); // resultimg = resultimg(cropRoi).clone(); // cv::polylines(resultimg, m_CheckBaseConfig->pointArry, true, cv::Scalar(0, 255, 0), 2); @@ -488,7 +492,7 @@ int Down_Detect::ImgAlinRotate(const cv::Mat &img, cv::Mat &alignImg) return 1; } - //判断尺寸 + // 判断尺寸 int w = m_CheckBaseConfig->baseCheckFunction.detconfig.chip_width_mm / m_CheckBaseConfig->imageScaleParam.fScale_X; int h = m_CheckBaseConfig->baseCheckFunction.detconfig.chip_height_mm / m_CheckBaseConfig->imageScaleParam.fScale_Y; auto w_offset = std::abs(w - m_AlignMaxRoi.width); @@ -497,7 +501,7 @@ int Down_Detect::ImgAlinRotate(const cv::Mat &img, cv::Mat &alignImg) int param_h_offset = m_CheckBaseConfig->baseCheckFunction.detconfig.chip_height_offset_mm / m_CheckBaseConfig->imageScaleParam.fScale_Y; if (w_offset > param_w_offset || h_offset > param_h_offset) { - printf("Align error, no product\n"); + printf("Align error, no product\n"); return 1; } diff --git a/Side_Det/src/Side_Detect.cpp b/Side_Det/src/Side_Detect.cpp index cc44b56..7df21ca 100644 --- a/Side_Det/src/Side_Detect.cpp +++ b/Side_Det/src/Side_Detect.cpp @@ -116,12 +116,16 @@ int Side_Detect::CheckRun() re = ImgAlinRotate(detimg, AlignImg); if (0 != re) { + //失败NG + m_CheckResult_shareP->nresult = 1; return re; } // 缺陷检测 re = DetectImg(AlignImg); if (0 != re) { + //失败NG + m_CheckResult_shareP->nresult = 1; return re; } t2 = CheckUtil::getcurTime(); diff --git a/TOP_Det/src/Top_Detect.cpp b/TOP_Det/src/Top_Detect.cpp index 51c1b63..2e1a0d6 100644 --- a/TOP_Det/src/Top_Detect.cpp +++ b/TOP_Det/src/Top_Detect.cpp @@ -86,7 +86,7 @@ int Top_Detect::CheckRun() t1 = CheckUtil::getcurTime(); CheckImgInit(); cv::Mat detimg = DetImgInfo_shareP->img; - //准备结果图 + // 准备结果图 cv::resize(detimg.clone(), m_CheckResult_shareP->resultImg, cv::Size(800, 600)); if (detimg.empty()) { @@ -114,12 +114,16 @@ int Top_Detect::CheckRun() re = ImgAlinRotate(detimg, AlignImg); if (0 != re) { + // 失败NG + m_CheckResult_shareP->nresult = 1; return re; } // 缺陷检测 re = DetectImg(AlignImg); if (0 != re) { + // 失败NG + m_CheckResult_shareP->nresult = 1; return re; } t2 = CheckUtil::getcurTime(); @@ -308,13 +312,13 @@ int Top_Detect::Draw(const cv::Mat &img, cv::Mat &resultimg) // int x = center.x - w / 2; // int y = center.y - h / 2; - + // // 确保裁剪区域不超出图像边界 // x = std::max(0, x); // y = std::max(0, y); // x = std::min(x, img.cols - w); // y = std::min(y, img.rows - h); - + // // 创建裁剪区域 // cv::Rect cropRoi(x, y, w, h); // resultimg = resultimg(cropRoi); @@ -487,18 +491,18 @@ int Top_Detect::ImgAlinRotate(const cv::Mat &img, cv::Mat &alignImg) return 1; } - //判断尺寸 - int w = m_CheckBaseConfig->baseCheckFunction.detconfig.chip_width_mm / m_CheckBaseConfig->imageScaleParam.fScale_X; - int h = m_CheckBaseConfig->baseCheckFunction.detconfig.chip_height_mm / m_CheckBaseConfig->imageScaleParam.fScale_Y; - auto w_offset = std::abs(w - m_AlignMaxRoi.width); - auto h_offset = std::abs(h - m_AlignMaxRoi.height); - int param_w_offset = m_CheckBaseConfig->baseCheckFunction.detconfig.chip_width_offset_mm / m_CheckBaseConfig->imageScaleParam.fScale_X; - int param_h_offset = m_CheckBaseConfig->baseCheckFunction.detconfig.chip_height_offset_mm / m_CheckBaseConfig->imageScaleParam.fScale_Y; - if (w_offset > param_w_offset || h_offset > param_h_offset) - { - printf("Align error, no product\n"); - return 1; - } + // 判断尺寸 + int w = m_CheckBaseConfig->baseCheckFunction.detconfig.chip_width_mm / m_CheckBaseConfig->imageScaleParam.fScale_X; + int h = m_CheckBaseConfig->baseCheckFunction.detconfig.chip_height_mm / m_CheckBaseConfig->imageScaleParam.fScale_Y; + auto w_offset = std::abs(w - m_AlignMaxRoi.width); + auto h_offset = std::abs(h - m_AlignMaxRoi.height); + int param_w_offset = m_CheckBaseConfig->baseCheckFunction.detconfig.chip_width_offset_mm / m_CheckBaseConfig->imageScaleParam.fScale_X; + int param_h_offset = m_CheckBaseConfig->baseCheckFunction.detconfig.chip_height_offset_mm / m_CheckBaseConfig->imageScaleParam.fScale_Y; + if (w_offset > param_w_offset || h_offset > param_h_offset) + { + printf("Align error, no product\n"); + return 1; + } DetRotateType ratio = m_CheckBaseConfig->baseCheckFunction.detconfig.rotate; std::cout << "rotate ratio : " << ratio << std::endl;