// EdgeFind.h: interface for the CEdgeFind class.
|
//
|
//////////////////////////////////////////////////////////////////////
|
|
#if !defined(AFX_EDGEFIND_H__390230EE_3748_47C9_B543_04276FAFACA4__INCLUDED_)
|
#define AFX_EDGEFIND_H__390230EE_3748_47C9_B543_04276FAFACA4__INCLUDED_
|
|
#if _MSC_VER > 1000
|
#pragma once
|
#endif // _MSC_VER > 1000
|
|
#include "EDGE_DIPM.h"
|
|
class CSISBuffer;
|
class CEdgeProc;
|
|
enum EDGELINE_DIR{DIR_HORIZONTAL=0,DIR_VERTICAL};
|
enum EDGELINE_POLAR{POLAR_WTOB=0,POLAR_BTOW,POLAR_ANY};
|
enum enEdgeFindType{EDGE_MAXCONTRAST=0,EDGE_FIRSTEDGE,EDGE_PROJECTION,EDGE_NONE};
|
enum EdgeSearchType { SearchTypeMinMax, SearchTypeOut2In, SearchTypeIn2Out };
|
enum EdgeSignalType { EdgeTypeNegative=0, EdgeTypePositive, EdgeTypeNone };
|
enum EdgeResultType { EdgeResultMid=0, EdgeResultLeft, EdgeResultRight, };
|
enum SubPixelType { SubPixelLinear=0, SubPixelQuadratic, SubPixelRegression };
|
enum PreProcessType { PreProcNone=0, PreProcSobel };
|
enum TriangleResult { ImageFailModel=-1, ImageFailSource=-2, ImageFailSub=-3, ImageFailBandModel=-4, ImageFailBandSource=-5,
|
RecipeFailModel=-6, RecipeFailMarker=-7, RecipeFailFormula=-8,
|
ProcessFailModel=-9, ProcessFailMarker=-10, ProcessFailFormula=-11,
|
ResultFailModel=-12, ResultFailMarker=-13, ResultFailFormula=-14,
|
EdgeFailLeft=-15, EdgeFailRight=-16, PreProcessFail=-17,
|
ProcessSuccess=1, ProcessNone=0 };
|
|
//Projection data
|
#ifndef _IMPROJ_
|
#define _IMPROJ_
|
enum PROJECTION_TYPE{PROJECTION_VERTICAL=0,PROJECTION_HORIZONTAL};
|
typedef struct ImProj{
|
int x;
|
int f;
|
} IMPROJ, *LPIMPROJ;
|
#endif
|
|
class CPolynomial
|
{
|
public:
|
CPolynomial() { Reset(); }
|
CPolynomial(int degree, double coef)
|
{
|
nDegree = degree;
|
dCoef = coef;
|
}
|
~CPolynomial() { Reset(); }
|
void Reset()
|
{
|
nDegree = 0;
|
dCoef = 0.0;
|
}
|
int nDegree;
|
double dCoef;
|
};
|
|
typedef std::list<CPolynomial*> ListPolynomial;
|
typedef std::list<CPolynomial*>::iterator ListPolynomialIt;
|
|
typedef std::vector<double> VectorDouble;
|
typedef std::vector<double>::iterator VectorDoubleIt;
|
|
typedef std::vector<int> VectorInteger;
|
typedef std::vector<int>::iterator VectorIntegerIt;
|
|
class AFX_EXT_CLASS CEdgeResult
|
{
|
public:
|
CEdgeResult() { Reset(); }
|
|
CEdgeResult(int indexValue, int signalValue, int positionValue, double edgeValue)
|
{
|
|
nIndex = indexValue;
|
nSignal = signalValue;
|
nEdgePosition = positionValue;
|
dEdgeValue = edgeValue;
|
|
nEdgeType = EdgeResultMid;
|
dPosition = 0.0;
|
dStrength = 0.0;
|
|
nLeftPosition = positionValue;
|
nRightPosition = positionValue;
|
}
|
|
CEdgeResult(int indexValue, int signalValue, double positionValue, double strengthValue)
|
{
|
|
nIndex = indexValue;
|
nSignal = signalValue;
|
dPosition = positionValue;
|
dStrength = strengthValue;
|
|
nEdgeType = EdgeResultMid;
|
nLeftPosition = 0;
|
nRightPosition = 0;
|
}
|
|
~CEdgeResult() { Reset(); }
|
|
void Reset()
|
{
|
nEdgeType = EdgeResultMid;
|
nIndex = -1;
|
nSignal = EdgeTypeNone;
|
nEdgePosition = 0;
|
dEdgeValue = 0.0;
|
dPosition = 0.0;
|
dStrength = 0.0;
|
|
nLeftPosition = 0;
|
nRightPosition = 0;
|
}
|
|
int nEdgeType;
|
int nIndex;
|
int nSignal;
|
int nEdgePosition;
|
double dEdgeValue;
|
|
int nLeftPosition;
|
int nRightPosition;
|
|
double dPosition;
|
double dStrength;
|
};
|
typedef std::vector<CEdgeResult> VectorEdgeResult;
|
typedef std::vector<CEdgeResult>::iterator VectorEdgeResultIt;
|
|
class AFX_EXT_CLASS CEdgeFind
|
{
|
CSISBuffer *m_Buffer;
|
LPIMPROJ m_pHproj;
|
LPIMPROJ m_pVproj;
|
VectorDouble m_vectorEdgeData;
|
VectorInteger m_vectorEdgeType;
|
VectorDouble m_vectorImageData;
|
VectorEdgeResult m_vectorEdgeResult;
|
|
public:
|
CEdgeFind();
|
virtual ~CEdgeFind();
|
|
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);
|
|
public:
|
int Find_LeftCanny(CSISBuffer *pBuffer,int nThres);
|
double FindLine_H(LPBYTE pImg,CSize szImg,CRect &rectIns,int nThres,EDGELINE_POLAR enDir,EdgeSignalType enSignalType,enEdgeFindType enFind);
|
double FindLine_V(LPBYTE pImg,CSize szImg,CRect &rectIns,int nThres,EDGELINE_POLAR enDir,EdgeSignalType enSignalType,enEdgeFindType enFind,BOOL bTop);
|
double FindGlassHorizontalLine(LPBYTE pImg,CSize szImg,CRect &rectIns,int nThres,BOOL bDir, int nDist = 20);
|
double FindGlassVerticalLine(LPBYTE pImg,CSize szImg,CRect &rectIns,int nThres,BOOL bDir,int nDist = 10);
|
double FindLineSubPixel(LPBYTE pImg,CSize szImg,CRect &rectIns,int nPosiThres,int nNegaThres,EDGELINE_DIR enDir,EdgeSearchType enSearchType,EdgeSignalType enSignalType,int nKernelSize=2);
|
|
protected:
|
void AssertOnFrameRect(CRect &rect,CSize szImg=CSize(0,0));
|
BOOL FV_ProjGet(LPBYTE src,CSize szImg, CRect &rect, PROJECTION_TYPE type, IMPROJ* res, ULONG* max, ULONG* min);
|
int FindMaxContrastEx(IMPROJ* src, int nStart,int nEnd, long Width, long Height, EDGELINE_POLAR enDir, long Thresh,BOOL bForward=TRUE);
|
int FindFirstEdge(IMPROJ* src, int nStart,int nEnd, long Width, long Height, EDGELINE_POLAR enDir, long Thresh,BOOL bForward=TRUE);
|
int FindMaxContrast(CSISBuffer &bufferOrg,CRect rect,BOOL bHor,int &nMaxDiff,BOOL bForward=TRUE);
|
BOOL QuadraticRegression(VectorDouble& vectorX, VectorDouble& vectorY, double& a0, double& a1, double& a2);
|
bool parabolicInterpolate(double hm, double h0, double hp, double *c);
|
BOOL FindGlssEdgeLine(int &nPos,CRect rect,LPIMPROJ pProj,BOOL bDir,PROJECTION_TYPE nType,int nThres,int nContiValue,int nDist);
|
|
protected:
|
BOOL CalculateInterpolateLinear(CEdgeResult& edgeResult, double dEdgeThreshold);
|
BOOL CalculateInterpolateQuadratic(CEdgeResult& edgeResult);
|
BOOL CalculateInterpolateRegression(CEdgeResult& edgeResult);
|
void CalculateEdgePosition(int nSubPixelType, double dPosiThres, double dNegaThres);
|
BOOL CalculateImageValue(EDGELINE_DIR nDirection, BYTE *pImage, int nWidth, int nHeight, CRect &rect,int nStep, VectorDouble& vectorImageData);
|
BOOL CalculateEdgeValue(const VectorDouble& vectorImageData, VectorDouble& vectorEdgeData, int nKernelSize);
|
BOOL CalculateEdgeValue(const VectorDouble& vectorImageData, VectorDouble& vectorEdgeData, VectorInteger& vectorEdgeType, double dPositiveThres, double dNegativeThres, int nKernelSize);
|
BOOL CalculateEdgeValue(EDGELINE_DIR nDirection, short *pImage, int nWidth, int nHeight, int nStep, VectorDouble& vectorEdgeData, VectorInteger& vectorEdgeType, double dPositiveThres, double dNegativeThres);
|
BOOL GetEdgeLeftPosition(int nEdgeType, int nSearchType, int nStartPos, double& dPosition);
|
BOOL GetEdgeRightPosition(int nEdgeType, int nSearchType, int nStartPos, double& dPosition);
|
|
double AbsSum(double init, double x);
|
double Sum(double init, double x);
|
static double Square(double init, double x);
|
static double Cubic(double init, double x);
|
static double ForthPower(double init, double x);
|
double Combi(VectorDouble& vectorX, VectorDouble& vectorY, int n, int r);
|
void InsertPolynomial(ListPolynomial &listPolynomial, int degree, double coef);
|
void RemovePolynomial(ListPolynomial& listPolynomial);
|
BOOL CalculateLagrange(VectorDouble& vectorX, VectorDouble& vectorY, ListPolynomial& listPolynomial);
|
|
template <class T>
|
inline void imMinMax(const T *map, int count, T& min, T& max)
|
{
|
min = *map++;
|
max = min;
|
for (int i = 1; i < count; i++)
|
{
|
T value = *map++;
|
|
if (value > max)
|
max = value;
|
else if (value < min)
|
min = value;
|
}
|
}
|
};
|
|
|
#endif // !defined(AFX_EDGEFIND_H__390230EE_3748_47C9_B543_04276FAFACA4__INCLUDED_)
|