mrDarker
2025-08-22 04d89bc9216553adcd0df87985a7665882924093
EdgeInspector_App/Process/InspectCamera.cpp
@@ -3826,7 +3826,7 @@
         defectInfo.m_nSideIdx = (int)emDim;
         defectInfo.m_ptDefectPos_pxl = rtRotateArea.CenterPoint();
         defectInfo.m_rtDefectPos_pxl = rtRotateArea;
         defectInfo.m_DefectLoc = DefectLoc_Notch_Crack;
         defectInfo.m_DefectLoc = DefectLoc_Notch_NoGrind;
         m_pDefectControl->ExtractDefect(emDim, m_iCamera, stFrame.nScanIdx, defectInfo);
         cvReleaseImageHeader(&pOriginImage);
@@ -4127,13 +4127,13 @@
{
   if (m_pRecipe == NULL || m_pGlassData == NULL)
      return FALSE;
   int NotchFlag = 0;
   for (int nMeasureIdx = 0; nMeasureIdx < MAX_SIDE_NOTCH_MEASURE_COUNT; nMeasureIdx++)
   {
      CPoint ptRef_pxl = m_pGlassData->GetSideData(emDim)->m_ptNotch_Reference[nNotchIdx][nMeasureIdx];
      CPoint ptDim_pxl = m_pGlassData->GetSideData(emDim)->m_ptNotch_Dimension_Edge[nNotchIdx][nMeasureIdx];
      if (ptRef_pxl.x < 0 || ptRef_pxl.y < 0) {
   /*   if (ptRef_pxl.x < 0 || ptRef_pxl.y < 0) {
         g_pLog->DisplayMessage(_T("[ERROR] Invalid Ref Point at Notch_Process_Calculate, NotchIdx: %d, MeasureIdx: %d, Point: (%d, %d)"), nNotchIdx, nMeasureIdx, ptRef_pxl.x, ptRef_pxl.y);
         continue;
      }
@@ -4141,7 +4141,7 @@
      if (ptDim_pxl.x < 0 || ptDim_pxl.y < 0) {
         g_pLog->DisplayMessage(_T("[ERROR] Invalid Dim Point at Notch_Process_Calculate, NotchIdx: %d, MeasureIdx: %d, Point: (%d, %d)"), nNotchIdx, nMeasureIdx, ptDim_pxl.x, ptDim_pxl.y);
         continue;
      }
      }*/
      // Dimension
      double dX_dim_um = (double)(ptRef_pxl.x - ptDim_pxl.x) * m_dPixelSizeX;
@@ -4150,22 +4150,25 @@
      m_pGlassData->GetSideData(emDim)->m_dNotch_Dimension_Edge_Result_um[nNotchIdx][nMeasureIdx] = dDimension;
      CPoint ptChamfer_pxl = m_pGlassData->GetSideData(emDim)->m_ptNotch_Chamfer_Edge[nNotchIdx][nMeasureIdx];
      if (ptChamfer_pxl.x < 0 || ptChamfer_pxl.y < 0) {
   /*   if (ptChamfer_pxl.x < 0 || ptChamfer_pxl.y < 0) {
         g_pLog->DisplayMessage(_T("[ERROR] Invalid Chamfer Point at Notch_Process_Calculate, NotchIdx: %d, MeasureIdx: %d, Point: (%d, %d)"), nNotchIdx, nMeasureIdx, ptChamfer_pxl.x, ptChamfer_pxl.y);
         continue;
      }
      }*/
      double dX_Chamfer = (double)(ptChamfer_pxl.x - ptDim_pxl.x) * m_dPixelSizeX;
      double dY_Chamfer = (double)(ptChamfer_pxl.y - ptDim_pxl.y) * m_dPixelSizeY;
      double dChamfer = sqrtf((dX_Chamfer * dX_Chamfer) + (dY_Chamfer * dY_Chamfer));
      m_pGlassData->GetSideData(emDim)->m_dNotch_Chamfer_Edge_Result_um[nNotchIdx][nMeasureIdx] = dChamfer;
      if (dDimension > 2000.0 && dChamfer > 2000.0) {
      if (dDimension > 5000.0 && dChamfer > 5000.0) {
         g_pLog->DisplayMessage(_T("[ERROR] Abnormal Dimension & Chamfer too large at Notch_Process_Calculate, NotchIdx: %d, MeasureIdx: %d, Dimension: %.2f, Chamfer: %.2f"), nNotchIdx, nMeasureIdx, dDimension, dChamfer);
         continue;
         NotchFlag=1;
      }
   }
   if (NotchFlag == TRUE)
   {
      return FALSE;
   }else
   return TRUE;
}
@@ -4440,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;
@@ -4468,6 +4525,7 @@
   int iFrame = stFrame.nFrameIdx;
   CRect rtProcessArea = rtROI;
   int nMinSize_X = (pNotchParam->m_nNotch_Inspect_Defect_Min_X_um / (int)m_pGlassData->GetSideData(emDim)->m_dPixelSizeX);
   int nMinSize_Y = (pNotchParam->m_nNotch_Inspect_Defect_Min_Y_um / (int)m_pGlassData->GetSideData(emDim)->m_dPixelSizeY);
   int nMinSize = 0;