#if !defined(AFX_CHAMFERINSPECT_H_INCLUDED_)
|
#define AFX_CHAMFERINSPECT_H_INCLUDED_
|
|
#if _MSC_VER > 1000
|
#pragma once
|
#endif // _MSC_VER > 1000
|
// ChamferInspect.h : header file
|
//
|
#include <list>
|
#include <vector>
|
#include "EDGE_DIPM.h"
|
|
#include <opencv.hpp>
|
#include <highgui.hpp>
|
#include <core.hpp>
|
#include <imgproc.hpp>
|
|
|
//Search data
|
#ifndef _GLASSFINDDATA_
|
#define _GLASSFINDDATA_
|
typedef struct GlassFindData{
|
int *pPos;
|
int nPosCnt;
|
short nWidth;
|
|
GlassFindData()
|
{
|
pPos = NULL;
|
Reset();
|
}
|
void Reset()
|
{
|
nWidth = 0;
|
nPosCnt = 0;
|
if(pPos != NULL)
|
delete[] pPos, pPos = NULL;
|
}
|
GlassFindData& operator=(const GlassFindData &rh)
|
{
|
Reset();
|
nPosCnt = rh.nPosCnt;
|
nWidth = rh.nWidth;
|
|
if(nPosCnt > 0)
|
{
|
pPos = new int[nPosCnt];
|
CopyMemory(pPos,rh.pPos,sizeof(int)*nPosCnt);
|
}
|
return *this;
|
}
|
void GetMinMaxPos(int &nMin,int &nMax)
|
{
|
nMin = INT_MAX;
|
nMax = 0;
|
|
if(pPos == NULL || nPosCnt <= 0)
|
return;
|
|
int iLoop,nValue;
|
for(iLoop=0;iLoop<nPosCnt;iLoop++)
|
{
|
nValue = pPos[iLoop];
|
if(nMin > nValue) nMin = nValue;
|
if(nMax < nValue) nMax = nValue;
|
}
|
}
|
} GLASSFINDDATA, *LGLASSFINDDATA;
|
#endif
|
|
#ifndef _EDGE_POS_
|
#define _EDGE_POS_
|
typedef struct EdgePos{
|
double dLeft;
|
double dRight;
|
int nPos;
|
|
void Reset()
|
{
|
dLeft = dRight = 0;
|
nPos = 0;
|
}
|
} EDGEPOS, *LEDGEPOS;
|
#endif
|
|
typedef struct _STU_CHIPPINGINS_EXP_POS
|
{
|
int nSide;
|
int nPosY;
|
int nSize;
|
int nERType;//130115
|
int nPosX;//130115
|
int nSizeX;//130115
|
|
_STU_CHIPPINGINS_EXP_POS()
|
{
|
Reset();
|
}
|
void Reset()
|
{
|
nSide = 4;
|
nPosY = nSize = 0;
|
nERType = 2;//130115
|
nPosX = nSizeX = 0;//130115
|
}
|
|
} STU_CHIPPINGINS_EXP_POS, *pSTU_CHIPPINGINS_EXP_POS;
|
|
typedef struct _STU_EXTRA_POLY
|
{
|
int nSL,nST;
|
int nEL,nEB;
|
int nTheHeight;
|
double dTheta;
|
|
_STU_EXTRA_POLY()
|
{
|
Reset();
|
}
|
void Reset()
|
{
|
nSL = nST = nEL = nEB = nTheHeight = 0;
|
dTheta = 0.;
|
}
|
|
} STU_EXTRA_POLY, *pSTU_EXTRA_POLY;
|
|
/////////////////////////////////////////////////////////////////////////////
|
// CChamferInspect window
|
|
enum ChipErrCode {ERR_CHIP_SUCCESS = 0, ERR_CHIP_IMAGE_NULL_01,ERR_CHIP_IMAGE_NULL_02,ERR_CHIP_IMAGE_NULL_03,ERR_CHIP_PREPROCESS,
|
ERR_CHIP_FIND_FORELINE, ERR_CHIP_FIND_RIGHTLINE,ERR_CHIP_SUBPIXEL,ERR_CHIP_CHECK_CHIPRECT};
|
|
enum ChipThresMode {THRESMODE_FIXED=0,THRESMODE_ADAPTIVE,THRESMODE_ADAPTIVE_MAX};
|
|
#define MAX_CHIP_DEFECT_COUNT 1000
|
#define MAX_CHIP_PAIR_DEFECT_COUNT 20000
|
|
typedef struct _InspectParam
|
{
|
BOOL bUse_ChipIns;
|
BOOL bUse_CrackIns;
|
BOOL bUse_BrokenIns;
|
BOOL bUse_BurrIns;
|
|
int nChipThres;
|
int nChipDiffThres;
|
int nCrackThres;
|
int nBrokenThres;
|
int nBurrThres;
|
|
int nChipMinSize;
|
int nCrackMinSize;
|
int nBrokenMinSize;
|
int nBurrMinSize;
|
|
int nChipSideFilterSize;
|
int nCrackSideFilterSize;
|
int nBrokenSideFilterSize;
|
int nBurrSideFilterSize;
|
|
_InspectParam()
|
{
|
Reset();
|
}
|
void Reset()
|
{
|
bUse_ChipIns = bUse_CrackIns = bUse_BrokenIns = bUse_BurrIns = FALSE;
|
|
nChipThres = 15;
|
nChipDiffThres = 30;
|
nCrackThres = 15;
|
nBrokenThres = 15;
|
nBurrThres = 15;
|
|
nChipMinSize = nCrackMinSize = nBrokenMinSize = nBurrMinSize = 5;
|
|
nChipSideFilterSize = nCrackSideFilterSize = nBrokenSideFilterSize = nBurrSideFilterSize = 10;
|
}
|
|
} InspectParam, *pInspectParam;
|
|
class AFX_EXT_CLASS CChamferInspect
|
{
|
// Construction
|
public:
|
CChamferInspect();
|
virtual ~CChamferInspect();
|
|
// Chamfer & Chip
|
public:
|
ChipErrCode Inspection(int *nResult,LPBYTE lpHeader,int nFrameWidth,CRect &rectChamfer,int nChamferThres,BOOL bChipIns,BOOL bChamfer,CRect &rectChip,CRect &rectCrack,CRect &rectBroken
|
,int nChipThres,int nChipIDiffThres,int nCrackThres,int nBrokenThres,int nBurrThres,BOOL bSaveDebug=FALSE,int *nPreForeLine=NULL,ChipThresMode emThresMode=THRESMODE_FIXED,int iFrame = 0);
|
|
ChipErrCode Inspection(int *nResult,LPBYTE lpHeader,int nFrameWidth,CRect &rectChamfer,int nChamferThres,BOOL bChipIns,BOOL bChamfer,CRect &rectChip,CRect &rectCrack,CRect &rectBroken,
|
InspectParam insParam, BOOL bSaveDebug=FALSE,int *nPreForeLine=NULL,ChipThresMode emThresMode=THRESMODE_FIXED,int iFrame = 0);
|
|
BOOL ChipInspection(LPBYTE lpHeader,int nFrameWidth,CRect &rectChip,int nChipThres,int nBurrThres,int nEdgeLeft,int nEdgeRight);
|
BOOL ChipInspection_Binarization(LPBYTE lpHeader,int nFrameWidth,CRect &rectChip,CRect &rectCrack,CRect &rectBroken,int nChipThres,int nChipDiffThres,int nCrackThres,int nBrokenThres
|
,int nBurrThres,int nEdgeLeft,int nEdgeRight,BOOL bSaveDebug,int iFrame);
|
|
BOOL ChipInspection_Binarization_OpenCV(LPBYTE lpHeader,int nFrameWidth,CRect &rectChip,CRect &rectCrack,CRect &rectBroken,InspectParam insParam,int nEdgeLeft,int nEdgeRight,BOOL bSaveDebug,int iFrame);
|
|
void BinalizeFind_Chip(CSISBuffer &pImg,int nThres,ChipResionType s_RegionType,DefectPosType s_DefectPos,CRect &rectInsReg,CSISBuffer &pImgSave,BOOL bSaveImage,BOOL bPolar=TRUE);
|
double FindBPosLine(CSISBuffer &bufferOrg,int nThres);
|
int GetForeEdgeLine(int iPos){return m_nForeEdgeLine[iPos];}
|
CChipBlob *GetDefectResult(){return m_DefectBlob;}
|
int GetDefectCount(){return m_nDefectCnt;}
|
double GetAvgThick(){return m_dAvgThick;}
|
double GetAreaAVG(LPBYTE pImg,CRect &rectIns,CRect &rect);
|
double GetConvRes(){return m_dConvResolution;}
|
|
ChipErrCode InspectCorner_Extra(CSISBuffer &BufferIns,int nThres,int nTop,int nLeft,BOOL bReset=TRUE,int nMergeReange=4);
|
ChipErrCode InspectCorner_ExtraPoly(CSISBuffer &BufferIns,int nThres,int nTop,int nLeft,STU_EXTRA_POLY &stuPoly,BOOL bReset=TRUE,int nMergeReange=4);
|
|
// Binarization..
|
BOOL Binarization_OpenCV(CSISBuffer* pOriginImg, COwnerBuffer* pBinImage, CRect rtInsRect, int nThresholdLow, int nThresholdHigh);
|
BOOL Binarization_OpenCV(CSISBuffer* pOriginImg, COwnerBuffer* pBinImage, CRect rtInsRect, int nThresholdLow, int nThresholdHigh, int nThresholdPitch, int nPitch, int iFram=0, BOOL bSave=FALSE);
|
BOOL Blob_OpenCV(CSISBuffer* pOriginImg, COwnerBuffer* pBinImage, CRect rtInsRect, std::vector<CChipBlob>* vecBlobList, ChipResionType s_RegionType,DefectPosType s_DefectPos, int nMinSize, int nSideFilter, BOOL bROIOffset=TRUE);
|
|
|
public:
|
void ReleaseBuffer();
|
void ResetValue();
|
void ReleaseChipBuffer();
|
BOOL CopyBuffer(CSISBuffer &bufferOrg,COwnerBuffer &bufferTgt);
|
BOOL PreProcessing(LPBYTE pImg,CRect &rectIns,COwnerBuffer &BufferCanny);
|
BOOL FindEdgeLine(LPBYTE pImg,CRect &rectIns);
|
int FindForeCastLine(CSISBuffer &pBuffer,CRect &rectIns,int &nforecast_S,int &nforecast_E,BOOL bChamfer);
|
BOOL Binarization(CSISBuffer &pOrg,COwnerBuffer &pBin,int nSetThres);
|
BOOL FindAdptThres(CSISBuffer &pOrg,CSISBuffer &CannyImg,int &nSetThres,int nForecast_S,ChipThresMode emThresMode);
|
double FindTraceLine(CSISBuffer &CannyImg,int nStart);
|
BOOL FindRightLine(CSISBuffer &pBuffer,CRect &rtIns,double dLeftLine,double &dRightLine,int nThres);
|
BOOL FindRightLine_Bin(CSISBuffer &pBuffer,int &nforecast_S,double &dRightLine);
|
double GetSubPixelThick(CSISBuffer &pBuffer,int nForecast_S,double dForecast_E,int nThres,double &dLeftEdge,double &dRightEdge);
|
|
void VConvolutionConvC(CSISBuffer &pImg,int nThres,ChipResionType s_RegionType,DefectPosType s_DefectPos,int nSetPitch,CRect &rectInsReg);
|
BOOL VertCalPitchConv(CSISBuffer &pImg,int nThres,ChipResionType s_RegionType,DefectPosType s_DefectPos,CRect &rectIns,CSize szConv,int nPitch,int nPitch2);
|
BOOL FilteringEdgeBlob(std::vector<CChipBlob> &vecBlob,int nBaseLeft,int nBaseRight,int nDetMargin,int nImgBurrMargin);
|
BOOL InsertEdgeBlobToDefect(std::vector<CChipBlob> &vecBlob);
|
|
void VConvolutionConvC_Com(COwnerBuffer &pRes,CSISBuffer &pImg,int nThres,ChipResionType s_RegionType,DefectPosType s_DefectPos,int nSetPitch,CRect &rectInsReg);
|
BOOL VertCalPitchConv_Com(COwnerBuffer &pRes,CSISBuffer &pImg,int nThres,ChipResionType s_RegionType,DefectPosType s_DefectPos,CRect &rectIns,CSize szConv,int nPitch,int nPitch2);
|
|
// Corner Chip
|
public:
|
BOOL ChipInspection_Corner(int nMergeRange,BOOL bSaveImage,CString strHpanelID, int nCamID,int iScan, int iThread,int iFrame,CSISBuffer &ChipBuffer,int nChipThres,int nChipInsWidth,int nEdgeRight, double dGradient, double dIntercept, int nDetMargin = 1, int nMargin = 2, int nMarginY = 2);
|
void SetCutAreaExpPos(int nSide,int nPosY, int nSize, int nERType, int nPosX, int nSizeX);
|
void GetCutAreaExpPos(CRect rectInsOrg,int nEdgeLeft, int nGlassStartLine,CRect &rectExpRegion, int nChipInsWidth, double dFindLeft);
|
ChipErrCode Inspection_OnlyChip(int nMergeRange,BOOL bSaveImage,CString strHpanelID, int nCamID, int iScan,int iFrame, int nIndex
|
,CRect &rectIns,CSISBuffer &ChipBuffer,int nChipInsWidth,int nChipThres, int nChipThres_L,BOOL bChipIns, int nDetMargin, double dLeftThres, CRect rectInsOrg
|
,int nGlassStartLine,int nGlassEndLine, int nFrameHeight,int nCPosXOffset, int nDPosXOffset, int nCPosYOffsetStart, int nCPosYOffsetEnd, int nDPosYOffsetStart
|
, int nDPosYOffsetEnd, int nChippingInsOffset, double dFindLeft, int nAirThres);
|
protected:
|
void VConvolutionConvC_Polygon(CSISBuffer &pSaveImg,BOOL bSaveImage,int nCamID,int iScan,int iFrame,CString strHpanelID, CSISBuffer &pImg,int nThres,std::vector<CChipPair> &vecPair,int nSetPitch, double dGradient, double dIntercept, int nDetMargin, double dLeft, int nOffset, int nOffsetY);
|
BOOL BlobDefect_Pixel_TypeRegionFilter(std::vector<CChipBlob> &vecBlob,std::vector<CChipPair> &vecPair,int nChipThres,int nMergeDist=2);
|
BOOL FilteringDiagonalEdgeBlob(std::vector<CChipBlob> &vecBlob);
|
BOOL OnlyChipInspection(int nMergeRange,BOOL bSaveImage,CString strHpanelID, int nCamID, int iScan,int iFrame, int nIndex,CSISBuffer &ChipBuffer
|
,int nChipThres, int nChipThres_L,int nChipInsWidth,int nEdgeLeft,int nEdgeRight, CRect rectInsOrg, int nGlassStartLine
|
,int nGlassEndLine, int nFrameHeight, int nCPosXOffset, int nDPosXOffset, int nCPosYOffsetStart, int nCPosYOffsetEnd, int nDPosYOffsetStart, int nDPosYOffsetEnd, int nDetMargin = 1, int nChippingInsOffset = 0 ,double dFindLeft=0,int nAirThres = 200);
|
void BinalizeFind_CornerChip(CSISBuffer &pSaveImg,BOOL bSaveImage,CString strHpanelID, CSISBuffer &pImg,int nThres,std::vector<CChipPair> &vecPair,ChipResionType s_RegionType,int nSetPitch,CRect rectExpRegion,int iFrame=0, int nIndex=0, int nCamID=0, int iScan=0, int nChippingInsOffset=0);
|
void BinalizeFind_CornerChip_White(CSISBuffer &pSaveImg,BOOL bSaveImage,CString strHpanelID, CSISBuffer &pImg,int nThres,std::vector<CChipPair> &vecPair,ChipResionType s_RegionType,int nSetPitch, CRect rectInsOrg,int nGlassStartLine,int nGlassEndLine, int nFrameHeight,int nCPosXOffset, int nDPosXOffset, int nCPosYOffsetStart, int nCPosYOffsetEnd, int nDPosYOffsetStart, int nDPosYOffsetEnd, CRect rectExpRegion, int iFrame, int nIndex, int nCamID, int iScan);
|
BOOL FilteringEdgeBlob_TypeFilter(std::vector<CChipBlob> &vecBlob,ChipResionType emSide,int nBaseLine,int nDetMargin);
|
void VConvolutionConvC_CornerChip(CSISBuffer &pSaveImg,BOOL bSaveImage,CString strHpanelID, CSISBuffer &pImg,int nThres,std::vector<CChipPair> &vecPair,ChipResionType s_RegionType,int nSetPitch,int iFrame=0, int nIndex=0, int nCamID=0, int iScan=0);
|
|
// General
|
public:
|
void ResetPairDefect(){m_nChipPairIndex=0;}
|
int GetPairDefectCount(){return m_nChipPairIndex;}
|
CChipPair *GetPairDefect(int iIndex);
|
BOOL BlobDefect_Pixel(std::vector<CChipBlob> &vecBlob,int nChipThres,int nMergeDist=2);
|
BOOL InsertPairing(int x, int y, int sub, int threshold, int graySrc, int grayRef,ChipResionType s_RegionType,DefectPosType s_DefectPos, BOOL bEdgeDefect = FALSE, double dThick=0.);
|
void SetConvResolution(double dRes){m_dConvResolution=dRes;}
|
void ResetSaveIndex(){m_nSaveIndex = 0;}
|
BOOL CopyRectImg(LPBYTE pOrg,LPBYTE pTgt,CSize szImg,CRect &rectIns);
|
|
protected:
|
BOOL MergeDivision(std::vector<CChipBlob> &vecBlob, int nMergePixel = 4);
|
BOOL MergeMix(std::vector<CChipBlob> &vecBlob, int nMergePixel = 4);
|
void CheckDefectRect(CChipBlob& Defect, int nX, int nY);
|
int CalcRScale(CPoint* pVertex);
|
void SetBrokenDefect(CRect rectDefect);
|
BOOL AssertRect(CRect rect,CSize szImg);
|
|
protected:
|
double m_dConvResolution;
|
LGLASSFINDDATA m_pGlassEdgeLine;
|
int m_nGlassEdgeLineCnt;
|
int *m_pCannyWidthCnt;
|
int m_nForeEdgeLine[2];
|
double m_dAvgThick;
|
CChipBlob *m_DefectBlob;
|
int m_nDefectCnt;
|
std::vector<STU_CHIPPINGINS_EXP_POS> m_expInsArea;
|
int m_nSaveIndex;
|
CChipPair *m_pChipPairBuf;
|
int m_nChipPairIndex;
|
BOOL *m_bMerged;
|
BOOL *m_bTemp;
|
int *m_lFirstIndex;
|
};
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
//{{AFX_INSERT_LOCATION}}
|
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
|
|
#endif // !defined(AFX_CHAMFERINSPECT_H_INCLUDED_)
|