zoukankan      html  css  js  c++  java
  • (转)Mat, vector<point2f>,Iplimage等等常见类型转换

    在mfc c++ 以及opencv 编写程序当中,很多常用的类型转换,现在总结一下。(注意加相应的头文件,这里不罗嗦)

    提纲:

    1. Mat ---> Iplimage
    2. Iplimage  --->  CvvImage
    3. Mat  ---> vector<Point2f> or vector<Point3f>
    4. vector<Point2f> or vector<Point3f>  --->  vector<vector<Point2f>> or vector<vector<Point3f>>

    5. vector<vector<Point2f>> or vector<vector<Point3f>>  ---> Mat

    6. vector<Point2f> or vector<Point3f>  --->  Mat

    图像类

    1. Mat ---> Iplimage :直接赋值 

    Mat img;  
    Iplimage myImg = img;  

    2. Iplimage  --->  CvvImage :用“Copyof ”

    CvvImage cImg;  
    Iplimage myimg;  
    cImg.Copyof(myimg, -1);  

    数据类

    3. Mat  ---> vector<Point2f> or vector<Point3f> :用“Mat_<Point2f>“ ,“Mat_<Point3f>”

    Mat m;  
    vector<Point3f> p;  
    p = Mat_<Point3f>(m);  

    4. vector<Point2f> or vector<Point3f>  --->  vector<vector<Point2f>> or vector<vector<Point3f>> :用“pushback”

    vector<Point3f> p1,p2,p3;
    vector<vector<Point3f>> pp;
    pp.pushback(p1);
    pp.pushback(p2);
    pp.pushback(p3);

    5. vector<vector<Point2f>> or vector<vector<Point3f>>  ---> Mat

    复制代码
    vector<vector<Point3f>> p;
    Mat pm((int)p.size(), p[0].size(), CV_32FC3);
    
    for( int i = 0; i < (int)p.size(); i++ )
    {
        Mat r = pm.row(i).reshape(3, pm.cols);
        Mat pm1(p[i]);
        pm1.copyTo(r);
    }
    复制代码

    6. vector<Point2f> or vector<Point3f>  --->  Mat :用“Mat(Point3f)"

    vector<Point3f> p;
    Mat m = Mat(p);
  • 相关阅读:
    如何测试复杂的逻辑
    Docker 安装nginx和tomcat
    提高英语
    2020年终总结
    在互联网上班是什么感觉?
    已经过去2周了,你感觉怎么样?
    如何使用玩弄 macOS 的「聚焦搜索」
    如何使用玩弄 macOS 的「聚焦搜索」
    [sdoi2015]排序(搜索+剪枝优化)
    [sdoi 2010][bzoj 1925]地精部落(神仙dp)
  • 原文地址:https://www.cnblogs.com/byteHuang/p/7478030.html
Copyright © 2011-2022 走看看