Opencv内中Point是很重要的数据结构,因为图像都是有点(Point)组成的。所以一定要弄明白Point类。
Point是一个模板类,定义如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
template<typename _Tp> class Point_ { public: typedef _Tp value_type; //! default constructor Point_(); Point_(_Tp _x, _Tp _y); Point_(const Point_& pt); Point_(const Size_<_Tp>& sz); Point_(const Vec<_Tp, 2>& v); Point_& operator = (const Point_& pt); //! conversion to another data type template<typename _Tp2> operator Point_<_Tp2>() const; //! conversion to the old-style C structures operator Vec<_Tp, 2>() const; //! dot product _Tp dot(const Point_& pt) const; //! dot product computed in double-precision arithmetics double ddot(const Point_& pt) const; //! cross-product double cross(const Point_& pt) const; //! checks whether the point is inside the specified rectangle bool inside(const Rect_<_Tp>& r) const; _Tp x; //!< x coordinate of the point _Tp y; //!< y coordinate of the point }; |
Opencv中将Point_类模板重新取别名如下:
1 2 3 4 5 |
typedef Point_<int> Point2i; //int类型Point_ typedef Point_<int64> Point2l; //int64类型Point_ typedef Point_<float> Point2f; //flota类型Point_ typedef Point_<double> Point2d; //double类型Point_ typedef Point2i Point; //int类型Point,因为int类型使用相对多些,再次重取名,编 写代码更方便 |
Point_类具体使用例:
1 2 3 4 |
Point2f point2f1(2.2,3); Point2f point2f2(1, 8); Point2f p3f = point2f1 + point2f2; cout << p3f.x << " " << p3f.y << endl; |
Point_类测试结果:
1 |
3.2 11 |