| | |
| | | return m_nDefect; |
| | | } |
| | | |
| | | int CDefectControl::ExtractDefect_NotchBroken(DimensionDir emDim, int iCam, int iScan, CDefect_Info defect) |
| | | { |
| | | if (m_pGrabber == NULL) { |
| | | return m_nDefect; |
| | | } |
| | | |
| | | CSingleLock MyLock(&m_csDefect); |
| | | MyLock.Lock(); |
| | | |
| | | if (m_nDefect >= m_maxDefect) { |
| | | MyLock.Unlock(); |
| | | return m_nDefect; |
| | | } |
| | | |
| | | CDefect* pDefect = GetDefect(m_nDefect); |
| | | if (pDefect == NULL) { |
| | | MyLock.Unlock(); |
| | | return m_nDefect; |
| | | } |
| | | |
| | | pDefect->Reset(); |
| | | pDefect->m_bJudge_NG = TRUE; |
| | | pDefect->m_DefectInfo = defect; |
| | | |
| | | int nXStart = pDefect->m_DefectInfo.m_ptDefectPos_pxl.x - (DEFECTIMAGE_WIDTH / 2); |
| | | int nYStart = pDefect->m_DefectInfo.m_ptDefectPos_pxl.y - (DEFECTIMAGE_HEIGHT / 2); |
| | | int nXSize = DEFECTIMAGE_WIDTH; |
| | | int nYSize = DEFECTIMAGE_HEIGHT; |
| | | //int nXStart = pDefect->m_DefectInfo.m_rtDefectPos_pxl.left; |
| | | //int nYStart = pDefect->m_DefectInfo.m_rtDefectPos_pxl.top; |
| | | //int nXSize = pDefect->m_DefectInfo.m_rtDefectPos_pxl.Width(); |
| | | //int nYSize = pDefect->m_DefectInfo.m_rtDefectPos_pxl.Height(); |
| | | if (m_pGrabber->GetSmallImage(iScan, pDefect->m_Image, nXStart, nYStart, nXSize, nYSize, FALSE) == FALSE) { |
| | | MyLock.Unlock(); |
| | | return m_nDefect; |
| | | } |
| | | |
| | | m_nDefect++; |
| | | |
| | | MyLock.Unlock(); |
| | | return m_nDefect; |
| | | } |
| | | |
| | | int CDefectControl::ExtractDefect_UserDefect(DimensionDir emDim, int iCam, int iScan, int nUserDefectAreaIdx, std::vector<CDefect_Info>* vecPreDefectList) |
| | | { |
| | | if(m_pGrabber == NULL) |
| | |
| | | int ExtractDefect(DimensionDir emDim, int iCam, int iScan, CDefect_Info preDefectList); |
| | | int ExtractDefect_Side(DimensionDir emDim, int iCam, int iScan, std::vector<CDefect_Info>* vecPreDefectList); |
| | | int ExtractDefect_Notch(DimensionDir emDim, int iCam, int iScan, int nNotchDefectAreaIdx, std::vector<CDefect_Info>* vecPreDefectList); |
| | | int ExtractDefect_NotchBroken(DimensionDir emDim, int iCam, int iScan, CDefect_Info defect); |
| | | int ExtractDefect_UserDefect(DimensionDir emDim, int iCam, int iScan, int nUserDefectAreaIdx, std::vector<CDefect_Info>* vecPreDefectList); |
| | | int ExtractDefect_Measure(DimensionDir emDim, int iCam, int iScan, CDefect_Info defect, double dMeasureResult_um, double dMeasureDiff_um); |
| | | |
| | |
| | | bJudgeUse = (pSideParam->m_UserDefectPrm[pDefect->m_nUserDefectAreaIdx].m_nJudge_Size_Min_OR_AND == 0) ? FALSE : TRUE; |
| | | break; |
| | | case DefectLoc_Notch_Crack: |
| | | |
| | | case DefectLoc_Notch_Broken: |
| | | case DefectLoc_Notch_NoGrind: |
| | | nJudgeW_um = pSideParam->m_NotchPrm[pDefect->m_nNotchIdx].m_nNotch_Inspect_Defect_Judge_X_um; |
| | | nJudgeH_um = pSideParam->m_NotchPrm[pDefect->m_nNotchIdx].m_nNotch_Inspect_Defect_Judge_Y_um; |
| | |
| | | DefectLoc_Measure_Chamfer, |
| | | |
| | | DefectLoc_Notch_Crack, |
| | | DefectLoc_Notch_Broken, |
| | | DefectLoc_Notch_NoGrind, |
| | | DefectLoc_Notch_Dimension, |
| | | DefectLoc_Notch_Chamfer, |
| | |
| | | _T("Chamfer"), |
| | | |
| | | _T("Notch"), |
| | | _T("Notch_Broken"), |
| | | _T("Notch_NoGrind"), |
| | | _T("Notch_Dimension"), |
| | | _T("Notch_Chamfer"), |
| | |
| | | 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 < 2000) { |
| | | continue; |
| | | } |
| | | |
| | | if (std::abs(dLength - 7000) > 1000) { |
| | | 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("[WARN] Notch defect contour length deviates significantly from expected: %f"), dLength); |
| | | break; |
| | | } |
| | |
| | | // 9. Notch Inspect |
| | | BOOL Notch_Process(int iThread,DimensionDir emDim, stFrameIndex stFrame); |
| | | void Notch_Process_PreProcess(DimensionDir emDim, stFrameIndex stFrame, int nNotchIdx, IplImage* scr, IplImage* img_Edge, IplImage* img_Bin, CRect rtROI); |
| | | void Notch_Process_PreProcess_2(DimensionDir emDim, stFrameIndex stFrame, int nNotchIdx, IplImage* scr, IplImage* img_Edge, IplImage* img_Bin, CRect rtROI); |
| | | void Notch_Process_Measure(DimensionDir emDim, stFrameIndex stFrame, int nNotchIdx, IplImage* scr,IplImage* img_Edge,IplImage* img_Bin, CRect rtROI); |
| | | bool Notch_Process_Calculate(DimensionDir emDim, stFrameIndex stFrame, int nNotchIdx, IplImage* scr,IplImage* img_Edge,IplImage* img_Bin, CRect rtROI); |
| | | void Notch_Process_Judge(DimensionDir emDim, stFrameIndex stFrame, int nNotchIdx, IplImage* scr,IplImage* img_Edge,IplImage* img_Bin, CRect rtROI); |