OpenCV3.0基本类型初探(二)

Point_

    point是CV中最基本的类型,其表示一个单个的点,文件中声明如下
template < typename   _Tp >   class   CV_EXPORTS   Point_
 
{
 
public:  
    typedef   _Tp   value_type ;
 
  // various constructors  
    Point_ ();  
    Point_ ( _Tp   _x ,   _Tp   _y );  
    Point_ ( const   Point_ &   pt );  
    Point_ ( const   CvPoint &   pt );  
    Point_ ( const   CvPoint2D32f &   pt );  
    Point_ ( const   Size_ < _Tp >&   sz );  //提供将Size的width和height作为Point的坐标值
    Point_ ( const   Vec < _Tp ,   2 >&   v );  //提供将一个二维的vector转换为Point类型
    Point_ &   operator   =   ( const   Point_ &   pt );//提供Point的赋值,当然两遍的模板类型必须一样,理由参见上一节
 
  //! conversion to another data type  
    template < typename   _Tp2 >   operator   Point_ < _Tp2 > ()   const ;  //显式的转换操作 //注意其与构造函数的参数区别

 //! conversion to the old-style C structures  
    operator   CvPoint ()   const ;  //为旧版本的CvPoint提供兼容接口 //但是我在源码里面没有看到这一段
    operator   CvPoint2D32f ()   const ;  
    operator   Vec < _Tp ,   2 > ()   const ;  
//! dot product 
   
  _Tp   dot ( const   Point_ &   pt )   const ;   //求点积  即返回pt1.x*pt2.x + pt1.y*pt2.y
//! dot product computed in double-precision arithmetics  
    double   ddot ( const   Point_ &   pt )   const ;   //返回为double型的点积
//! cross-product  
    double   cross ( const   Point_ &   pt )   const ;   //求叉积 即返回(double)x*pt.y - (double)y*pt.x;
//! checks whether the point is inside the specified rectangle  
    bool   inside ( const   Rect_ < _Tp >&   r )   const ;   _Tp   x ,   y ;   //检查点是否在矩形区域中
//< the point coordinates  
};  
另外也有一些为了方便使用而设定的类型名
typedef Point_<int> Point2i;
typedef Point_<float> Point2f;
typedef Point_<double> Point2d;
typedef Point2i Point;  
所以说一般我们所使用的Point接受的都是int参数
 其运算方面支持
+ - 和另一个点
* / 和一个常数(double flost 或者int) 

Point3_

和Point_类似,Point3_定义了一个三维空间中的点 
除了多一维度没有什么不同
点积公式为(x*pt.x + y*pt.y + z*pt.z);
叉积公式为(y*pt.z - z*pt.y, z*pt.x - x*pt.z, x*pt.y - y*pt.x)
 同样也有一些方便使用而设置的类型
typedef   Point3_ < int >   Point3i ;
 
typedef   Point3_ < float >   Point3f ;  
typedef   Point3_ < double >   Point3d ;  

Size_

表征 一个具有一定大小的区域,和point类似,只有两个量,但是其意义表示是 width还有 height

 
typedef   Size_ < int >   Size2i ;
typedef   Size2i   Size ;  
typedef   Size_ < float >   Size2f ;  
 几种类型方便使用。

提供area函数返回size表征的面积
template<typename _Tp> inline
_Tp Size_<_Tp>::area() const
{
    return width * height;
}
 

Rect_

 表示一个矩形区域
 基本构造函数为 Rect_ ( _Tp   _x ,   _Tp   _y ,   _Tp   _width ,   _Tp   _height );
可见 其需要提供一个初始点以及一个固定范围构成
当然,也可以通过传入一个Point和一个Size完成Rect的构造
Rect_ ( const   Point_ < _Tp >&   org ,   const   Size_ < _Tp >&   sz );
 
以及通过两个Point描述Rect
Rect_ ( const   Point_ < _Tp >&   pt1 ,   const   Point_ < _Tp >&   pt2 );
 
其也提供类似Szie中的area方法。

需要注意的是 Rect的创建并不会对参数是否合法进行检查,所以请确信自己创建参数是正确的
另外对于contain方法,默认其左上角的点(初始点是包含的)但是右下角(结束点)是不包含在区域之中的
其判别式为
x <= pt.x && pt.x < x + width && y <= pt.y && pt.y < y + height;

以及一些加减操作的重载:
  • \texttt{rect} = \texttt{rect} \pm \texttt{point} (shifting a rectangle by a certain offset)
  • \texttt{rect} = \texttt{rect} \pm \texttt{size} (expanding or shrinking a rectangle by a certain amount)
  • rect += point, rect -= point, rect += size, rect -= size (augmenting operations)
  • rect = rect1 & rect2 (rectangle intersection)
  • rect = rect1 | rect2 (minimum area rectangle containing rect2 and rect3 )
  • rect &= rect1, rect |= rect1 (and the corresponding augmenting operations)
  • rect == rect1, rect != rect1 (rectangle comparison) 
由点和区域表示的 Rect虽然简单,但是也有着很明显的缺陷,比如说用户想要表示一个旋转了一定角度的矩形
这时候就必须将整个图像进行一次旋转操作得到?显然在旋转矩形需求比较大的时候这样的设计思路并不合理
所以CV还给出了一种特殊的矩形

RotatedRect

这个类描述了旋转之后的矩形 
 带参构造函数有如下三种
RotatedRect ( const   Point2f &   center ,   const   Size2f &   size ,   float   angle );  
RotatedRect ( const   CvBox2D &   box );    
RotatedRect ( const   Point2f &   point1 ,   const   Point2f &   point2 ,   const   Point2f &   point3 );  
指定一个普通的Rect参数以及一个旋转量确定RRect时候其旋转将会以rect的中心为旋转点

 

TermCriteria

提供迭代算法的终止条件
 分为循环次数和误差两种条件

  C++:   TermCriteria:: TermCriteria ( int   type , int   maxCount , double   epsilon )
Parameters:
  • type – The type of termination criteria: TermCriteria::COUNTTermCriteria::EPS orTermCriteria::COUNT + TermCriteria::EPS.
  • maxCount – The maximum number of iterations or elements to compute.
  • epsilon – The desired accuracy or change in parameters at which the iterative algorithm stops.
  • criteria – Termination criteria in the deprecated CvTermCriteria format.
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值