From 04d89bc9216553adcd0df87985a7665882924093 Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期五, 22 八月 2025 17:56:10 +0800
Subject: [PATCH] 1. 优化Notch计算周长,使用比例的形式计算

---
 EdgeInspector_App/Process/InspectCamera.cpp |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 54 insertions(+), 0 deletions(-)

diff --git a/EdgeInspector_App/Process/InspectCamera.cpp b/EdgeInspector_App/Process/InspectCamera.cpp
index 5c328ec..178ab4e 100644
--- a/EdgeInspector_App/Process/InspectCamera.cpp
+++ b/EdgeInspector_App/Process/InspectCamera.cpp
@@ -4443,6 +4443,60 @@
 	strTemp.Format(_T("Notch\\Notch_%d_Defect_ProcBinImage"), nNotchIdx);
 	SaveDebugImage(emDim, stFrame, pProcBinImage, strTemp);
 
+	const double dExpectedLen = 6500;
+	const double dMinNotchLen = 0.20 * dExpectedLen;
+	const double dAlarmAbs = 0.10 * dExpectedLen;
+
+	CvSeq* pContours = nullptr;
+	CvMemStorage* pStorage = cvCreateMemStorage(0);
+	cvFindContours(pProcBinImage, pStorage, &pContours, sizeof(CvContour), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
+	for (CvSeq* c = pContours; c != nullptr; c = c->h_next) {
+		if (c->total == 0) {
+			continue;
+		}
+
+		double dLength = cvArcLength(c);
+		if (dLength < dMinNotchLen) {
+			continue;
+		}
+		g_pLog->DisplayMessage(_T("Notch defect contour length: %f, Frame: %d, Scan: %d, Camera: %d, NotchIdx: %d"), dLength, stFrame.nFrameIdx, stFrame.nScanIdx, m_iCamera, nNotchIdx);
+
+		if (std::abs(dLength - dExpectedLen) > dAlarmAbs) {
+			CvRect rect = cvBoundingRect(c, 0);
+			CRect rtDefectPos_pxl(
+				rect.x + rtROI.left,
+				rect.y + rtROI.top,
+				rect.x + rect.width + rtROI.left,
+				rect.y + rect.height + rtROI.top
+			);
+
+			CPoint ptDefectPos_pxl(0, 0);
+			CvPoint* ptStart = reinterpret_cast<CvPoint*>(CV_GET_SEQ_ELEM(CvPoint, c, 0));
+			CvPoint* ptEnd = reinterpret_cast<CvPoint*>(CV_GET_SEQ_ELEM(CvPoint, c, c->total - 1));
+			if (ptStart->x < ptEnd->x) {
+				ptDefectPos_pxl.x = ptStart->x + rtROI.left;
+				ptDefectPos_pxl.y = ptStart->y + rtROI.top;
+			}
+			else {
+				ptDefectPos_pxl.x = ptEnd->x + rtROI.left;
+				ptDefectPos_pxl.y = ptEnd->y + rtROI.top;
+			}
+
+			CDefect_Info info;
+			info.m_iFrameIdx = stFrame.nFrameIdx;
+			info.m_nCamID = m_iCamera;
+			info.m_nScanIdx = stFrame.nScanIdx;
+			info.m_nGlassStartLine = m_pGlassData->GetSideData(emDim)->m_nGlassStartLine;
+			info.m_nSideIdx = (int)emDim;
+			info.m_ptDefectPos_pxl = ptDefectPos_pxl;
+			info.m_rtDefectPos_pxl = rtDefectPos_pxl;
+			info.m_DefectLoc = DefectLoc_Notch_Broken;
+			m_pDefectControl->ExtractDefect_NotchBroken(emDim, m_iCamera, stFrame.nScanIdx, info);
+			g_pLog->DisplayMessage(_T("Notch defect contour length deviates significantly from expected: %f"), dLength);
+			break;
+		}
+	}
+
 #if	MINI_LED == 0
 	// 鎺橀健韴囬優電撮憭锛岆牆宀弘矔雽曤彅閳措船鐝傡儉旖旊嫺鐙傜棛
 	int nDilateCount = pNotchParam->m_nNotch_Inspect_Defect_dilate;

--
Gitblit v1.9.3