OpenCV初始化矩阵

1 代码

#include "stdafx.h"

#include

#include

using namespace cv;

using namespace std;

int main()

{

Mat mat0 = (Mat_(3, 3) << 10, 9, 8, 7, 6, 5, 4, 3, 2);

cout << "mat0=" << endl << mat0 << endl << endl;

Mat mat1(3,3,CV_8UC3,Scalar(100,150,255));//赋值每个像素都为RGB(100,150,255)

cout << "mat1=" << endl << mat1 << endl << endl;

Mat mat2 = Mat::eye(3,3,CV_8UC3);//对角矩阵

cout << "mat2=" << endl << mat2 << endl << endl;

Mat mat3 = Mat::ones(3,3,CV_8UC1);//全1矩阵

cout << "mat3=" << endl << mat3 << endl << endl;

Mat mat4 = Mat::zeros(3,3,CV_32F);//全0矩阵

cout << "mat4=" << endl << mat4 << endl << endl;

Point2f p2(6.5,2.1);//2维点

cout << "p2=" << endl << p2 << endl << endl;

Point3i p3(6,2,3);//3维点

cout << "p3=" << endl << p3 << endl << endl;

waitKey();

return 0;

}


2 运行结果

OpenCV初始化矩阵_第1张图片

你可能感兴趣的:(OpenCV初始化矩阵)