SDC C-Project CF Review 프로그램
LYW
2021-11-12 039bde2990b5b015232b5da9ff4df0cf1d88ddac
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
#include "StdAfx.h"
#include "AlignFinder_Extend.h"
 
 
CAlignFinder_Extend::CAlignFinder_Extend(int nIndex) : CAlignFinder(nIndex)
{
}
 
CAlignFinder_Extend::~CAlignFinder_Extend(void)
{
}
 
int CAlignFinder_Extend::FindAlignEdge( SAlignFindResult& findResult )
{
    findResult.nResultProcess = AlignProcess_Edge;
 
    if (m_findParam.bEdgeProcess==FALSE)
    {
        return AlignEdge_None;
    }
 
    // step1. Sobel Edge ¿¬»ê
    TRACE(_T("[A2E]CAlignFinder::FindAlignEdge Step1\n"));
 
    int nWidth = m_SourceImage.GetWidth();
    int nHeight = m_SourceImage.GetHeight();
 
    if (ImageSobelEdge((BYTE*)m_SourceImage.GetImageBuffer(), (BYTE*)m_EdgeImage.GetImageBuffer(), nWidth, nHeight)!=1)
    {
        findResult.nResultCode = AlignEdge_EdgeFail;
        return 0;
    }
 
    // step2. Binary Threshold ¿¬»ê
    TRACE(_T("[A2E]CAlignFinder::FindAlignEdge Step2\n"));
 
    if (m_EdgeImage.CopyImageTo(&m_ThresImage)==FALSE) 
    {
        findResult.nResultCode = AlignEdge_None;
        return 0;
    }
 
    if (ImageThresholding((BYTE*)m_ThresImage.GetImageBuffer(), nWidth, nHeight, m_findParam.nEdgeThreshold)!=1)
    {
        findResult.nResultCode = AlignEdge_BinaryFail;
        return 0;
    }
 
    // step3. Blob Analysis ¿¬»ê
    TRACE(_T("[A2E]CAlignFinder::FindAlignEdge Step3\n"));
 
    if (m_ThresImage.CopyImageTo(&m_BlobImage)==FALSE) 
    {
        findResult.nResultCode = AlignEdge_None;
        return 0;
    }
 
    VectorPixelBlob pixelBlob;
    if (ImageBlobAnalysis((BYTE*)m_BlobImage.GetImageBuffer(), nWidth, nHeight, pixelBlob, 
        m_findParam.nMergeRange, m_findParam.nAlignHeight, m_findParam.nAlignWidth)!=1) 
    {
        findResult.nResultCode = AlignEdge_BlobFail;
        return 0;
    }
 
    //
 
 
    // step4. Blob Matching °ª °è»ê
    TRACE(_T("[A2E]CAlignFinder::FindAlignEdge Step4\n"));
 
    findResult.dMatchValue = pixelBlob[0].dMatchValue;
    if (findResult.dMatchValue<m_findParam.dEdgeRate)
    {
        findResult.nResultCode = AlignEdge_LowScore;
        return 0;
    }
 
    // step5. check blob
    SPixelBlob resultBlob = pixelBlob[0];
 
    // Image Y - Axis is Loss
    if(resultBlob.GetHeight() < m_findParam.nAlignHeight - 10)
    {
        if((m_BlobImage.GetHeight() / 2) < resultBlob.GetCenterY())
        {
            // Loss Bottom
            resultBlob.nBottom = resultBlob.nTop + m_findParam.nAlignHeight;
        }
        else
        {
            // Loss Top
            resultBlob.nTop = resultBlob.nBottom - m_findParam.nAlignHeight;
        }
    }
 
    // Image X - Axis is Loss
    if(resultBlob.GetWidth() < m_findParam.nAlignWidth - 10)
    {
        if((m_BlobImage.GetWidth() / 2) < resultBlob.GetCenterX())
        {
            // Loss Right
            resultBlob.nRight = resultBlob.nLeft + m_findParam.nAlignWidth;
        }
        else
        {
            // Loss Left
            resultBlob.nLeft = resultBlob.nRight - m_findParam.nAlignWidth;
        }
    }
 
    // step6. Make Result À̹ÌÁö
    TRACE(_T("[A2E]CAlignFinder::FindAlignEdge Step5\n"));
    findResult.nResultCode = AlignEdge_Success;
    findResult.dPosX = resultBlob.GetCenterX();
    findResult.dPosY = resultBlob.GetCenterY();
    if (m_SourceImage.CopyImageTo(&m_ResultImage))
    {
        m_ResultImage.DrawRectangle(CPoint(resultBlob.nLeft, resultBlob.nTop), CPoint(resultBlob.nRight, resultBlob.nBottom), RGB(255,255,255), 2);
    }
 
    TRACE(_T("[A2E]CAlignFinder::FindAlignEdge Step6\n"));
 
    return 1;
}