Mat:
- the matrix header 包含矩陣尺寸;
- a pointer 包含矩陣中的數值。
建立Mat:
- 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;