LWQ
2025-07-14 8c7705d8e69c358dcbe77354fcc02b76156e8164
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
// EdgeFind.h: interface for the CSISEdgeFind class.
//
//////////////////////////////////////////////////////////////////////
#pragma once
 
#include <map>
 
class CSISBuffer;
 
 
// defect count ±â¹ÝÀ¸·Î cutoff point ¸¦ Ã£¾Æ ÁØ´Ù.
// AddCountData¸¦ ÅëÇÑ ¹æ¹ý°ú FindCutoff_Continue¸¦ ÅëÇÑ ¹æ¹ý µÎ°¡Áö°¡ ÀÖ´Ù.
class AFX_EXT_CLASS CCutoffFind
{
    int m_nContinuousCutoff;
    int *m_pCountData;
public:
    int    m_maxCount;
    int m_nCountData;
    CCutoffFind()
    {
        m_nCountData= 0;
        m_pCountData= NULL;
    }
    virtual ~CCutoffFind()
    {
        if(m_pCountData)
            delete m_pCountData;
    }
    BOOL SetSize(int nData)
    {
        m_nCountData= nData;
        if(m_pCountData)
            delete m_pCountData;
        m_pCountData= new int[nData];
        return TRUE;
    }
 
    // ¼øÂ÷ÀûÀ¸·Î È£ÃâµÇ¸é cutoffÀÎÁö¸¦ ÆÇº°ÇØ ¿¬¼Ó cutoff count¸¦ ¸®ÅÏÇØ ÁØ´Ù.
    int AddCountData(int data, int nCutoff)
    {
        if(data >= nCutoff)
        {
            m_nContinuousCutoff++;
            return m_nContinuousCutoff;
        }
        m_nContinuousCutoff= 0;
        return 0;
    }
 
 
    void SetCountData(int iData, int data)
    {
        m_pCountData[iData]= data;
    }
    // Á¤,¿ª¹æÇâÀ¸·Î line by line °Ë»çÇϸç Cutoff_Continuous¸¦ Ã£¾Æ ³½´Ù.  Cutoff_Continuous°¡ ¾øÀ¸¸é false, Cutoff À§Ä¡´Â Á¤¹æÇâ ±âÁØÀÇ indexÀÌ´Ù.
    // nContinue°³¼ö ÀÌ»ó Áö¼ÓÀûÀ¸·Î cutoff°¡ »ý°Ü¾ß Cutoff_Continuous·Î °£ÁÖÇÑ´Ù.
    BOOL FindCutoff_Continuous(BOOL bForwardScan, int nCutoff, int nContinue, int &iForwardResult,int nOffset=0)
    {
        int i;
        int nOccur= 0;
 
        if(bForwardScan)
        {
            for(i= nOffset; i< m_nCountData; i++)
            {
                if(m_pCountData[i] >= nCutoff)
                {
                    nOccur++;
                    if(nOccur >= nContinue)
                    {
                        iForwardResult= i- nContinue+ 1;
                        return TRUE;
                    }
                }else
                {
                    nOccur= 0;
                }
            }
            return FALSE;
        }
 
        for(i= m_nCountData-1; i >= nOffset; i--)
        {
            if(m_pCountData[i] >= nCutoff)
            {
                nOccur++;
                if(nOccur >= nContinue)
                {
                    iForwardResult= i+ nContinue;
                    return TRUE;
                }
            }else
            {
                nOccur= 0;
            }
        }
        return FALSE;
    }
};
 
enum SISEdgePos{eEP_LEFT, eEP_TOP, eEP_RIGHT, eEP_BOTTOM};
 
struct stEdgeLRResult
{
    int iFrame;
    int nPos;
};
 
typedef std::multimap<int, stEdgeLRResult> mapEdgeResult;
typedef std::multimap<int, stEdgeLRResult>::iterator mapEdgeResultIt;
 
class AFX_EXT_CLASS CSISEdgeFind
{
public:
    CSISEdgeFind();
    virtual ~CSISEdgeFind();
 
protected:
    CSISBuffer        *m_Buffer;
 
    //Left Result
    mapEdgeResult        m_mapLeftEdge;
    //Right Result
    mapEdgeResult        m_mapRightEdge;
    //Top Result
    int                    m_nTopEdge;
    //Bottom Result
    int                    m_nBottomEdge;
 
public:
    void                ResetEdge();
 
    int                    GetEdgeResult(SISEdgePos eEP, int iFrame = 0, BOOL bNearResult = FALSE);
    BOOL                IsFindEdge(SISEdgePos eEP, int iFrame = 0);
 
public:
    BOOL FindEdge_ToTop(CSISBuffer *pBuffer, int &offset, double pitch, int threshold, double rDefect);
    BOOL FindEdge_ToBottom(CSISBuffer *pBuffer, int &offset, double pitch, int threshold, double rDefect);
    BOOL FindEdge_ToLeft(CSISBuffer *pBuffer, int &offset, double pitch, int threshold, double rDefect,int nOffset);
    BOOL FindEdge_ToRight(CSISBuffer *pBuffer, int &offset, double pitch, int threshold, double rDefect,int nOffset);
    BOOL FindEdge_ToRightROI(CSISBuffer *pBuffer, int &offset, double pitch, int threshold, double rDefect,int nOffset,CRect rtROI);
 
public:
    int Find_LeftEdge(CSISBuffer *pBuffer, double pitch, int threshold, double rDefect, int nContinue);
    int Find_RightEdge(CSISBuffer *pBuffer, double pitch, int threshold, double rDefect, int nContinue);
    int Find_TopEdge(CSISBuffer *pBuffer, double pitch, int threshold, double rDefect, int nContinue);
    int Find_GlassStart(CSISBuffer *pBuffer, double pitch);
public:
    void GetCount_X(CSISBuffer *pBuffer, double pitch, int threshold, CCutoffFind &find,int nOffset);
    void GetCount_XROI(CSISBuffer *pBuffer, double pitch, int threshold, CCutoffFind &find,int nOffset,CRect rtROI);
    void GetCount_Y(CSISBuffer *pBuffer, double pitch, int threshold, CCutoffFind &find);
 
    int ImageProjection(BYTE* pBuff, int nWidth, int nHeight, CRect ROI, int nThres, int nDist = 8, int nContinue = 2);
    int    ImageProjection_R(BYTE* pBuff, int nWidth, int nHeight, CRect ROI, int nThres, int nDist = 8, int nContinue = 2);
    int    ImageProjection_Vert(BYTE* pBuff, int nWidth, int nHeight, CRect ROI, int nThres, int nDist = 8, int nContinue = 2);
    int    ImageProjection_Vert_R(BYTE* pBuff, int nWidth, int nHeight, CRect ROI, int nThres, int nDist = 8, int nContinue = 2);
 
    int    FindEdge(CSISBuffer framebuffer, SISEdgePos eEP, CRect rtROI, int nThres);
    int    FindEdgeVert(CSISBuffer framebuffer, SISEdgePos eEP, CRect rtROI, int nThres);
};