//==================================================================================
|
// DIPM.h : Declaration of DIPM
|
//==================================================================================
|
|
#ifndef __EDGE_DIPM__
|
#define __EDGE_DIPM__
|
|
//#include "stdafx.h"
|
#include "cv.h"
|
#include "highgui.h"
|
#include "opencv.hpp"
|
#include "core.hpp"
|
#include <math.h>
|
#include <map>
|
#include <list>
|
#include <vector>
|
|
//Define DLL IM/EXPORTs
|
|
#ifndef DLLEXPORT
|
#define DLLEXPORT __declspec(dllexport)
|
#endif
|
|
#ifndef DLLIMPORT
|
#define DLLIMPORT __declspec(dllimport)
|
#endif
|
|
////////////////////////////////////////////////////////////////////////////////////
|
// MACRO definitions
|
|
#define align_4byte(in) ((in + 3)/4)*4
|
|
// Memory allocation MACRO for compatible with windows SDK
|
#define memalloc(flags, cb) (GlobalLock(GlobalAlloc((flags),(cb))))
|
#define memfree(lp) \
|
(GlobalUnlock((HGLOBAL)GlobalHandle(lp)),(BOOL)GlobalFree((HGLOBAL)GlobalHandle(lp)))
|
|
////////////////////////////////////////////////////////////////////////////////////
|
// Constant definitions
|
|
#define ROUND(a) (a+0.5)
|
#define FLOOR(a) (a)
|
|
// Numerical MACRO's
|
#define M_PI acos(-1.0)
|
#define M_RADIAN(x) (((M_PI)*(x))/180.0)
|
#define M_DEGREE(x) (((180.0)*(x))/M_PI)
|
|
#ifndef RANGEIN
|
#define RANGEIN(a, r1, r2) (((a>=r1)&&(a<=r2)) ? (1) : (0))
|
#endif
|
|
// Logical MACRO's
|
#define MINIMUM(a, b) ((a)<(b) ? (a) : (b))
|
#define MAXIMUM(a, b) ((a)>(b) ? (a) : (b))
|
#define MIDDLE(a, b, c) (((a>b)&&(a<c)) ? (1) : (0))
|
|
enum enGradientMask{GM_Sobel, GM_Prewitt, GM_Roberts};
|
|
struct sPoint {
|
double x, y;
|
};
|
|
struct sLine {
|
double mx, my;
|
double sx, sy;
|
};
|
|
typedef struct rtiTEMP_RESULT
|
{
|
float fRat;
|
CvPoint2D32f pt;
|
}TEMP_RESULT;
|
|
typedef struct _rtiTEMP_MATCH_DATA
|
{
|
double dMaxRate;
|
double dMinRate;
|
double dPt_X;
|
double dPt_Y;
|
|
_rtiTEMP_MATCH_DATA(void)
|
{
|
dMaxRate = 0.0;
|
dMinRate = 0.0;
|
dPt_X = 0.0;
|
dPt_Y = 0.0;
|
}
|
}TEMP_MATCH_DATA;
|
|
enum ChipPair {CHIPDEFPAIR_NOTDEFINE = 0, CHIPDEFPAIR_PPAIR, CHIPDEFPAIR_MPAIR, CHIPDEFPAIR_SIDE, CHIPDEFPAIR_LARGE, CHIPDEFPAIR_UNPAIR };
|
enum ChipType {CHIPDEFTYPE_BLACK = 0, CHIPDEFTYPE_WHITE, CHIPDEFTYPE_MIXED, CHIPDEFTYPE_NODEFECT, CHIPDEFTYPE_DELETE};
|
enum ChipResionType {CHIPREGTYPE_LEFT = 0, CHIPREGTYPE_RIGHT, CHIPREGTYPE_RIGHT_WHITE, CHIPREGTYPE_NONE};
|
enum DefectPosType {INS_DEFECT_CRACK = 0, INS_DEFECT_BROKEN, INS_DEFECT_CHIP, INS_DEFECT_CHAMFER,INS_DEFECT_BURR,INS_DEFECT_NONE};
|
enum ChipPosType {CHIPPOSTYPE_BIN = 0, CHIPPOSTYPE_CEN, CHIPPOSTYPE_SP,CHIPPOSTYPE_NONE};
|
|
// Directional information
|
#define IM_NEGATIVE 101
|
#define IM_POSITIVE 102
|
#define IM_HORIZONTAL 103
|
#define IM_VERTICAL 104
|
#define IM_LEFT 105
|
#define IM_RIGHT 106
|
|
//Gray level
|
#define IM_BLACK 0
|
#define IM_WHITE 255
|
|
//Image
|
#ifndef _IMAGE_
|
#define _IMAGE_
|
typedef struct ImImage {
|
unsigned char *buf;
|
int cu;
|
int cv;
|
} IMAGE;
|
#endif
|
|
//Position in 2D
|
#ifndef _IMPOS2D_
|
#define _IMPOS2D_
|
typedef struct ImPos2D {
|
double u;
|
double v;
|
} IMPOS2D;
|
#endif
|
|
//Region of interest (ROI)
|
#ifndef _ROI_
|
#define _ROI_
|
typedef struct ImRoi {
|
int u1;
|
int v1;
|
int u2;
|
int v2;
|
} ROI, *LPROI;
|
#endif
|
|
class CChipBlob
|
{
|
public:
|
ChipResionType s_RegionType;
|
ChipPair s_DefectPair;
|
ChipType s_DefectType;
|
ChipPosType s_DefectPosType;
|
DefectPosType s_DefectJudgeType;
|
int s_nIndex;
|
int s_nDefectArea;
|
int s_nDefectX;
|
int s_nDefectY;
|
int s_xLevelSrcMax;
|
int s_yLevelSrcMax;
|
int s_nDefectRScale;
|
CRect s_DefectRect;
|
short s_sDefectPeak;
|
|
short s_sLevelSrcMin;
|
short s_sLevelSrcMax;
|
short s_sLevelSrcAvg;
|
short s_sLevelRefMin;
|
short s_sLevelRefMax;
|
short s_sLevelRefAvg;
|
short s_sLevelDiffMin;
|
short s_sLevelDiffMax;
|
short s_sLevelDiffAvg;
|
int s_nLevelSrcSum;
|
int s_nLevelRefSum;
|
int s_nLevelDiffSum;
|
short s_sThreshold;
|
BOOL s_bRemoved;
|
double s_dThick;
|
BOOL s_bCornerChip;
|
|
CPoint s_ptVertex[8];
|
|
CChipBlob()
|
{
|
Reset();
|
}
|
void Reset()
|
{
|
s_RegionType = CHIPREGTYPE_NONE;
|
s_DefectPair = CHIPDEFPAIR_NOTDEFINE;
|
s_DefectType = CHIPDEFTYPE_NODEFECT;
|
s_DefectJudgeType = INS_DEFECT_NONE;
|
s_nIndex = 0;
|
s_nDefectArea = 0;
|
s_nDefectX = 0;
|
s_nDefectY = 0;
|
s_nDefectRScale = 0;
|
// 20080525 ÀÌÁØÈñ
|
s_DefectRect.SetRect(INT_MAX, INT_MAX, 0, 0);
|
s_sDefectPeak = 0;
|
|
s_sLevelSrcMin = 2048;
|
s_sLevelSrcMax = 0;
|
s_xLevelSrcMax = 0;
|
s_yLevelSrcMax = 0;
|
s_sLevelSrcAvg = 0;
|
s_sLevelRefMin = 2048;
|
s_sLevelRefMax = 0;
|
s_sLevelRefAvg = 0;
|
s_sLevelDiffMin = 2048;
|
s_sLevelDiffMax = 0;
|
s_sLevelDiffAvg = 0;
|
s_nLevelSrcSum = 0;
|
s_nLevelRefSum = 0;
|
s_nLevelDiffSum = 0;
|
|
s_sThreshold = 0;
|
s_dThick = 0.;
|
s_bCornerChip = FALSE;
|
|
// 20080525 ÀÌÁØÈñ
|
s_ptVertex[0] = MAKELONG(32760, 32760);
|
s_ptVertex[1] = MAKELONG(32760, 0);
|
s_ptVertex[2] = MAKELONG(32760, 32760);
|
s_ptVertex[3] = MAKELONG(0, 32760);
|
s_ptVertex[4] = MAKELONG(0, 32760);
|
s_ptVertex[5] = MAKELONG(0, 0);
|
s_ptVertex[6] = MAKELONG(32760, 0);
|
s_ptVertex[7] = MAKELONG(0, 0);
|
|
s_bRemoved = FALSE;
|
}
|
|
void SetDefectPair(ChipPair DP)
|
{
|
if (s_DefectPair < DP)
|
s_DefectPair = DP;
|
}
|
|
// ´ëÀÔ¿¬»êÀÚ ¿À¹ö·Îµù.
|
CChipBlob& operator=(const CChipBlob& rhs)
|
{
|
if(this != &rhs)
|
{
|
s_RegionType = rhs.s_RegionType;
|
s_DefectPair = rhs.s_DefectPair;
|
s_DefectType = rhs.s_DefectType;
|
s_DefectJudgeType = rhs.s_DefectJudgeType;
|
s_nIndex = rhs.s_nIndex;
|
s_nDefectArea = rhs.s_nDefectArea;
|
s_nDefectX = rhs.s_nDefectX;
|
s_nDefectY = rhs.s_nDefectY;
|
s_nDefectRScale = rhs.s_nDefectRScale;
|
s_DefectRect = rhs.s_DefectRect;
|
s_sDefectPeak = rhs.s_sDefectPeak;
|
|
s_sLevelSrcMin = rhs.s_sLevelSrcMin;
|
s_sLevelSrcMax = rhs.s_sLevelSrcMax;
|
s_xLevelSrcMax = rhs.s_xLevelSrcMax;
|
s_yLevelSrcMax = rhs.s_yLevelSrcMax;
|
s_sLevelSrcAvg = rhs.s_sLevelSrcAvg;
|
s_sLevelRefMin = rhs.s_sLevelRefMin;
|
s_sLevelRefMax = rhs.s_sLevelRefMax;
|
s_sLevelRefAvg = rhs.s_sLevelRefAvg;
|
s_sLevelDiffMin = rhs.s_sLevelDiffMin;
|
s_sLevelDiffMax = rhs.s_sLevelDiffMax;
|
s_sLevelDiffAvg = rhs.s_sLevelDiffAvg;
|
s_nLevelSrcSum = rhs.s_nLevelSrcSum;
|
s_nLevelRefSum = rhs.s_nLevelRefSum;
|
s_nLevelDiffSum = rhs.s_nLevelDiffSum;
|
|
s_sThreshold = rhs.s_sThreshold;
|
s_dThick = rhs.s_dThick;
|
s_bCornerChip = rhs.s_bCornerChip;
|
|
int i;
|
for(i= 0; i< 8; i++)
|
{
|
s_ptVertex[i]= rhs.s_ptVertex[i];
|
}
|
s_bRemoved = rhs.s_bRemoved;
|
}
|
return *this;
|
}
|
|
// + ¿¬»êÀÚ ¿À¹ö·Îµù.
|
CChipBlob operator+(const CChipBlob& rhs)
|
{
|
if (s_DefectPair < rhs.s_DefectPair)
|
s_DefectPair = rhs.s_DefectPair;
|
|
s_nDefectArea += rhs.s_nDefectArea;
|
|
if (s_ptVertex[0].x >= rhs.s_ptVertex[0].x) // LT
|
s_ptVertex[0] = rhs.s_ptVertex[0];
|
if (s_ptVertex[1].x >= rhs.s_ptVertex[1].x) // LB
|
s_ptVertex[1] = rhs.s_ptVertex[1];
|
if (s_ptVertex[2].y >= rhs.s_ptVertex[2].y) // TL
|
s_ptVertex[2] = rhs.s_ptVertex[2];
|
if (s_ptVertex[3].y >= rhs.s_ptVertex[3].y) // TR
|
s_ptVertex[3] = rhs.s_ptVertex[3];
|
if (s_ptVertex[4].x <= rhs.s_ptVertex[4].x) // RT
|
s_ptVertex[4] = rhs.s_ptVertex[4];
|
if (s_ptVertex[5].x <= rhs.s_ptVertex[5].x) // RB
|
s_ptVertex[5] = rhs.s_ptVertex[5];
|
if (s_ptVertex[6].y <= rhs.s_ptVertex[6].y) // BL
|
s_ptVertex[6] = rhs.s_ptVertex[6];
|
if (s_ptVertex[7].y <= rhs.s_ptVertex[7].y) // BR
|
s_ptVertex[7] = rhs.s_ptVertex[7];
|
|
s_nDefectRScale = (s_nDefectRScale + rhs.s_nDefectRScale);
|
if (s_DefectRect.left > rhs.s_DefectRect.left)
|
s_DefectRect.left = rhs.s_DefectRect.left;
|
if (s_DefectRect.top > rhs.s_DefectRect.top)
|
s_DefectRect.top = rhs.s_DefectRect.top;
|
if (s_DefectRect.right < rhs.s_DefectRect.right)
|
s_DefectRect.right = rhs.s_DefectRect.right;
|
if (s_DefectRect.bottom < rhs.s_DefectRect.bottom)
|
s_DefectRect.bottom = rhs.s_DefectRect.bottom;
|
if (s_sDefectPeak < rhs.s_sDefectPeak)
|
s_sDefectPeak = rhs.s_sDefectPeak;
|
|
s_nDefectX = (s_DefectRect.right + s_DefectRect.left) / 2;
|
s_nDefectY = (s_DefectRect.bottom + s_DefectRect.top) / 2;
|
|
if (s_sLevelSrcMin > rhs.s_sLevelSrcMin)
|
s_sLevelSrcMin = rhs.s_sLevelSrcMin;
|
if (s_sLevelSrcMax < rhs.s_sLevelSrcMax)
|
{
|
s_sLevelSrcMax = rhs.s_sLevelSrcMax;
|
s_xLevelSrcMax = rhs.s_xLevelSrcMax;
|
s_yLevelSrcMax = rhs.s_yLevelSrcMax;
|
}
|
s_sLevelSrcAvg = (s_sLevelSrcAvg + rhs.s_sLevelSrcAvg) / 2;
|
if (s_sLevelRefMin > rhs.s_sLevelRefMin)
|
s_sLevelRefMin = rhs.s_sLevelRefMin;
|
if (s_sLevelRefMax < rhs.s_sLevelRefMax)
|
s_sLevelRefMax = rhs.s_sLevelRefMax;
|
s_sLevelRefAvg = (s_sLevelRefAvg + rhs.s_sLevelRefAvg) / 2;
|
if (s_sLevelDiffMin > rhs.s_sLevelDiffMin)
|
s_sLevelDiffMin = rhs.s_sLevelDiffMin;
|
if (s_sLevelDiffMax < rhs.s_sLevelDiffMax)
|
s_sLevelDiffMax = rhs.s_sLevelDiffMax;
|
s_sLevelDiffAvg = (s_sLevelDiffAvg + rhs.s_sLevelDiffAvg) / 2;
|
s_nLevelSrcSum += rhs.s_nLevelSrcSum;
|
s_nLevelRefSum += rhs.s_nLevelRefSum;
|
s_nLevelDiffSum += rhs.s_nLevelDiffSum;
|
|
if (s_sThreshold < rhs.s_sThreshold)
|
s_sThreshold = rhs.s_sThreshold;
|
|
if(s_dThick < rhs.s_dThick)
|
s_dThick = rhs.s_dThick;
|
|
s_bCornerChip |= rhs.s_bCornerChip;
|
|
return *this;
|
}
|
|
};
|
|
class CChipPair
|
{
|
public:
|
ChipPair s_DefectPair;
|
ChipType s_DefectType;
|
ChipResionType s_RegionType;
|
DefectPosType s_DefectPosType;
|
float s_fDefectPeak;
|
int s_nDefectX;
|
int s_nDefectY;
|
int s_nGraySrc;
|
int s_nGrayRef;
|
double s_dThick;
|
BOOL s_bCornerChip;
|
|
CChipPair()
|
{
|
Reset();
|
}
|
void Reset()
|
{
|
s_DefectPair = CHIPDEFPAIR_NOTDEFINE;
|
s_DefectType = CHIPDEFTYPE_NODEFECT;
|
s_RegionType = CHIPREGTYPE_NONE;
|
s_DefectPosType = INS_DEFECT_NONE;
|
s_fDefectPeak = 0.0;
|
s_nDefectX = 0;
|
s_nDefectY = 0;
|
s_nGraySrc = 0;
|
s_nGrayRef = 0;
|
s_dThick = 0.;
|
s_bCornerChip = FALSE;
|
}
|
void SetPeak(int nPeak, int nKernelThres, int nCalcPixel)
|
{
|
s_fDefectPeak= static_cast<float>(abs(nPeak));
|
s_fDefectPeak -= static_cast<float>(nKernelThres);
|
s_fDefectPeak /= static_cast<float>(nCalcPixel);
|
}
|
|
// º¹»ç »ý¼ºÀÚ.
|
CChipPair(const CChipPair& rhs)
|
{
|
if(this != &rhs)
|
{
|
s_DefectPair = rhs.s_DefectPair;
|
s_DefectType = rhs.s_DefectType;
|
s_fDefectPeak = rhs.s_fDefectPeak;
|
s_nDefectX = rhs.s_nDefectX;
|
s_nDefectY = rhs.s_nDefectY;
|
s_nGraySrc = rhs.s_nGraySrc;
|
s_nGrayRef = rhs.s_nGrayRef;
|
s_RegionType = rhs.s_RegionType;
|
s_dThick = rhs.s_dThick;
|
s_bCornerChip = rhs.s_bCornerChip;
|
s_DefectPosType = rhs.s_DefectPosType;
|
}
|
}
|
|
// ´ëÀÔ¿¬»êÀÚ ¿À¹ö·Îµù.
|
CChipPair& operator=(const CChipPair& rhs)
|
{
|
if(this != &rhs)
|
{
|
s_DefectPair = rhs.s_DefectPair;
|
s_DefectType = rhs.s_DefectType;
|
s_fDefectPeak = rhs.s_fDefectPeak;
|
s_nDefectX = rhs.s_nDefectX;
|
s_nDefectY = rhs.s_nDefectY;
|
s_nGraySrc = rhs.s_nGraySrc;
|
s_nGrayRef = rhs.s_nGrayRef;
|
s_RegionType = rhs.s_RegionType;
|
s_dThick = rhs.s_dThick;
|
s_bCornerChip = rhs.s_bCornerChip;
|
}
|
return *this;
|
}
|
};
|
|
#endif
|
|
// End of FV_DIPM.h
|
////////////////////////////////////////////////////////////////////////////////////
|