#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;
|
}
|