OpenCV:vector数据类型转换

1.vector<Point2f> 和 vector<Point2i>之间相互转换

  1. vector<Point2f>===> vector<Point2i>

    cv::Mat(vector<Point2f>).convertTo(vector<Point2i>,CV_32SC1);
    //这种方式转换会将2.4转换为2;3.5转换为4;-3.4转换为-3,-3.5转换为-4;其他依次类推。类似于cvRound()

    1. vector<Point2i>===> vector<Point2f>

    cv::Mat(vector<Point2i>).convertTo(vector>Point2f>,CV_32FC1);


3.其他3f,3i之类的类似;基本思想:f表示float,4字节(32位),那么等同于32F;

2.Mat —> vector<Point2f> or vector<Point3f> :

用“Mat_<Point2f>“ 和“Mat_<Point3f>”

Mat m;
vector<Point3f> p;
p = Mat_<Point3f>(m);//说明:从Mat的首个元素开始,按照顺序,3个一组作为向量,因此P.size()为:m.cols*m.rows/3;
// 需要注意的是,m的类型。在我的项目中m均采用CV_32FC1类型,F是因为Point3f中的点集为float类型

猜你喜欢

转载自blog.csdn.net/leonardohaig/article/details/81569262