#include "StdAfx.h"
|
#include "DefectStorage.h"
|
#include "MulticamControl.h"
|
#include "Glass_Data.h"
|
#include "HardwareSettings.h"
|
|
CDefectStorage::CDefectStorage(void)
|
{
|
m_nDefectSpace = 0;
|
m_nDefect= m_maxDefect= 0;
|
m_pDefect= NULL;
|
}
|
|
CDefectStorage::~CDefectStorage(void)
|
{
|
if(m_pDefect)
|
delete[] m_pDefect;
|
}
|
|
void CDefectStorage::ResetDefectStorage()
|
{
|
|
// int i;
|
// if(m_pDefect != NULL)
|
// {
|
// for(i= 0; i< m_maxDefect; i++)
|
// m_pDefect[i].Reset();
|
// }
|
|
m_nDefect= 0;
|
}
|
|
|
int CDefectStorage::InitDefectStorage(int maxDefect)
|
{
|
if(maxDefect <= m_nDefectSpace)
|
{
|
m_maxDefect= maxDefect;
|
return m_maxDefect;
|
}
|
|
if(m_pDefect != NULL)
|
{
|
delete[] m_pDefect;
|
}
|
|
// 16°³ÀÇ ¿©ºÐÀ» µÐ´Ù..¿Ö? ³»¸É..
|
int DefectSapce= maxDefect+ 16;
|
m_pDefect= new CDefect[DefectSapce];
|
|
if(m_pDefect == NULL)
|
{
|
m_maxDefect= m_nDefectSpace= 0;
|
return m_maxDefect;
|
}
|
|
|
m_maxDefect= m_nDefectSpace= maxDefect;
|
|
|
return m_maxDefect;
|
}
|
|
void CDefectStorage::CheckDefectRect(CPoint* pVertex, CRect* pRect, int nX, int nY)
|
{
|
if (!pVertex || !pRect)
|
return;
|
|
// Rect
|
if (nY <= pRect->top)
|
{
|
pRect->top = nY;
|
if (pVertex[2].y == nY) // Top Left
|
{
|
if (nX < pVertex[2].x)
|
{
|
pVertex[2].x = nX;
|
pVertex[2].y = nY;
|
}
|
}
|
else
|
{
|
pVertex[2].x = nX;
|
pVertex[2].y = nY;
|
}
|
if (pVertex[3].y == nY) // Top Right
|
{
|
if (nX + 1 > pVertex[3].x)
|
{
|
pVertex[3].x = nX + 1;
|
pVertex[3].y = nY;
|
}
|
}
|
else
|
{
|
pVertex[3].x = nX + 1;
|
pVertex[3].y = nY;
|
}
|
}
|
if (nY + 1 >= pRect->bottom)
|
{
|
pRect->bottom = nY + 1;
|
if (pVertex[6].y == nY + 1) // Bottom Left
|
{
|
if (nX < pVertex[6].x)
|
{
|
pVertex[6].x = nX;
|
pVertex[6].y = nY + 1;
|
}
|
}
|
else
|
{
|
pVertex[6].x = nX;
|
pVertex[6].y = nY + 1;
|
}
|
if (pVertex[7].y == nY + 1) // Bottom Right
|
{
|
if (nX + 1 > pVertex[7].x)
|
{
|
pVertex[7].x = nX + 1;
|
pVertex[7].y = nY + 1;
|
}
|
}
|
else
|
{
|
pVertex[7].x = nX + 1;
|
pVertex[7].y = nY + 1;
|
}
|
}
|
if (nX <= pRect->left)
|
{
|
pRect->left = nX;
|
if (pVertex[1].x == nX) // Left Bottom
|
{
|
if (nY + 1 > pVertex[1].y)
|
{
|
pVertex[1].x = nX;
|
pVertex[1].y = nY + 1;
|
}
|
}
|
else
|
{
|
pVertex[1].x = nX;
|
pVertex[1].y = nY + 1;
|
}
|
if (pVertex[0].x == nX) // Left Top
|
{
|
if (nY < pVertex[0].y)
|
{
|
pVertex[0].x = nX;
|
pVertex[0].y = nY;
|
}
|
}
|
else
|
{
|
pVertex[0].x = nX;
|
pVertex[0].y = nY;
|
}
|
}
|
if (nX + 1 >= pRect->right)
|
{
|
pRect->right = nX + 1;
|
if (pVertex[5].x == nX + 1) // Right Bottom
|
{
|
if (nY + 1 > pVertex[5].y)
|
{
|
pVertex[5].x = nX + 1;
|
pVertex[5].y = nY + 1;
|
}
|
}
|
else
|
{
|
pVertex[5].x = nX + 1;
|
pVertex[5].y = nY + 1;
|
}
|
if (pVertex[4].x == nX + 1) // Right Top
|
{
|
if (nY < pVertex[4].y)
|
{
|
pVertex[4].x = nX + 1;
|
pVertex[4].y = nY;
|
}
|
}
|
else
|
{
|
pVertex[4].x = nX + 1;
|
pVertex[4].y = nY;
|
}
|
}
|
}
|
|
int CDefectStorage::StopInspection(CAssemControl *pAssemControl)
|
{
|
return 0;
|
}
|
|
void CDefectStorage::SetBlobDefect( int i )
|
{
|
|
}
|
|
CDefectControl::CDefectControl()
|
{
|
m_pGrabber = NULL;
|
m_pGlassData = NULL;
|
m_pHWRecipe = NULL;
|
ResetDefectControl();
|
}
|
|
CDefectControl::~CDefectControl()
|
{
|
|
}
|
|
void CDefectControl::ResetDefectControl()
|
{
|
CDefectStorage::ResetDefectStorage();
|
}
|
|
int CDefectControl::CheckDefectCount()
|
{
|
if(m_nDefect >= m_maxDefect)
|
return DIT_CONV_GLASSOVERFLOW;
|
|
return DIT_CONV_SUCCESS;
|
}
|
|
int CDefectControl::ExtractDefect_ProfileChamfer(DimensionDir emDim,int iCam,int iScan,DefectLocation nDefectLoc,CvPoint2D32f ptDefect,int nProfileIndex)
|
{
|
if(m_pGrabber == NULL)
|
return m_nDefect;
|
|
CSingleLock MyLock(&m_csDefect);
|
MyLock.Lock();
|
|
if(m_nDefect >= m_maxDefect)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
CRect rectDefect;
|
CDefect *pDefect=NULL;
|
|
pDefect = GetDefect(m_nDefect);
|
if(pDefect == NULL)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
pDefect->Reset();
|
|
int nGlassStart = 0;
|
|
if(m_pGlassData != NULL)
|
{
|
INS_EDGE_RESULT_INFO *pEdgeInfo = m_pGlassData->GetEdgeResultInfo(emDim);
|
if(pEdgeInfo != NULL)
|
{
|
nGlassStart = pEdgeInfo->nGlassStartLine;
|
}
|
}
|
|
CAMERA_DIR eCamDir = CAMDIR_NONE;
|
int nFrameWidth = 0;
|
if(m_pHWRecipe != NULL)
|
{
|
CCameraSettings *pCamera = m_pHWRecipe->GetCameraSettings(iCam,iScan);
|
if(pCamera != NULL)
|
{
|
eCamDir = pCamera->m_enCamDir;
|
nFrameWidth = pCamera->m_FrameSize.cx;
|
}
|
}
|
|
rectDefect = CRect((int)ptDefect.x,(int)ptDefect.y,(int)ptDefect.x,(int)ptDefect.y);
|
rectDefect.InflateRect(5,5);
|
|
pDefect->m_nGlassStartLine = nGlassStart;
|
pDefect->m_nIndex = m_nDefect;
|
pDefect->m_nCamID = iCam;
|
pDefect->m_nScanIdx = iScan;
|
pDefect->m_DefectLoc = nDefectLoc;
|
pDefect->m_nSideLoc = (int)emDim;
|
pDefect->m_nCamDir = (int)eCamDir;
|
pDefect->m_nProfileIndex = nProfileIndex;
|
|
pDefect->m_Defect.s_nDefectRScale = rectDefect.Width()*rectDefect.Height();
|
|
pDefect->m_Defect.s_DefectRect = rectDefect;
|
pDefect->m_Defect.s_nDefectX = (int)ptDefect.x;
|
pDefect->m_Defect.s_nDefectY = (int)ptDefect.y;
|
|
if(pDefect->m_Defect.s_DefectRect.left < 0 || pDefect->m_Defect.s_DefectRect.right >= nFrameWidth
|
|| pDefect->m_Defect.s_DefectRect.top < 0)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
if(m_pGrabber->GetSmallImage(iScan,pDefect->m_Image
|
, pDefect->m_Defect.s_nDefectX - DEFECTIMAGE_WIDTH / 2
|
, pDefect->m_Defect.s_nDefectY - DEFECTIMAGE_HEIGHT / 2
|
, DEFECTIMAGE_WIDTH, DEFECTIMAGE_HEIGHT, FALSE) == FALSE)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
if(nDefectLoc == DefectLoc_Chamfer)
|
g_pLog->DisplayMessage(_T("%s Chamfer Defect Pos[%d,%d]"),PANEL_SIDE[emDim],pDefect->m_Defect.s_nDefectX,pDefect->m_Defect.s_nDefectY);
|
else
|
g_pLog->DisplayMessage(_T("%s Profile Defect Pos[%d,%d]"),PANEL_SIDE[emDim],pDefect->m_Defect.s_nDefectX,pDefect->m_Defect.s_nDefectY);
|
|
m_nDefect++;
|
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
int CDefectControl::ExtractDefect_Hole(DimensionDir emDim,int iCam,int iScan,std::vector<CRect> &vecList,int nDefectCount,DefectLocation nDefectLoc,CRect rectIns)
|
{
|
if(m_pGrabber == NULL)
|
return m_nDefect;
|
|
CSingleLock MyLock(&m_csDefect);
|
MyLock.Lock();
|
if(m_nDefect >= m_maxDefect)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
int iDefect;
|
CRect rectDefect;
|
CDefect *pDefect=NULL;
|
|
int nGlassStart = 0;
|
|
if(m_pGlassData != NULL)
|
{
|
INS_EDGE_RESULT_INFO *pEdgeInfo = m_pGlassData->GetEdgeResultInfo(emDim);
|
if(pEdgeInfo != NULL)
|
{
|
nGlassStart = pEdgeInfo->nGlassStartLine;
|
}
|
}
|
|
CAMERA_DIR eCamDir = CAMDIR_NONE;
|
int nFrameWidth = 0;
|
if(m_pHWRecipe != NULL)
|
{
|
CCameraSettings *pCamera = m_pHWRecipe->GetCameraSettings(iCam,iScan);
|
if(pCamera != NULL)
|
{
|
eCamDir = pCamera->m_enCamDir;
|
nFrameWidth = pCamera->m_FrameSize.cx;
|
}
|
}
|
|
for(iDefect=0;iDefect<nDefectCount;iDefect++)
|
{
|
if(m_nDefect >= m_maxDefect)
|
break;
|
|
pDefect = GetDefect(m_nDefect);
|
if(pDefect == NULL)
|
break;
|
|
pDefect->Reset();
|
|
rectDefect = vecList[iDefect];
|
|
pDefect->m_nGlassStartLine = nGlassStart;
|
pDefect->m_nIndex = m_nDefect;
|
pDefect->m_nCamID = iCam;
|
pDefect->m_nScanIdx = iScan;
|
pDefect->m_DefectLoc = nDefectLoc;
|
pDefect->m_nSideLoc = (int)emDim;
|
pDefect->m_nCamDir = (int)eCamDir;
|
|
pDefect->m_Defect.s_nDefectRScale = rectDefect.Width()*rectDefect.Height();
|
|
pDefect->m_Defect.s_DefectRect = rectDefect;
|
pDefect->m_Defect.s_DefectRect.OffsetRect(rectIns.left,rectIns.top);
|
|
pDefect->m_Defect.s_nDefectX = rectDefect.left;
|
pDefect->m_Defect.s_nDefectY = rectDefect.top;
|
pDefect->m_Defect.s_nDefectY += rectIns.top;
|
pDefect->m_Defect.s_nDefectX += rectIns.left;
|
pDefect->m_Defect.s_nDefectArea = rectDefect.Width() * rectDefect.Height();
|
|
if(pDefect->m_Defect.s_DefectRect.left < 0 || pDefect->m_Defect.s_DefectRect.right >= nFrameWidth
|
|| pDefect->m_Defect.s_DefectRect.top < 0)
|
continue;
|
|
if(m_pGrabber->GetSmallImage(iScan,pDefect->m_Image
|
, pDefect->m_Defect.s_nDefectX - DEFECTIMAGE_WIDTH / 2
|
, pDefect->m_Defect.s_nDefectY - DEFECTIMAGE_HEIGHT / 2
|
, DEFECTIMAGE_WIDTH, DEFECTIMAGE_HEIGHT, FALSE) == FALSE)
|
continue;
|
|
g_pLog->DisplayMessage(_T("%s Hole Defect Pos[%d,%d]"),PANEL_SIDE[eCamDir],pDefect->m_Defect.s_nDefectX,pDefect->m_Defect.s_nDefectY);
|
|
m_nDefect++;
|
}
|
|
MyLock.Unlock();
|
|
return m_nDefect;
|
}
|
|
int CDefectControl::ExtractDefect_NotchChip(DimensionDir emDim,int iCam,int iScan,CChipBlob *pBlobStorage,int nDefectCount,DefectLocation nDefectLoc,CRect rectIns)
|
{
|
if(m_pGrabber == NULL)
|
return m_nDefect;
|
|
CSingleLock MyLock(&m_csDefect);
|
MyLock.Lock();
|
|
if(m_nDefect >= m_maxDefect)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
int iDefect;
|
CChipBlob *pBlob;
|
CDefect *pDefect=NULL;
|
|
int nGlassStart = 0;
|
|
if(m_pGlassData != NULL)
|
{
|
INS_EDGE_RESULT_INFO *pEdgeInfo = m_pGlassData->GetEdgeResultInfo(emDim);
|
if(pEdgeInfo != NULL)
|
{
|
nGlassStart = pEdgeInfo->nGlassStartLine;
|
}
|
}
|
|
CAMERA_DIR eCamDir = CAMDIR_NONE;
|
int nFrameWidth = 0;
|
if(m_pHWRecipe != NULL)
|
{
|
CCameraSettings *pCamera = m_pHWRecipe->GetCameraSettings(iCam,iScan);
|
if(pCamera != NULL)
|
{
|
eCamDir = pCamera->m_enCamDir;
|
nFrameWidth = pCamera->m_FrameSize.cx;
|
}
|
}
|
|
for(iDefect=0;iDefect<nDefectCount;iDefect++)
|
{
|
if(m_nDefect >= m_maxDefect)
|
break;
|
|
pBlob = &pBlobStorage[iDefect];
|
if(pBlob == NULL)
|
continue;
|
|
if(pBlob->s_DefectType == DEFTYPE_NODEFECT || pBlob->s_bRemoved == TRUE)
|
continue;
|
|
pDefect = GetDefect(m_nDefect);
|
if(pDefect == NULL)
|
break;
|
|
pDefect->Reset();
|
|
pDefect->m_nGlassStartLine = nGlassStart;
|
pDefect->m_nIndex = m_nDefect;
|
pDefect->m_nCamID = iCam;
|
pDefect->m_nScanIdx = iScan;
|
pDefect->m_DefectLoc = nDefectLoc;
|
pDefect->m_nSideLoc = (int)emDim;
|
pDefect->m_nCamDir = (int)eCamDir;
|
|
CopyChipToBlob(pBlob,&pDefect->m_Defect);
|
|
pDefect->m_Defect.s_DefectRect.OffsetRect(rectIns.left,rectIns.top);
|
pDefect->m_Defect.s_nDefectY += rectIns.top;
|
pDefect->m_Defect.s_nDefectX += rectIns.left;
|
|
if(pDefect->m_Defect.s_DefectRect.left < 0 || pDefect->m_Defect.s_DefectRect.right >= nFrameWidth
|
|| pDefect->m_Defect.s_DefectRect.top < 0)
|
continue;
|
|
if(m_pGrabber->GetSmallImage(iScan,pDefect->m_Image
|
, pDefect->m_Defect.s_nDefectX - DEFECTIMAGE_WIDTH / 2
|
, pDefect->m_Defect.s_nDefectY - DEFECTIMAGE_HEIGHT / 2
|
, DEFECTIMAGE_WIDTH, DEFECTIMAGE_HEIGHT, FALSE) == FALSE)
|
continue;
|
|
g_pLog->DisplayMessage(_T("%s Notch Defect Loc[%d] Pos[%d,%d]"),PANEL_SIDE[emDim],pDefect->m_nSplineLoc,pDefect->m_Defect.s_nDefectX,pDefect->m_Defect.s_nDefectY);
|
|
m_nDefect++;
|
}
|
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
int CDefectControl::ExtractDefect_SplineChip(DimensionDir emDim,int iCam,int iScan,CChipBlob *pBlobStorage,int nDefectCnt,DefectLocation nDefectLoc,CPoint basePos,int nSplineType,BOOL bFlip,int nChipW,int nChipH,EM_CHIPPING_COMP eComp)
|
{
|
if(m_pGrabber == NULL)
|
return m_nDefect;
|
|
CSingleLock MyLock(&m_csDefect);
|
MyLock.Lock();
|
|
if(m_nDefect >= m_maxDefect)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
std::vector<CChipBlob*>::iterator it;
|
CChipBlob *pBlob;
|
CDefect *pDefect=NULL;
|
const int nDetYPosition = 2;
|
int iDefect;
|
int nMinWidthSize = 2;
|
|
int nGlassStart = 0;
|
|
if(m_pGlassData != NULL)
|
{
|
INS_EDGE_RESULT_INFO *pEdgeInfo = m_pGlassData->GetEdgeResultInfo(emDim);
|
if(pEdgeInfo != NULL)
|
{
|
nGlassStart = pEdgeInfo->nGlassStartLine;
|
}
|
}
|
|
CAMERA_DIR eCamDir = CAMDIR_NONE;
|
int nFrameWidth = 0;
|
if(m_pHWRecipe != NULL)
|
{
|
CCameraSettings *pCamera = m_pHWRecipe->GetCameraSettings(iCam,iScan);
|
if(pCamera != NULL)
|
{
|
eCamDir = pCamera->m_enCamDir;
|
nFrameWidth = pCamera->m_FrameSize.cx;
|
}
|
}
|
|
for(iDefect=0;iDefect<nDefectCnt;iDefect++)
|
{
|
if(m_nDefect >= m_maxDefect)
|
break;
|
|
pBlob = &pBlobStorage[iDefect];
|
if(pBlob == NULL)
|
continue;
|
|
if(pBlob->s_DefectType == DEFTYPE_NODEFECT || pBlob->s_bRemoved == TRUE || pBlob->s_DefectRect.Width() <= nMinWidthSize)
|
continue;
|
|
pDefect = GetDefect(m_nDefect);
|
if(pDefect == NULL)
|
break;
|
|
pDefect->Reset();
|
|
pDefect->m_nGlassStartLine = nGlassStart;
|
pDefect->m_nIndex = m_nDefect;
|
pDefect->m_nCamID = iCam;
|
pDefect->m_nScanIdx = iScan;
|
pDefect->m_DefectLoc = nDefectLoc;
|
pDefect->m_nSideLoc = (int)emDim;
|
pDefect->m_nCamDir = (int)eCamDir;
|
|
if(nSplineType == 0)
|
{
|
if(bFlip == FALSE)
|
pDefect->m_nSplineLoc = Spline_BotRight;
|
else
|
pDefect->m_nSplineLoc = Spline_BotLeft;
|
}
|
else
|
{
|
if(bFlip == FALSE)
|
pDefect->m_nSplineLoc = Spline_TopRight;
|
else
|
pDefect->m_nSplineLoc = Spline_TopLeft;
|
}
|
|
CopyChipToBlob(pBlob,&pDefect->m_Defect);
|
|
pDefect->m_Defect.s_DefectRect.OffsetRect(basePos.x,basePos.y);
|
pDefect->m_Defect.s_nDefectY += basePos.y;
|
pDefect->m_Defect.s_nDefectX += basePos.x;
|
|
if(pDefect->m_Defect.s_DefectRect.left < 0 || pDefect->m_Defect.s_DefectRect.right >= nFrameWidth
|
|| pDefect->m_Defect.s_DefectRect.top < 0)
|
continue;
|
|
if(m_pGrabber->GetSmallImage(iScan,pDefect->m_Image
|
, pDefect->m_Defect.s_nDefectX - DEFECTIMAGE_WIDTH / 2
|
, pDefect->m_Defect.s_nDefectY - DEFECTIMAGE_HEIGHT / 2
|
, DEFECTIMAGE_WIDTH, DEFECTIMAGE_HEIGHT, FALSE) == FALSE)
|
continue;
|
|
g_pLog->DisplayMessage(_T("%s Spline Defect Loc[%d] Pos[%d,%d]"),PANEL_SIDE[emDim],pDefect->m_nSplineLoc,pDefect->m_Defect.s_nDefectX,pDefect->m_Defect.s_nDefectY-nGlassStart);
|
|
m_nDefect++;
|
}
|
|
MyLock.Unlock();
|
|
return m_nDefect;
|
}
|
|
int CDefectControl::ExtractDefect_SpNew(DimensionDir emDim,int iCam,int iScan,DefectLocation eDefect,CvPoint2D32f ptDefect,int nSplineType,BOOL bFlip,int nDefectArea)
|
{
|
CSingleLock MyLock(&m_csDefect);
|
MyLock.Lock();
|
|
if(m_nDefect >= m_maxDefect)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
CRect rectDefect;
|
CDefect *pDefect=NULL;
|
|
int nGlassStart = 0;
|
|
if(m_pGlassData != NULL)
|
{
|
INS_EDGE_RESULT_INFO *pEdgeInfo = m_pGlassData->GetEdgeResultInfo(emDim);
|
if(pEdgeInfo != NULL)
|
{
|
nGlassStart = pEdgeInfo->nGlassStartLine;
|
}
|
}
|
|
CAMERA_DIR eCamDir = CAMDIR_NONE;
|
int nFrameWidth = 0;
|
if(m_pHWRecipe != NULL)
|
{
|
CCameraSettings *pCamera = m_pHWRecipe->GetCameraSettings(iCam,iScan);
|
if(pCamera != NULL)
|
{
|
eCamDir = pCamera->m_enCamDir;
|
nFrameWidth = pCamera->m_FrameSize.cx;
|
}
|
}
|
|
pDefect = GetDefect(m_nDefect);
|
if(pDefect == NULL)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
pDefect->Reset();
|
|
rectDefect = CRect((int)ptDefect.x,(int)ptDefect.y,(int)ptDefect.x,(int)ptDefect.y);
|
rectDefect.InflateRect(5,5);
|
|
pDefect->m_nGlassStartLine = nGlassStart;
|
pDefect->m_nIndex = m_nDefect;
|
pDefect->m_nCamID = iCam;
|
pDefect->m_nScanIdx = iScan;
|
pDefect->m_DefectLoc = eDefect;
|
pDefect->m_nSideLoc = (int)emDim;
|
pDefect->m_nCamDir = (int)eCamDir;
|
|
pDefect->m_Defect.s_nDefectRScale = rectDefect.Width()*rectDefect.Height();
|
|
pDefect->m_Defect.s_DefectRect = rectDefect;
|
pDefect->m_Defect.s_nDefectX = (int)ptDefect.x;
|
pDefect->m_Defect.s_nDefectY = (int)ptDefect.y;
|
pDefect->m_Defect.s_nDefectArea = nDefectArea;
|
|
if(nSplineType == 0)
|
{
|
if(bFlip == FALSE)
|
pDefect->m_nSplineLoc = Spline_BotRight;
|
else
|
pDefect->m_nSplineLoc = Spline_BotLeft;
|
}
|
else
|
{
|
if(bFlip == FALSE)
|
pDefect->m_nSplineLoc = Spline_TopRight;
|
else
|
pDefect->m_nSplineLoc = Spline_TopLeft;
|
}
|
|
if(m_pGrabber->GetSmallImage(iScan,pDefect->m_Image
|
, pDefect->m_Defect.s_nDefectX - DEFECTIMAGE_WIDTH / 2
|
, pDefect->m_Defect.s_nDefectY - DEFECTIMAGE_HEIGHT / 2
|
, DEFECTIMAGE_WIDTH, DEFECTIMAGE_HEIGHT, FALSE) == FALSE)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
m_nDefect++;
|
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
int CDefectControl::ExtractDefect_Chip(DimensionDir emDim,int iCam,int iScan,CChipBlob *pCBlob,int nDefect,DefectLocation eDefect,int iFrameV)
|
{
|
if(m_pGrabber == NULL)
|
return m_nDefect;
|
|
CSingleLock MyLock(&m_csDefect);
|
MyLock.Lock();
|
|
if(m_nDefect >= m_maxDefect)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
CChipBlob *pBlob;
|
CDefect *pDefect=NULL;
|
const int nMinWidthSize = 2;
|
|
int nGlassStart = 0;
|
|
if(m_pGlassData != NULL)
|
{
|
INS_EDGE_RESULT_INFO *pEdgeInfo = m_pGlassData->GetEdgeResultInfo(emDim);
|
if(pEdgeInfo != NULL)
|
{
|
nGlassStart = pEdgeInfo->nGlassStartLine;
|
}
|
}
|
|
CAMERA_DIR eCamDir = CAMDIR_NONE;
|
int nFrameWidth = 0;
|
if(m_pHWRecipe != NULL)
|
{
|
CCameraSettings *pCamera = m_pHWRecipe->GetCameraSettings(iCam,iScan);
|
if(pCamera != NULL)
|
{
|
eCamDir = pCamera->m_enCamDir;
|
nFrameWidth = pCamera->m_FrameSize.cx;
|
}
|
}
|
|
for(int iDefect=0;iDefect<nDefect;iDefect++)
|
{
|
pBlob = &pCBlob[iDefect];
|
if(pBlob == NULL)
|
continue;
|
|
if(m_nDefect >= m_maxDefect)
|
break;
|
|
if(pBlob->s_DefectType == DEFTYPE_NODEFECT || pBlob->s_bRemoved == TRUE)// || pBlob->s_DefectRect.Width() <= nMinWidthSize)
|
continue;
|
|
pDefect = GetDefect(m_nDefect);
|
if(pDefect == NULL)
|
break;
|
|
pDefect->Reset();
|
|
switch(pBlob->s_DefectJudgeType)
|
{
|
case INS_DEFECT_CHIP:
|
pDefect->m_DefectLoc = DefectLoc_Chip;
|
break;
|
case INS_DEFECT_BURR:
|
pDefect->m_DefectLoc = DefectLoc_Burr;
|
break;
|
case INS_DEFECT_CRACK:
|
pDefect->m_DefectLoc = DefectLoc_Crack;
|
break;
|
case INS_DEFECT_BROKEN:
|
pDefect->m_DefectLoc = DefectLoc_Broken;
|
break;
|
default:
|
pDefect->m_DefectLoc = eDefect;
|
break;
|
}
|
|
pDefect->m_nGlassStartLine = nGlassStart;
|
pDefect->m_nIndex = m_nDefect;
|
pDefect->m_nCamID = iCam;
|
pDefect->m_nScanIdx = iScan;
|
pDefect->m_nSideLoc = (int)emDim;
|
pDefect->m_nCamDir = (int)eCamDir;
|
|
CopyChipToBlob(pBlob,&pDefect->m_Defect);
|
|
pDefect->m_Defect.s_nDefectY += iFrameV;
|
pDefect->m_Defect.s_nDefectX += 0;
|
pDefect->m_Defect.s_DefectRect.OffsetRect(0,iFrameV);
|
|
if(m_pGrabber->GetSmallImage(iScan,pDefect->m_Image
|
, pDefect->m_Defect.s_nDefectX - DEFECTIMAGE_WIDTH / 2
|
, pDefect->m_Defect.s_nDefectY - DEFECTIMAGE_HEIGHT / 2
|
, DEFECTIMAGE_WIDTH, DEFECTIMAGE_HEIGHT, FALSE) == FALSE)
|
continue;
|
|
m_nDefect++;
|
}
|
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
int CDefectControl::ExtractDefect_KDist(DimensionDir emDim, int iCam, int iScan, DefectLocation eDefect, CvPoint2D32f ptDefect, CRect rectDefect, int nProfileIndex)
|
{
|
if (m_pGrabber == NULL)
|
return m_nDefect;
|
|
CSingleLock MyLock(&m_csDefect);
|
MyLock.Lock();
|
|
if (m_nDefect >= m_maxDefect)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
//Rect rectDefect;
|
CDefect* pDefect = NULL;
|
|
pDefect = GetDefect(m_nDefect);
|
if (pDefect == NULL)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
pDefect->Reset();
|
|
int nGlassStart = 0;
|
|
if (m_pGlassData != NULL)
|
{
|
INS_EDGE_RESULT_INFO* pEdgeInfo = m_pGlassData->GetEdgeResultInfo(emDim);
|
if (pEdgeInfo != NULL)
|
{
|
nGlassStart = pEdgeInfo->nGlassStartLine;
|
}
|
}
|
|
CAMERA_DIR eCamDir = CAMDIR_NONE;
|
int nFrameWidth = 0;
|
if (m_pHWRecipe != NULL)
|
{
|
CCameraSettings* pCamera = m_pHWRecipe->GetCameraSettings(iCam, iScan);
|
if (pCamera != NULL)
|
{
|
eCamDir = pCamera->m_enCamDir;
|
nFrameWidth = pCamera->m_FrameSize.cx;
|
}
|
}
|
|
//rectDefect = CRect((int)ptDefect.x, (int)ptDefect.y, (int)ptDefect.x, (int)ptDefect.y);
|
//rectDefect.InflateRect(25, 25);
|
|
pDefect->m_nGlassStartLine = nGlassStart;
|
pDefect->m_nIndex = m_nDefect;
|
pDefect->m_nCamID = iCam;
|
pDefect->m_nScanIdx = iScan;
|
pDefect->m_DefectLoc = eDefect;
|
pDefect->m_nSideLoc = (int)emDim;
|
pDefect->m_nCamDir = (int)eCamDir;
|
pDefect->m_nProfileIndex = nProfileIndex;
|
|
pDefect->m_Defect.s_nDefectRScale = rectDefect.Width() * rectDefect.Height();
|
|
pDefect->m_Defect.s_DefectRect = rectDefect;
|
pDefect->m_Defect.s_nDefectX = (int)ptDefect.x;
|
pDefect->m_Defect.s_nDefectY = (int)ptDefect.y;
|
|
if (pDefect->m_Defect.s_DefectRect.left < 0 || pDefect->m_Defect.s_DefectRect.right >= nFrameWidth
|
|| pDefect->m_Defect.s_DefectRect.top < 0)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
if (m_pGrabber->GetSmallImage(iScan, pDefect->m_Image
|
, pDefect->m_Defect.s_nDefectX - DEFECTIMAGE_WIDTH / 2
|
, pDefect->m_Defect.s_nDefectY - DEFECTIMAGE_HEIGHT / 2
|
, DEFECTIMAGE_WIDTH, DEFECTIMAGE_HEIGHT, FALSE) == FALSE)
|
{
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
m_nDefect++;
|
MyLock.Unlock();
|
return m_nDefect;
|
}
|
|
void CDefectControl::CopyChipToBlob(CChipBlob *pChip,CDefectBlob *pBlob)
|
{
|
pBlob->s_DefectPair = (DefectPair)pChip->s_DefectPair;
|
pBlob->s_DefectType = (DefectType)pChip->s_DefectType;
|
pBlob->s_nIndex = pChip->s_nIndex;
|
pBlob->s_nDefectArea = pChip->s_nDefectArea;
|
pBlob->s_nDefectX = pChip->s_nDefectX;
|
pBlob->s_nDefectY = pChip->s_nDefectY;
|
pBlob->s_nDefectRScale = pChip->s_nDefectRScale;
|
pBlob->s_DefectRect = pChip->s_DefectRect;
|
pBlob->s_sDefectPeak = pChip->s_sDefectPeak;
|
|
pBlob->s_sLevelSrcMin = pChip->s_sLevelSrcMin;
|
pBlob->s_sLevelSrcMax = pChip->s_sLevelSrcMax;
|
pBlob->s_xLevelSrcMax = pChip->s_xLevelSrcMax;
|
pBlob->s_yLevelSrcMax = pChip->s_yLevelSrcMax;
|
pBlob->s_sLevelSrcAvg = pChip->s_sLevelSrcAvg;
|
pBlob->s_sLevelRefMin = pChip->s_sLevelRefMin;
|
pBlob->s_sLevelRefMax = pChip->s_sLevelRefMax;
|
pBlob->s_sLevelRefAvg = pChip->s_sLevelRefAvg;
|
pBlob->s_sLevelDiffMin = pChip->s_sLevelDiffMin;
|
pBlob->s_sLevelDiffMax = pChip->s_sLevelDiffMax;
|
pBlob->s_sLevelDiffAvg = pChip->s_sLevelDiffAvg;
|
pBlob->s_nLevelSrcSum = pChip->s_nLevelSrcSum;
|
pBlob->s_nLevelRefSum = pChip->s_nLevelRefSum;
|
pBlob->s_nLevelDiffSum = pChip->s_nLevelDiffSum;
|
|
pBlob->s_sThreshold = pChip->s_sThreshold;
|
|
int i;
|
#define MOSIS_EDIT_VERTEX
|
for(i= 0; i< 8; i++)
|
{
|
pBlob->s_ptVertex[i]= pChip->s_ptVertex[i];
|
}
|
pBlob->s_bRemoved = pChip->s_bRemoved;
|
}
|