1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#pragma once
 
#define        DEFECTIMAGE_WIDTH        1024
#define        DEFECTIMAGE_HEIGHT        500
 
enum DefectLocation 
    DefectLoc_Chip=0,
    DefectLoc_Crack, 
    DefectLoc_Burr,
    DefectLoc_Chamfer,
    DefectLoc_In_Chip, 
    DefectLoc_In_Crack,
    DefectLoc_In_Burr,
    DefectLoc_In_Chamfer,
    DefectLoc_Top_Corner,
    DefectLoc_Bot_Corner,
 
    DefectLoc_Corner_Chamfer,
    DefectLoc_Measure_Corner,
    DefectLoc_Measure_Dimension,
    DefectLoc_Measure_Chamfer,
 
    DefectLoc_Notch_Crack,
    DefectLoc_Notch_NoGrind,
    DefectLoc_Notch_Dimension,
    DefectLoc_Notch_Chamfer,
    DefectLoc_Notch_Circle_Radius,
 
    DefectLoc_UserDefect,
 
    DefectLoc_Mark,
 
    DefectLoc_WS_Fail,
 
    DefectLoc_Exception,
 
    DefectLoc_License,
 
    DefectLoc_Rip_Thickness_Glass,
    DefectLoc_Rip_Thickness_Left,
    DefectLoc_Rip_Thickness_Right,
 
    DefectLoc_Unknown,
    
    DefectLoc_None
    
};
 
static CString g_strDefectType[DefectLoc_None] = 
{
    _T("Chip"),
    _T("Crack"), 
    _T("Burr"),
    _T("Chamfer"),
    _T("In_Chip"),
    _T("In_Crack"),
    _T("In_Burr"),
    _T("In_Chamfer"),
    _T("Top_Corner"),
    _T("Bot_Corner"),
 
    _T("Corner_Chamfer"),
    _T("Corner_Dimension"),
    _T("Dimension"),
    _T("Chamfer"),
 
    _T("Notch"),
    _T("Notch_NoGrind"),
    _T("Notch_Dimension"),
    _T("Notch_Chamfer"),
    _T("Notch_Radius"),
 
    _T("User_Defect"),
 
    _T("Mark"),
 
    _T("WS_Fail"),
 
    _T("Exception"),
 
    _T("License"),
 
    _T("Rip_GlassThickness"),
    _T("Rip_LeftGap"),
    _T("Rip_RightGap"),
 
    _T("Unknown")
};
 
class CDefect_Info
{
public:
    CDefect_Info()            {Reset();};
    virtual ~CDefect_Info()    {};
 
public:
    void Reset()
    {
        m_nIndex = -1;
        m_iFrameIdx = -1;
        m_nCamID = -1;
        m_nScanIdx = -1;
        m_nGlassStartLine = -1;
 
        m_nSideIdx = -1;
        m_DefectLoc = DefectLoc_None;
 
        m_ptDefectPos_pxl = CPoint(-1,-1);
        m_rtDefectPos_pxl = CRect(-1,-1,-1,-1);
 
        m_nMinSize = 0;
        m_nBlobDilation = 0;
 
        m_nBlobCount = 0;
        m_nGray_Max = 0;
        m_nGray_Min = 0;
        m_nGray_Sum = 0;
        m_dGray_Avg = 0;
        m_dRectArea_Ratio = 0.0;
    }
 
public:    
    int                m_nIndex;
    int                m_iFrameIdx;
    int                m_nCamID;
    int                m_nScanIdx;
    int                m_nGlassStartLine;
    int                m_nSideIdx;
    DefectLocation    m_DefectLoc;
 
 
    CPoint            m_ptDefectPos_pxl;
    CRect            m_rtDefectPos_pxl;
 
    int                m_nMinSize;
    int                m_nBlobDilation;
 
    // Image Info
    UINT            m_nBlobCount;
    UINT            m_nGray_Max;
    UINT            m_nGray_Min;
    UINT            m_nGray_Sum;
    double            m_dGray_Avg;
 
    double            m_dRectArea_Ratio;
};
 
class CDefect
{
public:
    CDefect()            {Reset();};
    virtual ~CDefect()    {};
 
public:
    void Reset()
    {
        m_nIdx = 0;
        m_DefectInfo.Reset();
 
        m_dSizeX_um = 0.0;
        m_dSizeY_um = 0.0;
        m_dChamfer_um = 0.0;
        m_dChamferOff_um = 0.0;
 
        m_nDefectMergeCount = 0;
        m_bDefectMergeRemoved = FALSE;
 
        m_bJudge_NG = 0;                    // 0 : OK, 1 : NG
        m_nJudge_X_um = 0;
        m_nJudge_Y_um = 0;
        m_nJudge_Type = 0;
 
        m_nExceptionArea = 0;
 
        m_nUserDefectAreaIdx = 0;
 
        m_nNotchIdx = 0;
 
        m_nJudgeArea = 0;
 
        ZeroMemory(m_Image, sizeof(m_Image));
        m_strSaveImagePath = _T("");
    }
public:    
    int                m_nIdx;
    CDefect_Info    m_DefectInfo;
 
    double            m_dSizeX_um;
    double            m_dSizeY_um;
    double            m_dChamfer_um;
    double            m_dChamferOff_um;
 
    // Merge
    int                m_nDefectMergeCount;
    BOOL            m_bDefectMergeRemoved;
 
    // Judge
    BOOL            m_bJudge_NG;            // 0 : OK, 1 : NG
    int                m_nJudge_X_um;
    int                m_nJudge_Y_um;
    int                m_nJudge_Type;
 
    // Exception Area
    int                m_nExceptionArea;        // 0 : 固器窃, 1 : 混娄 吧魔, 2 : 肯傈 器窃
 
    // User Defect Idx
    int                m_nUserDefectAreaIdx;
 
    // Notch Defect Idx
    int             m_nNotchIdx;
 
    // Judge Area
    int                m_nJudgeArea;            // 0 : 1st, 1 : 2nd, 2 : 3rd
 
    // Image
    BYTE            m_Image[DEFECTIMAGE_WIDTH * DEFECTIMAGE_HEIGHT + 1];
    CString            m_strSaveImagePath;
};
 
typedef std::multimap<int, CDefect*>            MapDefect;
typedef std::multimap<int, CDefect*>::iterator    MapDefectIt;