| | |
| | | iScan = m_iScan; |
| | | |
| | | stFrameIndex stFrame; |
| | | |
| | | stFrame.nScanIdx = m_iScan; |
| | | |
| | | if (m_bFindGlassStart[stFrame.nScanIdx] == TRUE) |
| | | if (m_bFindGlassStart[stFrame.nScanIdx] == TRUE) { |
| | | return ERR_FINDGLASSSTART_SUCCESS; |
| | | } |
| | | |
| | | // 자동일때 프레임 수를 충분히 잡으면 문제가 안되는거 같다만... 프레임 수가 부족하면 여기서 무한으로 걸림.. 그리고 시작선 찾았으면 그냥 넘어가면 되지 않나? |
| | | if (m_pGrabber->GetGrabFrameCount() < 1) |
| | | { |
| | | if (m_pGrabber->GetGrabFrameCount() < 1 || iThread != 0) { |
| | | Sleep(0); |
| | | return ERR_FINDGLASSSTART_FAIL; |
| | | } |
| | | |
| | | /* |
| | | stFrameIndex stFrame; |
| | | |
| | | stFrame.nScanIdx = m_iScan; |
| | | |
| | | if(m_bFindGlassStart[stFrame.nScanIdx] == TRUE) |
| | | return ERR_FINDGLASSSTART_SUCCESS; |
| | | */ |
| | | |
| | | if (iThread != 0) |
| | | return ERR_FINDGLASSSTART_FAIL; |
| | | |
| | | DimensionDir emDim = GetDimension(stFrame.nScanIdx); |
| | | |
| | | iScan = stFrame.nScanIdx; |
| | | |
| | | if (FindGlassStartLine(emDim, stFrame) == TRUE) |
| | | { |
| | | g_pLog->DisplayMessage(_T("Find Start Line Success!")); |
| | | g_pLog->DisplayMessage(_T("%s Is Glass Start Line!"), PANEL_SIDE[emDim]); |
| | | |
| | | if (FindGlassStartLine(emDim, stFrame) == TRUE) { |
| | | g_pLog->DisplayMessage(_T("%s Find Start Line Success!"), PANEL_SIDE[emDim]); |
| | | |
| | | ScanRegionSet(stFrame); |
| | | m_bFindGlassStart[stFrame.nScanIdx] = TRUE; |
| | |
| | | m_MsgJob.nDispLine = 0; |
| | | m_MsgJob.nSide = (int)emDim; |
| | | CSide_Data* pSideData = m_pGlassData->GetSideData(emDim); |
| | | if (pSideData != NULL) |
| | | if (pSideData != NULL) { |
| | | m_MsgJob.nDispLine = pSideData->m_nGlassStartLine; |
| | | } |
| | | |
| | | ::SendMessage(m_hWndViewScan, WM_POCESS_STATUS, (WPARAM)&m_MsgJob, (int)emDim); |
| | | |
| | | return ERR_FINDGLASSSTART_SUCCESS; |
| | | } |
| | | else |
| | | { |
| | | else { |
| | | return ERR_FINDGLASSSTART_FIND_FAIL; |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | #endif // HALCON_VISION_KEY |
| | | |
| | | MeasureSideEdge_EI(eDim); |
| | | } |
| | | |
| | | BOOL CInspectCamera::MeasureSideEdge_EI(DimensionDir eDim) { |
| | | /* code */ |
| | | bool bExec = (DIMENSION_A_RIP == eDim) || (DIMENSION_B_RIP == eDim) || (DIMENSION_C_RIP == eDim) || (DIMENSION_D_RIP == eDim); |
| | | if (!bExec) return FALSE; |
| | | CSide_Data* pSideData = m_pGlassData->GetSideData(eDim); |
| | | |
| | | //查找边界 |
| | | CFrameBufferController* pFrameBufferController = m_pGrabber->GetFrameBuffer(); |
| | | int imgWidth = pFrameBufferController->GetFrameWidth(); |
| | | |
| | | //获取上边界和下边 |
| | | int nTopEdge = pSideData->m_nGlassStartLine; |
| | | int nBottomEdge = pSideData->m_nGlassEndLine; |
| | | g_pLog->DisplayMessage(_T("[APP]Measure Side Edge Start, StartEdge = %d, EndEdge = %d, Width = %d"), nTopEdge, nBottomEdge, imgWidth); |
| | | |
| | | stFrameIndex stFrame = m_pGrabber->GetGrabFrame(); |
| | | CSIDE_PARM parm = m_pRecipe->m_SideParam[eDim]; |
| | | CRIP_THICKNESS_PARM& rip = parm.m_RipThk; |
| | | if (rip.m_bUseInspect != TRUE) { |
| | | return TRUE; |
| | | } |
| | | |
| | | //输入参数 |
| | | int topOffset = rip.m_nTopOffset; //T Offset |
| | | int botOffset = rip.m_nBottomOffset; //B Offset |
| | | int leftEdge = rip.m_nRectLeft; //Rect L |
| | | int rightEdge = rip.m_nRectRight; //Rect R |
| | | int leftThres = rip.m_nLeftThres; //Left Thres |
| | | int rightThres = rip.m_nRightThres; //Right Thres |
| | | int gassThres = rip.m_nGlassThres; //Gas Thres |
| | | |
| | | int inspectNum = 36; |
| | | |
| | | int startY = nTopEdge + topOffset; |
| | | int endY = nBottomEdge - botOffset; |
| | | int step = (int)((endY - startY) / inspectNum); |
| | | g_pLog->DisplayMessage(_T("[APP]Measure Side Edge, (startY, endY, step) = (%d, %d, %d)"), startY, endY, step); |
| | | |
| | | int nStep = max(1, (endY - startY) / inspectNum); // 防 0 |
| | | auto SpecDiff = [](double v, double vMin, double vMax)->double { |
| | | if (v <= 0) return 0.0; // 无效值 |
| | | if (v < vMin) return v - vMin; // 负:低于下限 |
| | | if (v > vMax) return v - vMax; // 正:高于上限 |
| | | return 0.0; // 在规格内 |
| | | }; |
| | | auto judge = [](double v_um, double vMin, double vMax)->int { |
| | | if (v_um <= 0) return 0; |
| | | return (v_um < vMin || v_um > vMax) ? 2 : 1; |
| | | }; |
| | | auto MakeBaseInfo = [&](CPoint pt, CRect rt, DefectLocation loc)->CDefect_Info { |
| | | CDefect_Info info; |
| | | info.m_iFrameIdx = stFrame.nFrameIdx; |
| | | info.m_nCamID = m_iCamera; |
| | | info.m_nScanIdx = stFrame.nScanIdx; |
| | | info.m_nGlassStartLine = pSideData->m_nGlassStartLine; |
| | | info.m_nSideIdx = (int)eDim; |
| | | info.m_ptDefectPos_pxl = pt; |
| | | info.m_rtDefectPos_pxl = rt; |
| | | info.m_DefectLoc = loc; |
| | | return info; |
| | | }; |
| | | |
| | | #if 1 |
| | | int nMeasureCount = parm.m_nSideDimensionCount; |
| | | for (int nMeasurePointIdx = 0; nMeasurePointIdx < nMeasureCount; nMeasurePointIdx++) { |
| | | if (nMeasurePointIdx == MAX_SIDE_DIMENSION_MEASURE_COUNT) { |
| | | break; |
| | | } |
| | | |
| | | if (parm.m_bSideDimension_Use[nMeasurePointIdx] != TRUE) { |
| | | continue; |
| | | } |
| | | |
| | | //这里做一个测试 |
| | | int inputY = (int)(parm.m_nSideDimensionPos_TopMarkToDistance_um[nMeasurePointIdx] * m_dPixelSizeY); //这个是输入参数,距离StartLine的距离, um |
| | | int targetY = (int)(inputY / m_dPixelSizeY); |
| | | int x1 = leftEdge; |
| | | int y1 = nTopEdge + targetY - 50; |
| | | int x2 = rightEdge; |
| | | int y2 = nTopEdge + targetY + 50; |
| | | |
| | | double dist_ret = 0.0f; //输出结果 |
| | | double left_dist_Gass = 0.0f; //输出结果 |
| | | double right_dist_Gass; //输出结果 |
| | | double xMinEdge_px = 0.0f; //输出结果 |
| | | double yMinEdge_px = 0.0f; //输出结果 |
| | | double xMaxEdge_px = 0.0f; //输出结果 |
| | | double yMaxEdge_px = 0.0f; //输出结果 |
| | | double xMinGas_px = 0.0f; //输出结果 |
| | | double yMinGas_px = 0.0f; //输出结果 |
| | | double xMaxGas_px = 0.0f; //输出结果 |
| | | double yMaxGas_px = 0.0f; //输出结果 |
| | | MeasureSideEdge_POS_1(eDim, x1, y1, x2, y2, leftThres, rightThres, gassThres, |
| | | xMinEdge_px, yMinEdge_px, xMaxEdge_px, yMaxEdge_px, |
| | | xMinGas_px, yMinGas_px, xMaxGas_px, yMaxGas_px, |
| | | dist_ret, left_dist_Gass, right_dist_Gass); |
| | | |
| | | g_pLog->DisplayMessage(_T("[APP]Measure Result: LeftEdge = (%.1f, %.1f), LeftGas = (%.1f, %.1f), rightGas = (%.1f, %.1f), RightEdge = (%.1f, %.1f), (Dist, LeftGass, RightGass) = (%.1f, %.1f, %.1f)"), |
| | | xMinEdge_px, yMinEdge_px, |
| | | xMinGas_px, yMinGas_px, |
| | | xMaxGas_px, yMaxGas_px, |
| | | xMaxEdge_px, yMaxEdge_px, |
| | | dist_ret, left_dist_Gass, right_dist_Gass); |
| | | |
| | | dist_ret *= m_dPixelSizeX; |
| | | left_dist_Gass *= m_dPixelSizeX; |
| | | right_dist_Gass *= m_dPixelSizeX; |
| | | |
| | | const int nGlassState = judge(dist_ret, rip.m_nGlassSizeMin_um, rip.m_nGlassSizeMax_um); |
| | | const int nLeftState = judge(left_dist_Gass, rip.m_nLeftRipSizeMin_um, rip.m_nLeftRipSizeMax_um); |
| | | const int nRightState = judge(right_dist_Gass, rip.m_nRightRipSizeMin_um, rip.m_nRightRipSizeMax_um); |
| | | |
| | | if (nMeasurePointIdx < MAX_RIP_SAMPLE_COUNT) { |
| | | // Glass 线段 |
| | | pSideData->m_ptSideRip_Glass_pxl[nMeasurePointIdx][0] = CPoint((int)xMinEdge_px, (int)yMinEdge_px); |
| | | pSideData->m_ptSideRip_Glass_pxl[nMeasurePointIdx][1] = CPoint((int)xMaxEdge_px, (int)yMaxEdge_px); |
| | | pSideData->m_dSideRip_Glass_um[nMeasurePointIdx] = dist_ret; |
| | | pSideData->m_nSideRip_Glass_Status[nMeasurePointIdx] = nGlassState; |
| | | |
| | | // Left 线段 |
| | | pSideData->m_ptSideRip_Left_pxl[nMeasurePointIdx][0] = CPoint((int)xMinEdge_px, (int)yMinEdge_px); |
| | | pSideData->m_ptSideRip_Left_pxl[nMeasurePointIdx][1] = CPoint((int)xMinGas_px, (int)yMinGas_px); |
| | | pSideData->m_dSideRip_Left_um[nMeasurePointIdx] = left_dist_Gass; |
| | | pSideData->m_nSideRip_Left_Status[nMeasurePointIdx] = nLeftState; |
| | | |
| | | // Right 线段 |
| | | pSideData->m_ptSideRip_Right_pxl[nMeasurePointIdx][0] = CPoint((int)xMaxGas_px, (int)yMaxGas_px); |
| | | pSideData->m_ptSideRip_Right_pxl[nMeasurePointIdx][1] = CPoint((int)xMaxEdge_px, (int)yMaxEdge_px); |
| | | pSideData->m_dSideRip_Right_um[nMeasurePointIdx] = right_dist_Gass; |
| | | pSideData->m_nSideRip_Right_Status[nMeasurePointIdx] = nRightState; |
| | | } |
| | | |
| | | // Glass NG |
| | | if (nGlassState == 2) { |
| | | CRect rt( |
| | | (int)min(min(xMinEdge_px, xMinGas_px), min(xMaxEdge_px, xMaxGas_px)), |
| | | (int)min(min(yMinEdge_px, yMinGas_px), min(yMaxEdge_px, yMaxGas_px)), |
| | | (int)max(max(xMinEdge_px, xMinGas_px), max(xMaxEdge_px, xMaxGas_px)), |
| | | (int)max(max(yMinEdge_px, yMinGas_px), max(yMaxEdge_px, yMaxGas_px)) |
| | | ); |
| | | CPoint pt((rt.left + rt.right) / 2, (rt.top + rt.bottom) / 2); |
| | | CDefect_Info defect = MakeBaseInfo(pt, rt, DefectLoc_Rip_Thickness_Glass); |
| | | double dDiff = SpecDiff(dist_ret, rip.m_nGlassSizeMin_um, rip.m_nGlassSizeMax_um); |
| | | m_pDefectControl->ExtractDefect_RipThickness(eDim, m_iCamera, stFrame.nScanIdx, defect, dist_ret, dDiff); |
| | | } |
| | | // Left NG |
| | | if (nLeftState == 2) { |
| | | CRect rt( |
| | | (int)min(xMinEdge_px, xMinGas_px), |
| | | (int)min(yMinEdge_px, yMinGas_px), |
| | | (int)max(xMinEdge_px, xMinGas_px), |
| | | (int)max(yMinEdge_px, yMinGas_px) |
| | | ); |
| | | CPoint pt((rt.left + rt.right) / 2, (rt.top + rt.bottom) / 2); |
| | | CDefect_Info defect = MakeBaseInfo(pt, rt, DefectLoc_Rip_Thickness_Left); |
| | | double dDiff = SpecDiff(left_dist_Gass, rip.m_nLeftRipSizeMin_um, rip.m_nLeftRipSizeMax_um); |
| | | m_pDefectControl->ExtractDefect_RipThickness(eDim, m_iCamera, stFrame.nScanIdx, defect, left_dist_Gass, dDiff); |
| | | } |
| | | // Right NG |
| | | if (nRightState == 2) { |
| | | CRect rt( |
| | | (int)min(xMaxEdge_px, xMaxGas_px), |
| | | (int)min(yMaxEdge_px, yMaxGas_px), |
| | | (int)max(xMaxEdge_px, xMaxGas_px), |
| | | (int)max(yMaxEdge_px, yMaxGas_px) |
| | | ); |
| | | CPoint pt((rt.left + rt.right) / 2, (rt.top + rt.bottom) / 2); |
| | | CDefect_Info defect = MakeBaseInfo(pt, rt, DefectLoc_Rip_Thickness_Right); |
| | | double dDiff = SpecDiff(right_dist_Gass, rip.m_nRightRipSizeMin_um, rip.m_nRightRipSizeMax_um); |
| | | m_pDefectControl->ExtractDefect_RipThickness(eDim, m_iCamera, stFrame.nScanIdx, defect, right_dist_Gass, dDiff); |
| | | } |
| | | } |
| | | #else |
| | | double dist_array[36]; //输出结果 |
| | | double left_dist_Gass_array[36]; //输出结果 |
| | | double right_dist_Gass_array[36]; //输出结果 |
| | | double xMinEdge_array_px[36]; //输出结果 |
| | | double yMinEdge_array_px[36]; //输出结果 |
| | | double xMaxEdge_array_px[36]; //输出结果 |
| | | double yMaxEdge_array_px[36]; //输出结果 |
| | | double xMinGas_array_px[36]; //输出结果 |
| | | double yMinGas_array_px[36]; //输出结果 |
| | | double xMaxGas_array_px[36]; //输出结果 |
| | | double yMaxGas_array_px[36]; //输出结果 |
| | | |
| | | for (int i = 0; i < inspectNum; i++) { |
| | | int x1 = leftEdge; |
| | | int y1 = startY + i * step; |
| | | int x2 = rightEdge; |
| | | int y2 = startY + (i + 1) * step; |
| | | |
| | | double szDist, leftGassDist, rightGassDist; |
| | | MeasureSideEdge_POS(eDim, |
| | | x1, y1, x2, y2, |
| | | leftThres, rightThres, gassThres, |
| | | xMinEdge_array_px[i], yMinEdge_array_px[i], xMaxEdge_array_px[i], yMaxEdge_array_px[i], |
| | | xMinGas_array_px[i], yMinGas_array_px[i], xMaxGas_array_px[i], yMaxGas_array_px[i], |
| | | szDist, leftGassDist, rightGassDist); |
| | | |
| | | dist_array[i] = m_dPixelSizeX * szDist; |
| | | left_dist_Gass_array[i] = m_dPixelSizeX * leftGassDist; |
| | | right_dist_Gass_array[i] = m_dPixelSizeX * rightGassDist; |
| | | |
| | | g_pLog->DisplayMessage(_T("[APP]Measure Result %d: LeftEdge = (%.1f, %.1f), LeftGas = (%.1f, %.1f), rightGas = (%.1f, %.1f), RightEdge = (%.1f, %.1f), (Dist, LeftGass, RightGass) = (%.1f, %.1f, %.1f)"), |
| | | i + 1, |
| | | xMinEdge_array_px[i], yMinEdge_array_px[i], |
| | | xMinGas_array_px[i], yMinGas_array_px[i], |
| | | xMaxGas_array_px[i], yMaxGas_array_px[i], |
| | | xMaxEdge_array_px[i], yMaxEdge_array_px[i], |
| | | dist_array[i], left_dist_Gass_array[i], right_dist_Gass_array[i]); |
| | | |
| | | // 添加缺陷 |
| | | int nStep = max(1, (endY - startY) / inspectNum); // 防 0 |
| | | auto SpecDiff = [](double v, double vMin, double vMax)->double { |
| | | if (v <= 0) return 0.0; // 无效值 |
| | | if (v < vMin) return v - vMin; // 负:低于下限 |
| | | if (v > vMax) return v - vMax; // 正:高于上限 |
| | | return 0.0; // 在规格内 |
| | | }; |
| | | |
| | | auto MakeBaseInfo = [&](CPoint pt, CRect rt, DefectLocation loc)->CDefect_Info { |
| | | CDefect_Info info; |
| | | info.m_iFrameIdx = stFrame.nFrameIdx; |
| | | info.m_nCamID = m_iCamera; |
| | | info.m_nScanIdx = stFrame.nScanIdx; |
| | | info.m_nGlassStartLine = pSideData->m_nGlassStartLine; |
| | | info.m_nSideIdx = (int)eDim; |
| | | info.m_ptDefectPos_pxl = pt; |
| | | info.m_rtDefectPos_pxl = rt; |
| | | info.m_DefectLoc = loc; |
| | | return info; |
| | | }; |
| | | |
| | | bool ngGlass = (dist_array[i] > 0) && (dist_array[i] < rip.m_nGlassSizeMin_um || dist_array[i] > rip.m_nGlassSizeMax_um); |
| | | bool ngLeft = (left_dist_Gass_array[i] > 0) && (left_dist_Gass_array[i] < rip.m_nLeftRipSizeMin_um || left_dist_Gass_array[i] > rip.m_nLeftRipSizeMax_um); |
| | | bool ngRight = (right_dist_Gass_array[i] > 0) && (right_dist_Gass_array[i] < rip.m_nRightRipSizeMin_um || right_dist_Gass_array[i] > rip.m_nRightRipSizeMax_um); |
| | | |
| | | // Glass 厚度 NG |
| | | if (ngGlass) { |
| | | CRect rt( |
| | | (int)min(min(xMinEdge_array_px[i], xMinGas_array_px[i]), min(xMaxEdge_array_px[i], xMaxGas_array_px[i])), |
| | | (int)min(min(yMinEdge_array_px[i], yMinGas_array_px[i]), min(yMaxEdge_array_px[i], yMaxGas_array_px[i])), |
| | | (int)max(max(xMinEdge_array_px[i], xMinGas_array_px[i]), max(xMaxEdge_array_px[i], xMaxGas_array_px[i])), |
| | | (int)max(max(yMinEdge_array_px[i], yMinGas_array_px[i]), max(yMaxEdge_array_px[i], yMaxGas_array_px[i])) |
| | | ); |
| | | CPoint pt((rt.left + rt.right) / 2, (rt.top + rt.bottom) / 2); |
| | | CDefect_Info defect = MakeBaseInfo(pt, rt, DefectLoc_Rip_Thickness_Glass); |
| | | double dDiff = SpecDiff(dist_array[i], rip.m_nGlassSizeMin_um, rip.m_nGlassSizeMax_um); |
| | | m_pDefectControl->ExtractDefect_RipThickness(eDim, m_iCamera, stFrame.nScanIdx, defect, dist_array[i], dDiff); |
| | | } |
| | | |
| | | // 左侧气隙 NG |
| | | if (ngLeft) { |
| | | CRect rt( |
| | | (int)min(xMinEdge_array_px[i], xMinGas_array_px[i]), |
| | | (int)min(yMinEdge_array_px[i], yMinGas_array_px[i]), |
| | | (int)max(xMinEdge_array_px[i], xMinGas_array_px[i]), |
| | | (int)max(yMinEdge_array_px[i], yMinGas_array_px[i]) |
| | | ); |
| | | CPoint pt((rt.left + rt.right) / 2, (rt.top + rt.bottom) / 2); |
| | | CDefect_Info defect = MakeBaseInfo(pt, rt, DefectLoc_Rip_Thickness_Left); |
| | | double dDiff = SpecDiff(left_dist_Gass_array[i], rip.m_nLeftRipSizeMin_um, rip.m_nLeftRipSizeMax_um); |
| | | m_pDefectControl->ExtractDefect_RipThickness(eDim, m_iCamera, stFrame.nScanIdx, defect, left_dist_Gass_array[i], dDiff); |
| | | } |
| | | |
| | | // 右侧气隙 NG |
| | | if (ngRight) { |
| | | CRect rt( |
| | | (int)min(xMaxEdge_array_px[i], xMaxGas_array_px[i]), |
| | | (int)min(yMaxEdge_array_px[i], yMaxGas_array_px[i]), |
| | | (int)max(xMaxEdge_array_px[i], xMaxGas_array_px[i]), |
| | | (int)max(yMaxEdge_array_px[i], yMaxGas_array_px[i]) |
| | | ); |
| | | CPoint pt((rt.left + rt.right) / 2, (rt.top + rt.bottom) / 2); |
| | | CDefect_Info defect = MakeBaseInfo(pt, rt, DefectLoc_Rip_Thickness_Right); |
| | | double dDiff = SpecDiff(right_dist_Gass_array[i], rip.m_nRightRipSizeMin_um, rip.m_nRightRipSizeMax_um); |
| | | m_pDefectControl->ExtractDefect_RipThickness(eDim, m_iCamera, stFrame.nScanIdx, defect, right_dist_Gass_array[i], dDiff); |
| | | } |
| | | |
| | | if (i < MAX_RIP_SAMPLE_COUNT) { |
| | | pSideData->m_ptSideRip_Glass_pxl[i][0] = CPoint((int)xMinEdge_array_px[i], (int)yMinEdge_array_px[i]); // start |
| | | pSideData->m_ptSideRip_Glass_pxl[i][1] = CPoint((int)xMaxEdge_array_px[i], (int)yMaxEdge_array_px[i]); // end |
| | | pSideData->m_ptSideRip_Left_pxl[i][0] = CPoint((int)xMinEdge_array_px[i], (int)yMinEdge_array_px[i]); // start |
| | | pSideData->m_ptSideRip_Left_pxl[i][1] = CPoint((int)xMinGas_array_px[i], (int)yMinGas_array_px[i]); // end |
| | | pSideData->m_ptSideRip_Right_pxl[i][0] = CPoint((int)xMaxGas_array_px[i], (int)yMaxGas_array_px[i]); // start |
| | | pSideData->m_ptSideRip_Right_pxl[i][1] = CPoint((int)xMaxEdge_array_px[i], (int)yMaxEdge_array_px[i]); // end |
| | | |
| | | pSideData->m_dSideRip_Glass_um[i] = dist_array[i]; |
| | | pSideData->m_dSideRip_Left_um[i] = left_dist_Gass_array[i]; |
| | | pSideData->m_dSideRip_Right_um[i] = right_dist_Gass_array[i]; |
| | | |
| | | if (dist_array[i] > 0) { |
| | | pSideData->m_nSideRip_Glass_Status[i] = ngGlass ? 2 : 1; |
| | | } |
| | | else { |
| | | pSideData->m_nSideRip_Glass_Status[i] = 0; |
| | | } |
| | | |
| | | if (left_dist_Gass_array[i] > 0) { |
| | | pSideData->m_nSideRip_Left_Status[i] = ngLeft ? 2 : 1; |
| | | } |
| | | else { |
| | | pSideData->m_nSideRip_Left_Status[i] = 0; |
| | | } |
| | | |
| | | if (right_dist_Gass_array[i] > 0) { |
| | | pSideData->m_nSideRip_Right_Status[i] = ngRight ? 2 : 1; |
| | | } |
| | | else { |
| | | pSideData->m_nSideRip_Right_Status[i] = 0; |
| | | } |
| | | } |
| | | } |
| | | #endif |
| | | |
| | | return TRUE; |
| | | } |
| | | |
| | | void CInspectCamera::MeasureSideEdge_POS_1(DimensionDir eDim, |
| | | int x1, int y1, int x2, int y2, |
| | | int leftThres, int rightThres, int gassThres, |
| | | double& minEdgeX, double& minEdgeY, double& maxEdgeX, double& maxEdgeY, |
| | | double& minGasX, double& minGasY, double& maxGasX, double& maxGasY, |
| | | double& szDist, double& leftGassDist, double& rightGassDist) { |
| | | /* code */ |
| | | szDist = 0.0f; |
| | | leftGassDist = 0.0f; |
| | | rightGassDist = 0.0f; |
| | | int width = x2 - x1 + 1; |
| | | int height = y2 - y1 + 1; |
| | | uchar* imgData = new uchar[width * height]; |
| | | try { |
| | | CutImageROI(imgData, eDim, x1, y1, x2, y2); |
| | | |
| | | MeasurePoint dotResult1[100]; |
| | | MeasurePoint dotResult2[100]; |
| | | MeasurePoint dotResult3[100]; |
| | | int dotNum1 = 0; |
| | | int dotNum2 = 0; |
| | | int dotNum3 = 0; |
| | | CVisionMeasureClass doExec; |
| | | double sigma = 2.5f; //输入参数, 增加参数 |
| | | doExec.doMeasurePosB(imgData, width, height, sigma, |
| | | dotResult1, dotNum1, |
| | | dotResult2, dotNum2, |
| | | dotResult3, dotNum3); |
| | | for (int i = 0; i < dotNum1; i++) { |
| | | dotResult1[i].x += x1; |
| | | dotResult1[i].y += y1; |
| | | } |
| | | for (int i = 0; i < dotNum2; i++) { |
| | | dotResult2[i].x += x1; |
| | | dotResult2[i].y += y1; |
| | | } |
| | | for (int i = 0; i < dotNum3; i++) { |
| | | dotResult3[i].x += x1; |
| | | dotResult3[i].y += y1; |
| | | } |
| | | |
| | | int fzDist = 4.5; //输入参数, 增加参数 |
| | | |
| | | double xMinResult[3] = { -1 }; |
| | | double yMinResult[3] = { -1 }; |
| | | double xMaxResult[3] = { -1 }; |
| | | double yMaxResult[3] = { -1 }; |
| | | double xMinGassResult[3] = { -1 }; |
| | | double yMinGassResult[3] = { -1 }; |
| | | double xMaxGassResult[3] = { -1 }; |
| | | double yMaxGassResult[3] = { -1 }; |
| | | MeasureResultProc(dotResult1, dotNum1, leftThres, rightThres, gassThres, fzDist, |
| | | xMinResult[0], yMinResult[0], xMaxResult[0], yMaxResult[0], |
| | | xMinGassResult[0], yMinGassResult[0], xMaxGassResult[0], yMaxGassResult[0]); |
| | | MeasureResultProc(dotResult2, dotNum2, leftThres, rightThres, gassThres, fzDist, |
| | | xMinResult[1], yMinResult[1], xMaxResult[1], yMaxResult[1], |
| | | xMinGassResult[1], yMinGassResult[1], xMaxGassResult[1], yMaxGassResult[1]); |
| | | MeasureResultProc(dotResult3, dotNum3, leftThres, rightThres, gassThres, fzDist, |
| | | xMinResult[2], yMinResult[2], xMaxResult[2], yMaxResult[2], |
| | | xMinGassResult[2], yMinGassResult[2], xMaxGassResult[2], yMaxGassResult[2]); |
| | | |
| | | std::vector<double> vDist, vLeftGass, vRightGass; |
| | | for (int i = 0; i < 3; i++) { |
| | | if (xMinResult[i] > 0 && xMaxResult[i] > 0) { |
| | | double dx = xMaxResult[i] - xMinResult[i]; |
| | | double dy = yMaxResult[i] - yMinResult[i]; |
| | | double dist = sqrt(dx * dx + dy * dy); |
| | | vDist.push_back(dist); |
| | | } |
| | | if (xMinResult[i] > 0 && xMinGassResult[i] > 0) { |
| | | double dx = xMinGassResult[i] - xMinResult[i]; |
| | | double dy = yMinGassResult[i] - yMinResult[i]; |
| | | double dist = sqrt(dx * dx + dy * dy); |
| | | vLeftGass.push_back(dist); |
| | | } |
| | | if (xMaxResult[i] > 0 && xMaxGassResult[i] > 0) { |
| | | double dx = xMaxResult[i] - xMaxGassResult[i]; |
| | | double dy = yMaxResult[i] - yMaxGassResult[i]; |
| | | double dist = sqrt(dx * dx + dy * dy); |
| | | vRightGass.push_back(dist); |
| | | } |
| | | } |
| | | |
| | | double avgDist = 0.0f; |
| | | int sz = (int)(vDist.size()); |
| | | if (sz > 2) { |
| | | for (int i = 0; i < sz - 1; i++) { |
| | | for (int j = i + 1; j < sz; j++) { |
| | | if (vDist[i] > vDist[j]) { |
| | | double tmp = vDist[i]; |
| | | vDist[i] = vDist[j]; |
| | | vDist[j] = tmp; |
| | | } |
| | | } |
| | | } |
| | | double avg = 0.0f; |
| | | for (int i = 1; i < sz - 1; i++) { |
| | | avg += vDist[i]; |
| | | } |
| | | avgDist = avg / (sz - 2); |
| | | } |
| | | double avgLeftGass = 0.0f; |
| | | sz = (int)(vLeftGass.size()); |
| | | if (sz > 2) { |
| | | for (int i = 0; i < sz - 1; i++) { |
| | | for (int j = i + 1; j < sz; j++) { |
| | | if (vLeftGass[i] > vLeftGass[j]) { |
| | | double tmp = vLeftGass[i]; |
| | | vLeftGass[i] = vLeftGass[j]; |
| | | vLeftGass[j] = tmp; |
| | | } |
| | | } |
| | | } |
| | | double avg = 0.0f; |
| | | for (int i = 1; i < sz - 1; i++) { |
| | | avg += vLeftGass[i]; |
| | | } |
| | | avgLeftGass = avg / (sz - 2); |
| | | } |
| | | |
| | | double avgRightGass = 0.0f; |
| | | sz = (int)(vRightGass.size()); |
| | | if (sz > 2) { |
| | | for (int i = 0; i < sz - 1; i++) { |
| | | for (int j = i + 1; j < sz; j++) { |
| | | if (vRightGass[i] > vRightGass[j]) { |
| | | double tmp = vRightGass[i]; |
| | | vRightGass[i] = vRightGass[j]; |
| | | vRightGass[j] = tmp; |
| | | } |
| | | } |
| | | } |
| | | double avg = 0.0f; |
| | | for (int i = 1; i < sz - 1; i++) { |
| | | avg += vRightGass[i]; |
| | | } |
| | | avgRightGass = avg / (sz - 2); |
| | | } |
| | | |
| | | szDist = avgDist; |
| | | leftGassDist = avgLeftGass; |
| | | rightGassDist = avgRightGass; |
| | | |
| | | minEdgeX = xMinResult[1]; |
| | | minEdgeY = yMinResult[1]; |
| | | maxEdgeX = xMaxResult[1]; |
| | | maxEdgeY = yMaxResult[1]; |
| | | minGasX = minEdgeX + leftGassDist - 1; |
| | | minGasY = minEdgeY; |
| | | maxGasX = maxEdgeX - rightGassDist + 1; |
| | | maxGasY = maxEdgeY; |
| | | |
| | | delete[] imgData; |
| | | imgData = nullptr; |
| | | } |
| | | catch (...) { |
| | | delete[] imgData; |
| | | imgData = nullptr; |
| | | } |
| | | } |
| | | |
| | | void CInspectCamera::MeasureSideEdge_POS(DimensionDir eDim, |
| | | int x1, int y1, int x2, int y2, |
| | | int leftThres, int rightThres, int gassThres, |
| | | double& minEdgeX, double& minEdgeY, double& maxEdgeX, double& maxEdgeY, |
| | | double& minGasX, double& minGasY, double& maxGasX, double& maxGasY, |
| | | double& szDist, double& leftGassDist, double& rightGassDist) { |
| | | /* code */ |
| | | szDist = 0.0f; |
| | | leftGassDist = 0.0f; |
| | | rightGassDist = 0.0f; |
| | | int width = x2 - x1 + 1; |
| | | int height = y2 - y1 + 1; |
| | | uchar* imgData = new uchar[width * height]; |
| | | try { |
| | | CutImageROI(imgData, eDim, x1, y1, x2, y2); |
| | | |
| | | MeasurePoint dotResult1[100]; |
| | | MeasurePoint dotResult2[100]; |
| | | MeasurePoint dotResult3[100]; |
| | | MeasurePoint dotResult4[100]; |
| | | MeasurePoint dotResult5[100]; |
| | | MeasurePoint dotResult6[100]; |
| | | MeasurePoint dotResult7[100]; |
| | | int dotNum1 = 0; |
| | | int dotNum2 = 0; |
| | | int dotNum3 = 0; |
| | | int dotNum4 = 0; |
| | | int dotNum5 = 0; |
| | | int dotNum6 = 0; |
| | | int dotNum7 = 0; |
| | | CVisionMeasureClass doExec; |
| | | double sigma = 2.5f; //输入参数, 增加参数 |
| | | doExec.doMeasurePosA(imgData, width, height, sigma, |
| | | dotResult1, dotNum1, |
| | | dotResult2, dotNum2, |
| | | dotResult3, dotNum3, |
| | | dotResult4, dotNum4, |
| | | dotResult5, dotNum5, |
| | | dotResult6, dotNum6, |
| | | dotResult7, dotNum7); |
| | | for (int i = 0; i < dotNum1; i++) { |
| | | dotResult1[i].x += x1; |
| | | dotResult1[i].y += y1; |
| | | } |
| | | for (int i = 0; i < dotNum2; i++) { |
| | | dotResult2[i].x += x1; |
| | | dotResult2[i].y += y1; |
| | | } |
| | | for (int i = 0; i < dotNum3; i++) { |
| | | dotResult3[i].x += x1; |
| | | dotResult3[i].y += y1; |
| | | } |
| | | for (int i = 0; i < dotNum4; i++) { |
| | | dotResult4[i].x += x1; |
| | | dotResult4[i].y += y1; |
| | | } |
| | | for (int i = 0; i < dotNum5; i++) { |
| | | dotResult5[i].x += x1; |
| | | dotResult5[i].y += y1; |
| | | } |
| | | for (int i = 0; i < dotNum6; i++) { |
| | | dotResult6[i].x += x1; |
| | | dotResult6[i].y += y1; |
| | | } |
| | | for (int i = 0; i < dotNum7; i++) { |
| | | dotResult7[i].x += x1; |
| | | dotResult7[i].y += y1; |
| | | } |
| | | |
| | | int fzDist = 4.5; //输入参数, 增加参数 |
| | | |
| | | double xMinResult[7] = { -1 }; |
| | | double yMinResult[7] = { -1 }; |
| | | double xMaxResult[7] = { -1 }; |
| | | double yMaxResult[7] = { -1 }; |
| | | double xMinGassResult[7] = { -1 }; |
| | | double yMinGassResult[7] = { -1 }; |
| | | double xMaxGassResult[7] = { -1 }; |
| | | double yMaxGassResult[7] = { -1 }; |
| | | |
| | | MeasureResultProc(dotResult1, dotNum1, leftThres, rightThres, gassThres, fzDist, |
| | | xMinResult[0], yMinResult[0], xMaxResult[0], yMaxResult[0], |
| | | xMinGassResult[0], yMinGassResult[0], xMaxGassResult[0], yMaxGassResult[0]); |
| | | MeasureResultProc(dotResult2, dotNum2, leftThres, rightThres, gassThres, fzDist, |
| | | xMinResult[1], yMinResult[1], xMaxResult[1], yMaxResult[1], |
| | | xMinGassResult[1], yMinGassResult[1], xMaxGassResult[1], yMaxGassResult[1]); |
| | | MeasureResultProc(dotResult3, dotNum3, leftThres, rightThres, gassThres, fzDist, |
| | | xMinResult[2], yMinResult[2], xMaxResult[2], yMaxResult[2], |
| | | xMinGassResult[2], yMinGassResult[2], xMaxGassResult[2], yMaxGassResult[2]); |
| | | MeasureResultProc(dotResult4, dotNum4, leftThres, rightThres, gassThres, fzDist, |
| | | xMinResult[3], yMinResult[3], xMaxResult[3], yMaxResult[3], |
| | | xMinGassResult[3], yMinGassResult[3], xMaxGassResult[3], yMaxGassResult[3]); |
| | | MeasureResultProc(dotResult5, dotNum5, leftThres, rightThres, gassThres, fzDist, |
| | | xMinResult[4], yMinResult[4], xMaxResult[4], yMaxResult[4], |
| | | xMinGassResult[4], yMinGassResult[4], xMaxGassResult[4], yMaxGassResult[4]); |
| | | MeasureResultProc(dotResult6, dotNum6, leftThres, rightThres, gassThres, fzDist, |
| | | xMinResult[5], yMinResult[5], xMaxResult[5], yMaxResult[5], |
| | | xMinGassResult[5], yMinGassResult[5], xMaxGassResult[5], yMaxGassResult[5]); |
| | | MeasureResultProc(dotResult7, dotNum7, leftThres, rightThres, gassThres, fzDist, |
| | | xMinResult[6], yMinResult[6], xMaxResult[6], yMaxResult[6], |
| | | xMinGassResult[6], yMinGassResult[6], xMaxGassResult[6], yMaxGassResult[6]); |
| | | |
| | | std::vector<double> vDist, vLeftGass, vRightGass; |
| | | for (int i = 0; i < 7; i++) { |
| | | if (xMinResult[i] > 0 && xMaxResult[i] > 0) { |
| | | double dx = xMaxResult[i] - xMinResult[i]; |
| | | double dy = yMaxResult[i] - yMinResult[i]; |
| | | double dist = sqrt(dx * dx + dy * dy); |
| | | vDist.push_back(dist); |
| | | } |
| | | if (xMinResult[i] > 0 && xMinGassResult[i] > 0) { |
| | | double dx = xMinGassResult[i] - xMinResult[i]; |
| | | double dy = yMinGassResult[i] - yMinResult[i]; |
| | | double dist = sqrt(dx * dx + dy * dy); |
| | | vLeftGass.push_back(dist); |
| | | } |
| | | if (xMaxResult[i] > 0 && xMaxGassResult[i] > 0) { |
| | | double dx = xMaxResult[i] - xMaxGassResult[i]; |
| | | double dy = yMaxResult[i] - yMaxGassResult[i]; |
| | | double dist = sqrt(dx * dx + dy * dy); |
| | | vRightGass.push_back(dist); |
| | | } |
| | | } |
| | | |
| | | double avgDist = 0.0f; |
| | | int sz = (int)(vDist.size()); |
| | | if (sz > 3){ |
| | | for (int i = 0; i < sz - 1; i++) { |
| | | for (int j = i + 1; j < sz; j++) { |
| | | if (vDist[i] > vDist[j]) { |
| | | double tmp = vDist[i]; |
| | | vDist[i] = vDist[j]; |
| | | vDist[j] = tmp; |
| | | } |
| | | } |
| | | } |
| | | double avg = 0.0f; |
| | | for (int i = 1; i < sz - 1; i++) { |
| | | avg += vDist[i]; |
| | | } |
| | | avgDist = avg / (sz - 2); |
| | | } |
| | | double avgLeftGass = 0.0f; |
| | | sz = (int)(vLeftGass.size()); |
| | | if (sz > 3) { |
| | | for (int i = 0; i < sz - 1; i++) { |
| | | for (int j = i + 1; j < sz; j++) { |
| | | if (vLeftGass[i] > vLeftGass[j]) { |
| | | double tmp = vLeftGass[i]; |
| | | vLeftGass[i] = vLeftGass[j]; |
| | | vLeftGass[j] = tmp; |
| | | } |
| | | } |
| | | } |
| | | double avg = 0.0f; |
| | | for (int i = 1; i < sz - 1; i++) { |
| | | avg += vLeftGass[i]; |
| | | } |
| | | avgLeftGass = avg / (sz - 2); |
| | | } |
| | | |
| | | double avgRightGass = 0.0f; |
| | | sz = (int)(vRightGass.size()); |
| | | if (sz > 3) { |
| | | for (int i = 0; i < sz - 1; i++) { |
| | | for (int j = i + 1; j < sz; j++) { |
| | | if (vRightGass[i] > vRightGass[j]) { |
| | | double tmp = vRightGass[i]; |
| | | vRightGass[i] = vRightGass[j]; |
| | | vRightGass[j] = tmp; |
| | | } |
| | | } |
| | | } |
| | | double avg = 0.0f; |
| | | for (int i = 1; i < sz - 1; i++) { |
| | | avg += vRightGass[i]; |
| | | } |
| | | avgRightGass = avg / (sz - 2); |
| | | } |
| | | |
| | | szDist = avgDist; |
| | | leftGassDist = avgLeftGass; |
| | | rightGassDist = avgRightGass; |
| | | |
| | | minEdgeX = xMinResult[3]; |
| | | minEdgeY = yMinResult[3]; |
| | | maxEdgeX = xMaxResult[3]; |
| | | maxEdgeY = yMaxResult[3]; |
| | | minGasX = minEdgeX + leftGassDist - 1; |
| | | minGasY = minEdgeY; |
| | | maxGasX = maxEdgeX - rightGassDist + 1; |
| | | maxGasY = maxEdgeY; |
| | | |
| | | delete[] imgData; |
| | | imgData = nullptr; |
| | | } |
| | | catch (...) { |
| | | delete[] imgData; |
| | | imgData = nullptr; |
| | | } |
| | | } |
| | | |
| | | bool CInspectCamera::MeasureResultProc(MeasurePoint* ptResult, int dotNum, int leftThres, int rightRes, int gasThres, double fzDist, |
| | | double& minX, double& minY, double& maxX, double& maxY, double& minGasX, double& minGasY, double& maxGasX, double& maxGasY){ |
| | | /* code */ |
| | | minX = -1.0f; |
| | | minY = -1.0f; |
| | | maxX = -1.0f; |
| | | maxY = -1.0f; |
| | | minGasX = -1.0f; |
| | | minGasY = -1.0f; |
| | | if (dotNum < 2) return false; |
| | | |
| | | //1. 首先查找minX, minY |
| | | bool bMinFin = false; |
| | | minX = MAXINT; |
| | | for (int i = 0; i < dotNum; i++) { |
| | | if (fabs(ptResult[i].cy) > leftThres && ptResult[i].x < minX) { |
| | | minX = ptResult[i].x; |
| | | minY = ptResult[i].y; |
| | | bMinFin = true; |
| | | } |
| | | } |
| | | if (!bMinFin) { |
| | | minX = -1.0f; |
| | | minY = -1.0f; |
| | | } |
| | | |
| | | //2. 查找左右点 |
| | | bool bMaxFind = false; |
| | | maxX = -1.0f; |
| | | for (int i = 0; i < dotNum; i++) { |
| | | if (fabs(ptResult[i].cy) > rightRes && ptResult[i].x > maxX) { |
| | | maxX = ptResult[i].x; |
| | | maxY = ptResult[i].y; |
| | | bMaxFind = true; |
| | | } |
| | | } |
| | | if (!bMaxFind) { |
| | | maxX = -1.0f; |
| | | maxY = -1.0f; |
| | | } |
| | | |
| | | //3. 查找最小气体点 |
| | | if (bMinFin) { |
| | | bool bFind = false; |
| | | minGasX = MAXINT; |
| | | for (int i = 0; i < dotNum; i++) { |
| | | double dx = ptResult[i].x - minX; |
| | | double dy = ptResult[i].y - minY; |
| | | double dist = sqrt(dx * dx + dy * dy); |
| | | if (dist > fzDist) { |
| | | if (fabs(ptResult[i].cy) > gasThres && ptResult[i].x < minGasX && ptResult[i].x > minX) { |
| | | minGasX = ptResult[i].x; |
| | | minGasY = ptResult[i].y; |
| | | bFind = true; |
| | | } |
| | | } |
| | | } |
| | | if (!bFind) { |
| | | minGasX = -1.0f; |
| | | minGasY = -1.0f; |
| | | } |
| | | } |
| | | |
| | | //4. 查找最大气体点 |
| | | if (bMaxFind) { |
| | | bool bFind = false; |
| | | maxGasX = -1.0f; |
| | | for (int i = 0; i < dotNum; i++) { |
| | | double dx = ptResult[i].x - maxX; |
| | | double dy = ptResult[i].y - maxY; |
| | | double dist = sqrt(dx * dx + dy * dy); |
| | | if (dist > fzDist) { |
| | | if (fabs(ptResult[i].cy) > gasThres && ptResult[i].x > maxGasX && ptResult[i].x < maxX) { |
| | | maxGasX = ptResult[i].x; |
| | | maxGasY = ptResult[i].y; |
| | | bFind = true; |
| | | } |
| | | } |
| | | } |
| | | if (!bFind) { |
| | | maxGasX = -1.0f; |
| | | maxGasY = -1.0f; |
| | | } |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | int CInspectCamera::CutImageROI(uchar* img, DimensionDir eDim, int x1, int y1, int x2, int y2) { |
| | | /* code */ |
| | | int iScan = m_pHardparm->GetScanToDimension(eDim); |
| | | |
| | | int width = x2 - x1 + 1; |
| | | for (int i = y1; i <= y2; i++) { |
| | | LPBYTE lp = m_pGrabber->GetFrameHeaderLine(iScan, i); |
| | | std::memcpy(img+ (i-y1) * width, lp+x1, width); |
| | | } |
| | | |
| | | return 1; |
| | | } |
| | | |
| | | BOOL CInspectCamera::CheckThreadEnd(int iThread, stFrameIndex stFrame) |
| | |
| | | CSingleLock myLoc(&m_csThreadEnd); |
| | | myLoc.Lock(); |
| | | |
| | | int iScan = stFrame.nScanIdx; |
| | | int iScan = stFrame.nScanIdx; |
| | | if (m_iThreadEnd[iScan][iThread] == 1) { |
| | | myLoc.Unlock(); |
| | | return FALSE; |
| | |
| | | if (m_pII2S != NULL) { |
| | | m_pII2S->II2S_InspectionEnd(m_iCamera, iScan); |
| | | } |
| | | |
| | | // Save the image as one image |
| | | //CString strFileName; |
| | | //strFileName.Format(_T("D:\\Dump\\%s.tif"), PANEL_SIDE[emDim]); |
| | | //m_pGrabber->DumpBufferAsOneImage(iScan, strFileName); |
| | | } |
| | | } |
| | | |
| | |
| | | if (pSideData == NULL) |
| | | return FALSE; |
| | | |
| | | if (g_pStatus->GetGrabFrameCount(stFrame.nScanIdx) - 1 <= stFrame.nFrameIdx) |
| | | if (g_pStatus->GetGrabFrameCount(m_iCamera, stFrame.nScanIdx) - 1 <= stFrame.nFrameIdx) |
| | | return TRUE; |
| | | |
| | | if (pSideData->m_nPreGlassEndFrame + MAX_THREAD <= stFrame.nFrameIdx) |
| | |
| | | |
| | | void CInspectCamera::ScanRegionSet(stFrameIndex stFrame) |
| | | { |
| | | g_pLog->DisplayMessage(_T("Scan Region Set")); |
| | | |
| | | SetGrabEnd(stFrame.nScanIdx); |
| | | } |
| | | |
| | |
| | | if (pSideData->m_bTopCorner_Find == TRUE) { |
| | | localLock.Unlock(); |
| | | return TRUE; |
| | | } |
| | | |
| | | BOOL bTopCornerUse = (BOOL)(m_pRecipe->m_SideParam[emDim].m_nTopCornerShape == 0) ? FALSE : TRUE; |
| | | if (bTopCornerUse == FALSE) { |
| | | localLock.Unlock(); |
| | | return FALSE; |
| | | } |
| | | |
| | | double dCornerSizeY_Um = (double)m_pRecipe->m_SideParam[emDim].m_nTopCornerSizeY_um; |
| | |
| | | if (pSideData->m_bBotCorner_Find == TRUE) { |
| | | localLock.Unlock(); |
| | | return TRUE; |
| | | } |
| | | |
| | | BOOL bBotCornerUse = (BOOL)(m_pRecipe->m_SideParam[emDim].m_nBottomCornerShape == 0) ? FALSE : TRUE; |
| | | if (bBotCornerUse == FALSE) { |
| | | localLock.Unlock(); |
| | | return FALSE; |
| | | } |
| | | |
| | | double dCornerSizeY_Um = (double)m_pRecipe->m_SideParam[emDim].m_nBottomCornerSizeY_um; |
| | |
| | | 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); |
| | |
| | | { |
| | | 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; |
| | | } |
| | |
| | | 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; |
| | |
| | | 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; |
| | | } |
| | | |
| | |
| | | m_pRecipe = pRecipe; |
| | | m_pHardparm = pHW; |
| | | |
| | | if (m_pGrabber != NULL) |
| | | { |
| | | if (m_pGrabber != NULL) { |
| | | m_pGrabber->ClearGrabIdx(); |
| | | //m_pGrabber->ClearBuffer(); |
| | | } |
| | | |
| | | if (m_pDefectControl != NULL) |
| | | { |
| | | if (m_pDefectControl != NULL) { |
| | | m_pDefectControl->SetHWRecipe(pHW); |
| | | m_pDefectControl->ResetDefectControl(); |
| | | } |
| | |
| | | |
| | | void CInspectCamera::SetGrabEnd(int iScan) |
| | | { |
| | | g_pLog->DisplayMessage(_T("Set Grab End")); |
| | | |
| | | CCameraSettings* pCamera = m_pHardparm->GetCameraSettings(m_iCamera, iScan); |
| | | |
| | | if (pCamera == NULL) |
| | | { |
| | | if (pCamera == NULL) { |
| | | g_pLog->DisplayMessage(_T("Camera Setting NULL")); |
| | | return; |
| | | } |
| | | |
| | | DimensionDir emDim = pCamera->m_eDimension; |
| | | DimensionDir emDim = pCamera->m_eDimension; |
| | | CSide_Data* pSideData = m_pGlassData->GetSideData(emDim); |
| | | if (pSideData == NULL) |
| | | if (pSideData == NULL) { |
| | | return; |
| | | } |
| | | |
| | | int nStageNo = g_pBase->m_nStageNo; |
| | | g_pLog->DisplayMessage(_T("%s Set Grab End"), PANEL_SIDE[emDim]); |
| | | |
| | | if (nStageNo < 0 || nStageNo > 1) |
| | | int nStageNo = g_pBase->m_nStageNo; |
| | | if (nStageNo < 0 || nStageNo > 1) { |
| | | nStageNo = 0; |
| | | } |
| | | |
| | | int nGlassSize = (int)(((double)m_pRecipe->m_SideParam[(int)emDim].m_nSidePanelSize_um) / pCamera->m_dScanResolution[nStageNo]); |
| | | |
| | | pSideData->m_nPreGlassEndLine = pSideData->m_nGlassStartLine + nGlassSize; |
| | | pSideData->m_nPreGlassEndFrame = pSideData->m_nPreGlassEndLine / pCamera->m_FrameSize.cy; |
| | | |
| | | g_pStatus->SetGrabFrametoScan(iScan, pSideData->m_nPreGlassEndFrame + 5); |
| | | |
| | | g_pStatus->SetGrabFrametoScan(m_iCamera, iScan, pSideData->m_nPreGlassEndFrame + 5); |
| | | g_pLog->DisplayMessage(_T("%s Scan %d : Set Grab EndFrame - GlassEnd %d, Frame %d, GrabBuf %d"), PANEL_SIDE[emDim], iScan, pSideData->m_nPreGlassEndLine, pSideData->m_nPreGlassEndFrame, pSideData->m_nPreGlassEndFrame + 5); |
| | | } |
| | | |
| | |
| | | // 1. Find End Line.. (Corner를 제외한 Side라인을 찾기 위해 End Line부터 찾는다) |
| | | FindEndLine(iThread, emDim, stFrame); |
| | | |
| | | bool bIsRipSide = (emDim == DIMENSION_A_RIP || emDim == DIMENSION_B_RIP || emDim == DIMENSION_C_RIP || emDim == DIMENSION_D_RIP); |
| | | if (bIsRipSide) { |
| | | return TRUE; |
| | | } |
| | | |
| | | // 2. Find Side Line.. (해당 프레임에서 Corner/Notch 를 제외한 Side 라인 찾기) |
| | | #if USE_AI_DETECT |
| | | FindSideLine(iThread, emDim, stFrame); |