#pragma once enum CORNERCUR_DIR{CO_LT=0,CO_LB,CO_RT,CO_RB}; enum ERRCODE_CORNERCUT{ERR_CO_IMAGENULL=0,ERR_CO_INSRECTNULL,ERR_CO_FINDVERT,ERR_CO_FINDHOR,ERR_CO_SUCCESS}; struct sCoPoint { double x, y; }; struct sCoLine { double mx, my; double sx, sy; }; using namespace std; class AFX_EXT_CLASS CCornerCut { public: CCornerCut(void); ~CCornerCut(void); public: ERRCODE_CORNERCUT Inspection(LPBYTE pImg,CSize szImg,CRect &rectIns,int iFrame,int nLowThres,int nHighThres,CORNERCUR_DIR nDir, CString strHPanelID,BOOL bSaveImage ,COwnerBuffer &pOrg,double &dResWidth,double &dResHeight); void GetData(sCoPoint *pPoint){CopyMemory(pPoint,m_nCornerPoint,sizeof(sCoPoint)*3);} protected: BOOL FindOuterLine(LPBYTE pImg,CRect rectIns,CORNERCUR_DIR nDir); BOOL FindOuterHori(LPBYTE pImg,CRect rectIns,double nYPos,double nStartX,CORNERCUR_DIR nDir); BOOL FindOuterVert(LPBYTE pImg,CRect rectIns,double nYPos,double nStartX,CORNERCUR_DIR nDir); void SaveMarkImage(LPBYTE pBuffer,CRect &rectIns); void AssertOnFrameRect(CRect &rect,CSize szImg=CSize(0,0)); float AdaptiveThreshold(BYTE* pImageData, int nWidth, int nHeight, int nStep, int nThresValue); float GetThresholdValue(BYTE* pImageData, int nWidth, int nHeight, int nStep, int nThresValue); BOOL CopyEdgeImg(LPBYTE pImg,CSize szImg,CRect &rectIns); void ThresholdProcessing(LPBYTE pImg,CSize szImg,int nThres,int nDir); void ThresholdProcLowHigh(CSISBuffer &pImg,int nLowThres,int nHighThres); BOOL FindVerticalLine(LPBYTE pImg,CRect rectIns,int &nVertLine,CORNERCUR_DIR nDir); BOOL FindHorizontalLine(LPBYTE pImg,CRect rectIns,int &nHorLine,CORNERCUR_DIR nDir); BOOL FindCornerPoint(LPBYTE pImg,CRect rectIns,sCoPoint point,CORNERCUR_DIR nDir); int DetectLine(LPBYTE pImg,CRect rectIns,sCoPoint point,BOOL bDir,BOOL bReverse,CORNERCUR_DIR nDir,sCoPoint &pointResult); void GetRegionInfo(sCoPoint point,CORNERCUR_DIR nDir,BOOL bDir,int &nStart,int &nEnd,BOOL &bReverse,int nWidth,int nHeight); int GetHorCount(LPBYTE pImg,int v,sCoPoint point,BOOL bDir,int nWidth,int nSetCount); int GetVertCount(LPBYTE pImg,int u,sCoPoint point,BOOL bDir,int nWidth,int nHeight,int nSetCount); void CalculateLenght(double &dResWidth,double &dResHeight); template inline void swapN(T a,T b) { T c; c = a; a = b; b = c; } inline void swapLong(LONG &a,LONG &b) { LONG c; c = a; a = b; b = c; } protected: BOOL FindFirstPoint(CRect &rectIns); double ransac_line_fitting(sCoPoint *data, int no_data, sCoLine &model, double distance_threshold); bool find_in_samples (sCoPoint *samples, int no_samples, sCoPoint *data); void get_samples (sCoPoint *samples, int no_samples, sCoPoint *data, int no_data); int compute_model_parameter(sCoPoint samples[], int no_samples, sCoLine &model); double compute_distance(sCoLine &line, sCoPoint &x); double model_verification (sCoPoint *inliers, int *no_inliers, sCoLine &estimated_model, sCoPoint *data, int no_data, double distance_threshold); BOOL LineInterSection(CPoint p1,CPoint p2,CPoint p3,CPoint p4,double &dInterX,double &dInterY); void bresenham_Line(COwnerBuffer *pRes,CPoint posStart,CPoint posEnd,BYTE color); protected: LPBYTE m_pInsImg; sCoPoint m_nCornerPoint[3]; sCoPoint *m_pOuterLineH,*m_pOuterLineV; int m_nOuterCountH,m_nOuterCountV; };