123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658 |
- #pragma once
- #include <math.h>
- #include <string>
- #include <vector>
- #include <fstream>
- //�����MFC�ڵĻ�
- #ifdef AFX_WIN
- #include <afx.h>
- #include <afxwin.h>
- #elif OPENCV_USE
- #include <opencv2/opencv.hpp>
- #elif QT_USE
- #include <QtCore>
- #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 (Right<InferRect.Left
- || Left >InferRect.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<fPoint>& vPoints);
- };
- class fPolygon
- {
- public:
- fRing Outer;
- std::vector<fRing> 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<fPolygon> 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<std::vector<cv::Point>>* Coutours //���ݱ���
- , std::vector<cv::Vec4i>* Coutour_hier
- , int heircount);//���ݼ�ϵ
- bool ReceiveCvCoutour(std::vector<cv::Point>* 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
- };
-
- }
|