Opencv学习笔记1(Mat The basic image container)

Posted 军军的测试集

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Opencv学习笔记1(Mat The basic image container)相关的知识,希望对你有一定的参考价值。

过去几个月因为毕业的事情一团糟,同时由于担心延期而七上八下的,因此学习计划一再被打乱。现在的空余时间稍微多了那么一点,尽量保持更新吧!

此外,经我和师弟们讨论认为:未来比较适合机械学生的方向大概是会点机械设计,会点编程。而我大概也会沿着这些模糊的路摸索,尽量向这些方向前进!

最近大概会学习OpenCV:参考资料主要就是官网的资料,以及毛星云的《OpenCV3》。本来是打算在Ubuntu系统跑这些程序的,现在的笔记本在Ubuntu上存在一些系统,而我的新笔记本暂时还没有买,暂时也不讨论安装的事情,就闲用VS先凑合着吧!

Mat





Mat A, C;                          // creates just the header parts

A = imread(argv[1], IMREAD_COLOR); // here we'll know the method used (allocate matrix)

Mat B(A);                                 // Use the copy constructor

C = A;                                    // Assignment operato


当需要连带矩阵数据也复制的时候,则采用以下函数:

cv :: Mat :: clone()cv :: Mat :: copyTo()


Storing methods

Creating a Mat object explicitly 

1.  

    Mat M(2,2, CV_8UC3, Scalar(0,0,255));

2.  

     int sz[3] = {2,2,2};

     Mat L(3,sz, CV_8UC(1), Scalar::all(0));

3.

    M.create(4,4, CV_8UC(2));

    out << "M = "<< endl << " "  << M << endl << endl;

4.

    Mat E = Mat::eye(4, 4, CV_64F);

    cout << "E = " << endl << " " << E << endl << endl;

    Mat O = Mat::ones(2, 2, CV_32F);

    cout << "O = " << endl << " " << O << endl << endl;

    Mat Z = Mat::zeros(3,3, CV_8UC1);

   cout << "Z = " << endl << " " << Z << endl << endl;

5.

    Mat C = (Mat_<double>(3,3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);

    cout << "C = " << endl << " " << C << endl << endl;

    C = (Mat_<double>({0, -1, 0, -1, 5, -1, 0, -1, 0})).reshape(3);

    cout << "C = " << endl << " " << C << endl << endl;

6.

    Mat RowClone = C.row(1).clone();

    cout << "RowClone = " << endl << " " << RowClone << endl << endl;


Output formatting

Output of other common items


以上是关于Opencv学习笔记1(Mat The basic image container)的主要内容,如果未能解决你的问题,请参考以下文章

OPENCV学习笔记1_Mat 创建

[OpenCV学习笔记2][Mat数据类型和操作]

OPENCV学习笔记2_Mat 加载, 显示

OpenCV学习笔记:Mat矩阵的初始化

OPENCV学习笔记3_Mat 保存

数字图像处理OpenCV3 学习笔记