Mat:
- the matrix header 包含矩阵尺寸;
- a pointer 包含矩阵中的数值。
- Mat M(2,2,CV_8UC3,Scalar(0,0,125));
注:2,2表示矩阵尺寸;
CV_8UC3表示
CV_[The number of bits per itrm][signed or Unsigned][Type
prefix]C[the channel number];
Scalar(0,0,125)表示初始值。
- 使用create()函数
M.create(4,4,CV_8UC(2));
注:使用这种方法不能初始化矩阵。
创建特殊的Mat矩阵:
- 零矩阵--zeros()
Mat zero=Mat::zeros(3,3,CV_8UC1);
- 单位矩阵--eye()
Mat I=Mat::eye(4,4,CV_64F);
- 全1矩阵--ones()
Mat one=Mat::ones(2,2,CV_32F);
常见的其他输出项:
- 2D Point
Point2f P(5, 1);
cout << "Point (2D) = " << P << endl << endl;
- 3D Point
Point3f P3f(2, 6, 7);
cout << "Point (3D) = " << P3f << endl << endl;
- std::vector via cv::Mat
vector<float> v;
v.push_back( (float)CV_PI); v.push_back(2); v.push_back(3.01f);
cout << "Vector of floats via Mat = " << Mat(v) << endl << endl;
- std::vector of points
vector<Point2f> vPoints(20);
for (size_t i = 0; i < vPoints.size(); ++i)
vPoints[i] = Point2f((float)(i * 5), (float)(i % 7));
cout << "A vector of 2D Points = " << vPoints << endl << endl;