1、生成常用矩阵
Mat类中的函数eye(),one()在mat.hpp文件中有申明:
/*@param rows Number of rows.
@param cols Number of columns.
@param type Created matrix type.*/
static MatExpr eye(int rows, int cols, int type);
static MatExpr ones(int rows, int cols, int type);
/*@param size Alternative matrix size specification as Size(cols, rows) .
@param type Created matrix type.*/
static MatExpr eye(Size size, int type);
static MatExpr ones(Size size, int type);
/*@param ndims Array dimensionality.
@param sz Array of integers specifying the array shape.
@param type Created matrix type.*/
static MatExpr ones(int ndims, const int* sz, int type);
生成矩阵:
#include<iostream>
#include <opencv2\opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat m1 = Mat::eye(4, 4, CV_32F);
Mat m2 = Mat::eye(Size(5, 5), CV_32S);
Mat m3 = Mat::ones(3, 4, CV_32F);
Mat m4 = (Mat_ < float >(3, 3) << 1, 2, 3, 4, 5, 6, 7, 8, 9);
cout << "m1="<<m1 << "\n"<< "m2=" << m2 << "\n"<< "m3=" << m3 << "\n"<<"m4="<<m4 <<endl;
getchar();
}
/*输出为:
m1=[1, 0, 0, 0; m2=[1,0,0,0,0; m3=[1,1,1,1,1; m4=[1,2,3;