#pragma once #include #include #include #include //�����MFC�ڵĻ� #ifdef AFX_WIN #include #include #elif OPENCV_USE #include #elif QT_USE #include #endif namespace MfcLabel { class Point { public: Point() { x = 0; y = 0; } Point(int x, int y) { this->x = x; this->y = y; } void SetZero() { x = 0; y = 0; } void offset(int x, int y) { this->x += x; this->y += y; } void SetPoint(int x, int y) { this->x = x; this->y = y; } bool operator==(const Point refer) { if (this->x == refer.x && this->y == refer.y) return true; else return false; } public: int x; int y; }; class fPoint { public: fPoint(float fX, float fY) { x = fX; y = fY; } fPoint() { x = 0; y = 0; } void SetZero() { x = 0; y = 0; } void offset(float x, float y) { this->x += x; this->y += y; } void SetPoint(float x, float y) { this->x = x; this->y = y; } bool operator==(const fPoint refer) { if (fabs(this->x - refer.x) < DBL_EPSILON && fabs(this->y - refer.y) < DBL_EPSILON) return true; else return false; } #ifdef AFX_WIN CPoint TurnFloat2Int() { CPoint tmp; tmp.x = (LONG)x; tmp.y = (LONG)y; return tmp; } void operator=(POINT &Copy) { x = Copy.x; y = Copy.y; } #elif QT_USE QPoint TurnFloatToInt() { QPoint temp; temp.setX(int(x)); temp.setY(int(y)); return temp; } fPoint(const QPoint& point) { x = point.x(); y = point.y(); } void operator=(QPoint Copy) { x = Copy.rx(); y = Copy.ry(); } void operator()(QPoint Copy) { x = Copy.x(); y = Copy.y(); } #endif // AFX_WIN double GetVectorProduct(fPoint B); fPoint VectorSub(fPoint B); float x; float y; }; class fRect { public: float Left; float Right; float Top; float Bottom; fRect() { this->Left = 0; this->Right = 0; this->Top = 0; this->Bottom = 0; } fRect(float Left, float Right, float Top, float Bottom) { this->Left = Left; this->Right = Right; this->Top = Top; this->Bottom = Bottom; } float Width() { return fabs(Right - Left); } float Height() { return fabs(Bottom - Top); } void SetRectEmpty() { Left = 0; Right = 0; Top = 0; Bottom = 0; } bool JudgePtInRectBoxOrNot(fPoint TestPt); #ifdef AFX_WIN CRect TrunFloat2Int() { CRect Int_Current_image_rect; Int_Current_image_rect.top = (int)Top; Int_Current_image_rect.left = (int)Left; Int_Current_image_rect.bottom = (int)Bottom; Int_Current_image_rect.right = (int)Right; return Int_Current_image_rect; } void operator=(CRect& Copy) { Left = (float)Copy.left; Top = (float)Copy.top; Right = (float)Copy.right; Bottom = (float)Copy.bottom; } #elif QT_USE fRect(const QRectF& Rect) { this->Left = Rect.left(); this->Right = Rect.right(); this->Top = Rect.top(); this->Bottom = Rect.bottom(); } QRect TrunFloat2Int() { QRect temp; temp.setLeft(int(Left)); temp.setTop(int(Top)); temp.setRight(int(Right)-1); temp.setBottom(int(Bottom)-1); return temp; } QRectF TrunFloat2Float() { QRectF temp; temp.setLeft(int(Left)); temp.setTop(int(Top)); temp.setRight(int(Right)); temp.setBottom(int(Bottom)); return temp; } void operator=(QRect Copy) { Left = Copy.left(); Top = Copy.top(); Right = Copy.right() -1 ; Bottom = Copy.bottom()-1; } void operator=(QRectF Copy) { Left = Copy.left(); Top = Copy.top(); Right = Copy.right()-1; Bottom = Copy.bottom()-1; } #endif // AFX_WIN void offset(float x, float y) { Left = Left + x; Right = Right + x; Top = Top + y; Bottom = Bottom + y; } void Scale(float dbScale) { Left = Left * dbScale; Top = Top * dbScale; Right = Right * dbScale; Bottom = Bottom * dbScale; //Right = Left + (Right - Left)* dbScale; //Bottom = Top + (Bottom - Top) * dbScale; } //���ص����ཻ�ľ��� fRect IntersectRect(fRect& InferRect) { fRect frcRes; if (!JudgeInterOtherRect(InferRect)) { frcRes.Top = 0; frcRes.Bottom = 0; frcRes.Left = 0; frcRes.Right = 0; return frcRes; } else { if (Left <= InferRect.Left) frcRes.Left = InferRect.Left; else frcRes.Left = Left; if (Right <= InferRect.Right) frcRes.Right = Right; else frcRes.Right = InferRect.Right; if (Top <= InferRect.Top) frcRes.Top = InferRect.Top; else frcRes.Top = Top; if (Bottom <= InferRect.Bottom) frcRes.Bottom = Bottom; else frcRes.Bottom = InferRect.Bottom; } return frcRes; } bool JudgeInterOtherRect(fRect& InferRect) { if (RightInferRect.Right || Top > InferRect.Bottom || Bottom < InferRect.Top) { return false; } return true; } }; class Rect { public: Rect() { Left = 0; Right = 0; Top = 0; Bottom = 0; Width = 0; Height = 0; } Rect(int Left, int Top, int Width, int Height) { this->Left = Left; this->Right = Left + Width; this->Top = Top; this->Bottom = Top + Height; this->Width = Width; this->Height = Height; } void SetRectEmpty() { Left = 0; Right = 0; Top = 0; Bottom = 0; } int GetWidth() { return Right - Left; } int GetHeight() { return Bottom - Top; } void SetWidth(int nWidth) { Right = Left + nWidth; Width = nWidth; } void SetHeight(int nHeight) { Bottom = Top + nHeight; Height = nHeight; } void operator=(fRect Copy) { Left = (int)Copy.Left; Top = (int)Copy.Top; Right = (int)Copy.Right; Bottom = (int)Copy.Bottom; Width = (int)Copy.Width(); Height = (int)Copy.Height(); } public: int Left; int Right; int Top; int Bottom; int Width; int Height; }; //�ؼ��� class KeyPoint { //�ؼ��㶨λ fPoint KPoint; //�õ����� std::string Name; //�÷� float Score; //�Ƕ� float angle; //�뾶 float radius; }; //��״��ṹ class fRing { public: fPoint * pPoints; int m_nPointsCount; fRect RectBox; //Ĭ��Ϊ�պϵ� bool isClosed; int size() { return m_nPointsCount; } fPoint* At(int index) { if (pPoints == NULL) { return NULL; } return &pPoints[index]; } ~fRing() { delete[] pPoints; pPoints = NULL; m_nPointsCount = 0; } fRing() { pPoints = NULL; m_nPointsCount = 0; isClosed = true; } //ʹ����������صĿ�������,Ҳ��ֱ�Ӷ��Ѿ�������Ring�ṹ��ֵ fRing operator=(const fRing& another) { //���֮ǰRing֮ǰ�������ݵĻ�������ɾ�� if (pPoints == NULL) { delete[] pPoints; } m_nPointsCount = another.m_nPointsCount; pPoints = new fPoint[m_nPointsCount]; isClosed = another.isClosed; RectBox.Left = 65535; RectBox.Top = 65535; RectBox.Bottom = 0; RectBox.Right = 0; for (int i = 0; i < m_nPointsCount; i++) { pPoints[i] = another.pPoints[i]; RectBox.Left = fmin(pPoints[i].x, RectBox.Left); RectBox.Top = fmin(pPoints[i].y, RectBox.Top); RectBox.Right = fmax(pPoints[i].x, RectBox.Right); RectBox.Bottom = fmax(pPoints[i].y, RectBox.Bottom); } return *this; } //�������캯��,vector��Push_back�������ø÷���,������Ч��ֹ��ַ���� fRing(const fRing& src) { m_nPointsCount = src.m_nPointsCount; pPoints = new fPoint[m_nPointsCount]; for (int i = 0; i < m_nPointsCount; i++) { pPoints[i] = src.pPoints[i]; } isClosed = src.isClosed; RectBox = src.RectBox; //edge_Box.fLeft = 65535; //edge_Box.fTop = 65535; //edge_Box.fBottom = 0; //edge_Box.fRight = 0; } void ComputeBox() { RectBox.Left = 65535; RectBox.Top = 65535; RectBox.Bottom = 0; RectBox.Right = 0; for (int i = 0; i < m_nPointsCount; i++) { RectBox.Left = fmin(pPoints[i].x, RectBox.Left); RectBox.Top = fmin(pPoints[i].y, RectBox.Top); RectBox.Right = fmax(pPoints[i].x, RectBox.Right); RectBox.Bottom = fmax(pPoints[i].y, RectBox.Bottom); } } float Area(); bool JudgePtInRingOrNot(fPoint TestPt); bool JudgeRingIntersectOrNot(fRing& TestRing); //���������溯���� bool JudgeTwoSegmentIntersect(fPoint& FirstLineStartPt, fPoint& FirstLineEndPt, fPoint& SecondLineStartPt, fPoint& SecondLineEndPt); fRect GetRectWithTwoPoint(fPoint& Pt1, fPoint& Pt2); bool JudgeRectBoxIntersectOrNot(fRect& Rect1, fRect& Rect2); fPoint GetTwoSegmentIntersectPt(fPoint FstStartPt, fPoint FstEndPt, fPoint SecStartPt, fPoint SecEndPt); fRing GetTwoRingIntersectRing(fRing& FstRing, fRing& SecRing); //�ж�a����b���˳ʱ�뷽������ʱ�뷽�� bool PointCmp(const fPoint &a, const fPoint &b, const fPoint ¢er); //��ʱ��㼯���� void ClockwiseSortPoints(std::vector& vPoints); }; class fPolygon { public: fRing Outer; std::vector Inner; std::string name; float score; int iInnerCount; int InnerCount() { return iInnerCount; } fPolygon() { iInnerCount = 0; score = 0; name = "unKnown"; } fPolygon(const fPolygon& src) { iInnerCount = src.iInnerCount; Outer = src.Outer; Inner.resize(src.iInnerCount); name = src.name; score = src.score; for (int i = 0; i < src.iInnerCount; i++) { Inner[i] = src.Inner[i]; } } ~fPolygon() { Inner.clear(); iInnerCount = 0; } }; class mfcLabel { public: std::string modelName = "ModeUnKnown"; float score = 0; std::string filePath; std::vector polygons; int iPolyCount; void Destory() { polygons.clear(); iPolyCount = 0; } ~mfcLabel() { polygons.clear(); iPolyCount = 0; } /***************************����opencv������������Ľ���****************************************/ #ifdef OPENCV_USE //�ú�����Ӧ����cv::findcoutours �в����趨ΪCV_RETR_CCOMP�ò�����ֻ�и��ӹ�ϵ void AnalysisCvCoutour(std::vector>* Coutours //���ݱ��� , std::vector* Coutour_hier , int heircount);//���ݼ�ϵ bool ReceiveCvCoutour(std::vector* coutour, bool Notinner, MfcLabel::fRing* ring); #endif bool Empty(); #ifdef AFX_WIN BOOL ShowLabelInCDC(CDC* pDC); BOOL Serialize_S(); BOOL Serialize_L(); //���л������л��ַ��� void Serialize_StringS(CArchive& ar, std::string& szString); void Serialize_StringL(CArchive& ar, std::string& szString); //���л������л�Point������Ring void Serialize_fPointArrayS(CArchive& ar, fRing* pfsend); void Serialize_fPointArrayL(CArchive& ar, fRing* pfreceive); //���л������л�Ring�ļ���polygon void Serialize_fpolygonS(CArchive& ar, fPolygon* pfsend); void Serialize_fpolygonL(CArchive& ar, fPolygon* pfreceive); /***************************����opencv������������Ľ���****************************************/ #endif // AFX_WIN }; }