opencv 数据结构

来源:互联网 发布:e订通软件 编辑:程序博客网 时间:2024/06/05 02:37

首先看OpenCV中最基本的数据结构Point。Point表示平面中或者空间中的一个点。Point可以在需要的时候被转换为固定向量(fixed vector)或者固定矩阵(Matx)类型。
在大部分的程序中,最常见的Point的形式是cv::Point2i 或者cv::Point3f,最后的字母表示构造点的数据类型,这里罗列如下:
b : unsigned character.
s : short integer.
i : 32-bit integer.
f : 32-bit floating-point number.
d: 64-bit floating-point bumber.
Point 最常用的操作:
Default constructor (默认构造函数) : cv::Point2i p;
Copy constructor(复制构造函数):cv::Point3f p2(p1);
Value constructor(赋值构造):cv::Point2i p2(x0,x1);
Cast to the fixed vector classes(转换为固定向量): (cv::Vec3f) p;
Member access(成员访问): p.x; p.y;
dot product (点积): float x = p1.dot(p2);
double precision dot product(双精度点积): doule x = p1.ddot(p2);
Cross product (叉积) : p1.cross(p2); (只对三维点有效)
Query if point p is inside rectangle r (查询点是否在矩形区域内):p.inside(r);

#include "opencv2/imgcodecs.hpp"#include  <iostream>using namespace std;using namespace cv;int main(){    Point2i p2i;    p2i.x = 9;    p2i.y = 10;    cout<<"p2i is : "<<p2i<<endl;    Point2i p3(p2i);    cout<<"p3 is : "<<p3<<endl;    Point3f p3f(8,8,2);    Point3f p3f_2(1,1,1);    cout<<"dot product is: "<<p3f.dot(p3f_2)<<endl;    cout<<"cross product is: "<<p3f.cross(p3f_2)<<endl;    cout<<"cross product is: "<<p3f_2.cross(p3f)<<endl;    Rect r(0,0,20,20);    cout<<"if p2i is inside r: "<<p2i.inside(r)<<endl;}

这里写图片描述

原创粉丝点击