#pragma once
|
#include "CHImageControls/CHImageData.h"
|
#include "RecipeTriangle.h"
|
|
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, CircleCoefficientFail=-18,
|
ProcessSuccess=1, ProcessNone=0 };
|
|
typedef std::vector<double> VectorDouble;
|
typedef std::vector<double>::iterator VectorDoubleIt;
|
|
typedef std::vector<int> VectorInteger;
|
typedef std::vector<int>::iterator VectorIntegerIt;
|
|
typedef std::vector<CPoint> VectorPoint;
|
typedef std::vector<CPoint>::iterator VectorPointIt;
|
|
class CPixelRegion
|
{
|
public:
|
int nLeft;
|
int nTop;
|
int nRight;
|
int nBottom;
|
VectorPoint vectorPoint;
|
|
CPixelRegion() { Reset(); }
|
virtual ~CPixelRegion() { Reset(); }
|
|
CPixelRegion(int left, int top, int right, int bottom)
|
{
|
nLeft = left;
|
nTop = top;
|
nRight = right;
|
nBottom = bottom;
|
|
vectorPoint.clear();
|
}
|
|
void Reset()
|
{
|
nLeft = INT_MAX;
|
nTop = INT_MAX;
|
nRight = INT_MIN;
|
nBottom = INT_MIN;
|
|
vectorPoint.clear();
|
}
|
|
int GetSquareSize() const { return (nRight-nLeft+1) * (nBottom-nTop+1); }
|
int GetWidth() const { return (nRight-nLeft+1); }
|
int GetHeight() const { return (nBottom-nTop+1); }
|
int GetCenterX() const { return nLeft + (nRight - nLeft + 1) / 2; }
|
int GetCenterY() const { return nTop + (nBottom - nTop + 1) / 2; }
|
int GetMaxSize() const { return (GetWidth() < GetHeight()) ? GetHeight(): GetWidth(); }
|
int GetMinSize() const { return (GetWidth() > GetHeight()) ? GetHeight(): GetWidth(); }
|
size_t GetPixelCount() const { return vectorPoint.size(); }
|
};
|
typedef std::vector<CPixelRegion> VectorPixelRegion;
|
typedef std::vector<CPixelRegion>::iterator VectorPixelRegionIt;
|
|
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 = EdgeResult_Mid;
|
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 = EdgeResult_Mid;
|
nLeftPosition = 0;
|
nRightPosition = 0;
|
}
|
|
~CEdgeResult() { Reset(); }
|
|
void Reset()
|
{
|
nEdgeType = EdgeResult_Mid;
|
nIndex = -1;
|
nSignal = EdgeSignal_None;
|
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 CEdgeTriangle
|
{
|
public:
|
CEdgeTriangle(void);
|
~CEdgeTriangle(void);
|
void Reset()
|
{
|
m_imageSource.ReleaseImage();
|
m_imageModel.ReleaseImage();
|
m_recipeTriangle.Reset();
|
m_resultTriangle.Reset();
|
}
|
|
|
VectorDouble GetImageData() { return m_vectorImageData; }
|
VectorDouble GetEdgeData() { return m_vectorEdgeData; }
|
VectorInteger GetEdgeType() { return m_vectorEdgeType; }
|
VectorEdgeResult GetEdgeResult() { return m_vectorEdgeResult; }
|
|
// getter
|
CRecipeTriangle* GetRecipeTriangle() { return &m_recipeTriangle; }
|
CResultTriangle* GetResultTriangle() { return &m_resultTriangle; }
|
|
// setter
|
BOOL SetImageSource(CCHImageData* imageSource);
|
BOOL SetImageModel(CCHImageData* imageModel);
|
BOOL SetRecipeTriangle(const CRecipeTriangle& recipeTriangle);
|
|
// reset
|
void ResetImageSource() { m_imageSource.ReleaseImage(); }
|
void ResetImageModel() { m_imageModel.ReleaseImage(); }
|
void ResetRecipeTriangle() { m_recipeTriangle.Reset(); }
|
void ResetResultTriangle() { m_resultTriangle.Reset(); }
|
|
// process function
|
int ProcessModel();
|
int ProcessModel(CCHImageData* imageSource, const CRecipeModel& recipeModel);
|
int ProcessModel(CCHImageData* imageSource, const VectorRecipeModel& vectorRecipeModel);
|
int ProcessModel(CCHImageData* imageModel, CCHImageData* imageSource, const CRecipeModel& recipeModel);
|
int ProcessModel(CCHImageData* imageModel, CCHImageData* imageSource, const VectorRecipeModel& vectorRecipeModel);
|
|
int ProcessMarker();
|
int ProcessMarker(CCHImageData* imageSource, const CRecipeMarker& recipeMarker);
|
int ProcessMarker(CCHImageData* imageSource, const VectorRecipeMarker& vectorRecipeMarker);
|
|
int ProcessModelMarker();
|
int ProcessModelMarker(CCHImageData* imageSource, const CRecipeModel& recipeModel, const CRecipeMarker& recipeMarker);
|
int ProcessModelMarker(CCHImageData* imageSource, const CRecipeModel& recipeModel, const VectorRecipeMarker& vectorRecipeMarker);
|
int ProcessModelMarker(CCHImageData* imageSource, const VectorRecipeModel& vectorRecipeModel, const VectorRecipeMarker& vectorRecipeMarker);
|
int ProcessModelMarker(CCHImageData* imageModel, CCHImageData* imageSource, const CRecipeModel& recipeModel, const CRecipeMarker& recipeMarker);
|
int ProcessModelMarker(CCHImageData* imageModel, CCHImageData* imageSource, const CRecipeModel& recipeModel, const VectorRecipeMarker& vectorRecipeMarker);
|
int ProcessModelMarker(CCHImageData* imageModel, CCHImageData* imageSource, const VectorRecipeModel& vectorRecipeModel, const VectorRecipeMarker& vectorRecipeMarker);
|
|
int ProcessMarkerFormula();
|
int ProcessMarkerFormula(CCHImageData* imageSource, const CRecipeMarker& recipeMarker, const CRecipeFormula& recipeFormula);
|
int ProcessMarkerFormula(CCHImageData* imageSource, const VectorRecipeMarker& vectorRecipeMarker, const VectorRecipeFormula& vectorRecipeFormula);
|
|
int ProcessTriangle();
|
int ProcessTriangle(CCHImageData* imageSource);
|
int ProcessTriangle(CCHImageData* imageSource, const CRecipeTriangle& recipeTriangle);
|
int ProcessTriangle(CCHImageData* imageModel, CCHImageData* imageSource, const CRecipeTriangle& recipeTriangle);
|
|
// static func
|
static int ImageResizeHalf(CCHImageData* pSource, CCHImageData* pResult);
|
static int ImageResizeQuarter(CCHImageData* pSource, CCHImageData* pResult);
|
static int ImageResizeOneEighth(CCHImageData* pSource, CCHImageData* pResult);
|
static BOOL ImageSobelEdge(CCHImageData* pSource, CCHImageData* pResult);
|
|
static BOOL GetImageData(CCHImageData* pSubImage, VectorDouble& vectorImageData);
|
static BOOL GetEdgeData(CCHImageData* pSubImage, VectorDouble& vectorEdgeData, int nKernelSize, double dKernelSigma);
|
static BOOL GetEdgeData(int& nBandType, CCHImageData* pSubImage, VectorDouble& vectorEdgeData, int nKernelSize, double dKernelSigma);
|
|
static double AbsSum(double init, double x);
|
static 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);
|
|
static int ImageSobelEdge(BYTE* pSrcImage, BYTE *pDstImage, int nWidth, int nHeight);
|
static int ImageAverage(BYTE* pSrcImage, BYTE *pDstImage, int nWidth, int nHeight);
|
static int ImageThresholding(BYTE* pImage, int nWidth, int nHeight, int nThresValue);
|
static int ImageThinning(BYTE* pImage, int nWidth, int nHeight);
|
static int ImageBlobAnalysis(BYTE *pImage, int nWidth, int nHeight, VectorPixelRegion& vectorRegion, int nBlobMargin=-1);
|
|
static int ImageErode(BYTE* pSrcImage, BYTE *pDstImage, int nWidth, int nHeight);
|
static int ImageDilate(BYTE* pSrcImage, BYTE *pDstImage, int nWidth, int nHeight);
|
static int ImageExclusiveOR(BYTE* pSrcImage1, BYTE *pSrcImage2, BYTE* pDstImage, int nWidth, int nHeight);
|
static int ImageAND(BYTE* pSrcImage1, BYTE *pSrcImage2, BYTE* pDstImage, int nWidth, int nHeight);
|
static int ImageOR(BYTE* pSrcImage1, BYTE *pSrcImage2, BYTE* pDstImage, int nWidth, int nHeight);
|
|
// check func
|
static BOOL CheckFormulationString(const CString& strFormulation, CString& strResultFormulation, CRecipeTriangle* pRecipeTriangle=NULL);
|
|
private:
|
// internal process
|
int FormulaProcess();
|
int MarkerProcess(CCHImageData *imageSource);
|
int MarkerFormulaProcess(CCHImageData *imageSource);
|
int ModelProcess(CCHImageData *imageModel, CCHImageData *imageSource);
|
int ModelMarkerProcess(CCHImageData *imageModel, CCHImageData *imageSource);
|
int TriangleProcess(CCHImageData *imageModel, CCHImageData *imageSource);
|
|
// model func
|
BOOL MatchImage(CCHImageData *pSource, CCHImageData *pModel, CRect* pRect, double dScore, int& nPosX, int& nPosY, double& dResult);
|
BOOL MatchImage(CCHImageData *pSource, CCHImageData *pModel, CRect* pRect, double dScore, double& dPosX, double& dPosY, double& dResult);
|
int MatchFull(CCHImageData *pSource, CCHImageData *pModel, const CRecipeModel *pRecipeModel, CResultModel& resultModel);
|
int MatchLevel(CCHImageData *pSource, CCHImageData *pModel, const CRecipeModel *pRecipeModel, CResultModel& resultModel);
|
static void GetMinLocation(float *pImage, int nWidth, int nHeight, int nStep, int& nPosX, int& nPosY, double& dValue);
|
static void GetMaxLocation(float *pImage, int nWidth, int nHeight, int nStep, int& nPosX, int& nPosY, double& dValue);
|
|
// Marker func
|
int MeasureImage(CCHImageData *imageSource, const CRecipeMarker* pRecipeMarker, CResultMarker& resultMarker);
|
int Process_MeasureLine(CCHImageData& imageData, const CRecipeMarker* pRecipeMarker, CResultMarker& resultMarker);
|
int Process_MeasureCircle(CCHImageData& imageData, const CRecipeMarker* pRecipeMarker, CResultMarker& resultMarker);
|
int Process_MeasureEllipse(CCHImageData& imageData, const CRecipeMarker* pRecipeMarker, CResultMarker& resultMarker);
|
void CalculateEdgePosition(int nSubPixelType, double dPosiThres, double dNegaThres, int nIteration=0);
|
|
BOOL CalculateInterpolateLinear(CEdgeResult& edgeResult, double dEdgeThreshold);
|
BOOL CalculateInterpolateQuadratic(CEdgeResult& edgeResult);
|
BOOL CalculateInterpolateGaussian(CEdgeResult& edgeResult, int nEdgeType);
|
BOOL CalculateInterpolateQuadraticRegression(CEdgeResult& edgeResult);
|
BOOL CalculateInterpolateGaussianRegression(CEdgeResult& edgeResult, int nEdgeType);
|
BOOL CalculateInterpolateGaussianRegressionReweight(CEdgeResult& edgeResult, int nEdgeType, int nIteartion);
|
|
|
BOOL GetEdgeLeftPosition(int nEdgeType, int nSearchType, int nStartPos, int nEndPos, double& dPosition);
|
BOOL GetEdgeRightPosition(int nEdgeType, int nSearchType, int nStartPos, int nEndPos, double& dPosition);
|
BOOL GetResultFormulation(const CString& strFormulation, CString& strResultFormulation);
|
|
static BOOL CalculateImageValue(int nDirection, BYTE *pImage, int nWidth, int nHeight, int nStep, VectorDouble& vectorImageData);
|
static BOOL CalculateEdgeValue(const VectorDouble& vectorImageData, VectorDouble& vectorEdgeData, int nKernelSize, double dKernelSigma);
|
static BOOL CalculateEdgeValue(const VectorDouble& vectorImageData, VectorDouble& vectorEdgeData, VectorInteger& vectorEdgeType, double dPositiveThres, double dNegativeThres, int nKernelSize, double dKernelSigma);
|
static BOOL CalculateEdgeValue(int nDirection, short *pImage, int nWidth, int nHeight, int nStep, VectorDouble& vectorEdgeData, VectorInteger& vectorEdgeType, double dPositiveThres, double dNegativeThres);
|
|
|
CCHImageData m_imageSource;
|
CCHImageData m_imageModel;
|
|
CRecipeTriangle m_recipeTriangle;
|
CResultTriangle m_resultTriangle;
|
|
VectorDouble m_vectorImageData;
|
VectorDouble m_vectorEdgeData;
|
VectorInteger m_vectorEdgeType;
|
VectorEdgeResult m_vectorEdgeResult;
|
|
};
|