opencv 数据结构

#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>

using namespace std;
using namespace cv;


int main(int, char**)
{
    Mat I = Mat::eye(4, 4, CV_64F);
    I.at<double>(3, 3) = CV_PI;
    cout << "\nI = \n " << I << ";\n" << endl;

    Mat r = Mat(2, 3, CV_8UC3);
    randu(r, Scalar::all(0), Scalar::all(255));

    cout << "r (OpenCV默认风格) = " << r << ";" << endl << endl;
    //    cout << "r (Python风格) = " << format(r,"python") << ";" << endl << endl;
    //    cout << "r (Numpy风格) = " << format(r,"numpy") << ";" << endl << endl;
    //    cout << "r (逗号分隔风格) = " << format(r,"csv") << ";" << endl<< endl;
    //    cout << "r (C语言风格) = " << format(r,"C") << ";" << endl << endl;


    // 1 定义和输出二维点
    Point2f p(6, 2);
    cout << "【2维点】p = " << p << ";\n" << endl;

    // 2 定义和输出三维点
    Point3f p3f(8, 2, 0);
    cout << "【3维点】p3f = " << p3f << ";\n" << endl;

    // 3 定义和输出Mat的std::vector
    vector<float> v;
    v.push_back(3);
    v.push_back(5);
    v.push_back(7);
    cout << "【基于Mat的vector】shortvec = " << Mat(v) << ";\n" << endl;

    vector<Point2f> points(5);
    for (size_t i = 0; i < points.size(); ++i)
        points[i] = Point2f((float)(i * 5), (float)(i % 7));
    cout << "【二维点向量】points = \n " << points << ";";


    getchar();//按任意键退出

    return 0;

}
I =
 [1, 0, 0, 0;
 0, 1, 0, 0;
 0, 0, 1, 0;
 0, 0, 0, 3.141592653589793];

r (OpenCV默认风格) = [ 91,   2,  79, 179,  52, 205, 236,   8, 181;
 239,  26, 248, 207, 218,  45, 183, 158, 101];

【2维点】p = [6, 2];

【3维点】p3f = [8, 2, 0];

【基于Mat的vector】shortvec = [3;
 5;
 7];

【二维点向量】points =
 [0, 0;
 5, 1;
 10, 2;
 15, 3;
 20, 4];

猜你喜欢

转载自www.cnblogs.com/hehe2014/p/10746710.html
今日推荐