OpenCV3.0基本类型初探(二)
2015-09-25 08:58
239 查看
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;
以及一些加减操作的重载:
(shifting
a rectangle by a certain offset)
(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::COUNT, TermCriteria::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. |
---|
相关文章推荐
- 架构之路(二):性能
- 架构之路(一):目标
- Docker container 集装箱说明
- 每天一个linux命令(8):cp 命令
- 如何用 Bash 创建一个二进制发布包
- Windows 下令 OpenCV 支持 h.264 视频编码的方法
- Linux内核学习之路:认识内核版本
- CentOS-6.5在线安装docker-1.7教程(升级内核)
- CentOS-6.5在线安装docker-1.7教程
- linux和max下使用tomcat
- linux学习之shell练习
- 加密解密基础、PKI及SSL、创建私有CA
- linux文件权限
- linux文件操作之ls、mkdir、rmdir、cp命令使用
- CentOS 7 使用点滴
- Linux系统中掩耳盗铃的sudo配置
- Linux中搭建FTP服务器的方法
- PHP网站建设的流程与步骤分享
- 网站关键词优化--要怎么6样提高关键词的排名
- 天津网站建设-文率科技天津众多网站建设中的楷模