OpenCV Mat -The Basic Image Container

 1 #include "opencv2/core/core.hpp"
 2 #include <iostream>
 3 
 4 using namespace cv;
 5 using namespace std;
 6 
 7 int main(int argc, char** argv) {
 8     Mat M(2, 2, CV_8UC3, Scalar(0, 0, 255));
 9     cout << "M = " << endl << " " << M << endl << endl;
10     M.create(4, 4, CV_8UC(1));
11     cout << "M = " << endl << " " << M << endl << endl;
12 
13     int sz[3] = { 2, 2, 2 };
14     Mat L(3, sz, CV_8UC(1), Scalar::all(0));
15     //cout << "L = " << endl << " " << L << endl << endl;
16 
17     Mat E = Mat::eye(4, 4, CV_64F);
18     cout << "E = "  << endl << " " << E << endl << endl;
19 
20     Mat O = Mat::ones(2, 2, CV_32F);
21     cout << "O = " << endl << " " << O << endl << endl;
22 
23     Mat Z = Mat::zeros(3, 3, CV_8UC1);
24     cout << "Z = " << endl << " " << Z << endl << endl;
25 
26     Mat C = (Mat_<double>(3, 3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);
27     cout << "C = " << endl << " " << C << endl << endl;
28 
29     Mat RowClone = C.row(1).clone();
30 
31     Mat R = Mat(3, 2, CV_8UC3);
32     randu(R, Scalar::all(0), Scalar::all(255));
33 
34     cout << "R = " << endl << " " << R << endl << endl;
35 
36     Point2f P(5, 1);
37     cout << "Point (2D) = " << P << endl << endl;
38     Point3f P3f(2, 6, 7);
39     cout << "Point (3D) = " << P3f << endl << endl;
40     vector<Point2f> vPoints(20);
41     for (size_t E = 0; E < vPoints.size(); ++E) {
42         vPoints[E] = Point2f((float)(E * 5), (float)(E % 7));
43     }
44     cout << "A vector of 2D Points = " << vPoints << endl << endl;
45     return 0;
46 }

M =
[ 0, 0, 255, 0, 0, 255;
0, 0, 255, 0, 0, 255]

M =
[205, 205, 205, 205;
205, 205, 205, 205;
205, 205, 205, 205;
205, 205, 205, 205]

E =
[1, 0, 0, 0;
0, 1, 0, 0;
0, 0, 1, 0;
0, 0, 0, 1]

O =
[1, 1;
1, 1]

Z =
[ 0, 0, 0;
0, 0, 0;
0, 0, 0]

C =
[0, -1, 0;
-1, 5, -1;
0, -1, 0]

R =
[ 91, 2, 79, 179, 52, 205;
236, 8, 181, 239, 26, 248;
207, 218, 45, 183, 158, 101]

Point (2D) = [5, 1]

Point (3D) = [2, 6, 7]

A vector of 2D Points = [0, 0;
5, 1;
10, 2;
15, 3;
20, 4;
25, 5;
30, 6;
35, 0;
40, 1;
45, 2;
50, 3;
55, 4;
60, 5;
65, 6;
70, 0;
75, 1;
80, 2;
85, 3;
90, 4;
95, 5]

猜你喜欢

转载自www.cnblogs.com/chenguifeng/p/12576654.html
今日推荐