版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wuguanghao/article/details/77323619
Opencv使用过程中我们经常会需要将一个Mat数据转换到另外一个Mat数据,
Mat src;
src = imread("C:\\Users\\934554314\\Desktop\\1.jpg", 0);
Mat dst;
dst = Mat(src.rows, src.cols, src.type());//这是一个构造函数,内部数据为空
//st = Mat::zeros(src.rows, src.cols, src.type());//这是一个将像素都转换成0的静态操作
namedWindow("src", CV_NORMAL);
imshow("src", src);
namedWindow("dst", CV_NORMAL);
imshow("dst", dst);
blur(src, dst, Size(3, 3), Point(0, 0), 4);
Mat src;
src = imread("C:\\Users\\934554314\\Desktop\\1.jpg", 0);
Mat dst;
//dst = Mat(src.rows, src.cols, src.type());//这是一个构造函数,内部数据为空
**dst = Mat::zeros(src.rows, src.cols, src.type());//这是一个将像素都转换成0的静态操作**
namedWindow("src", CV_NORMAL);
imshow("src", src);
namedWindow("dst", CV_NORMAL);
imshow("dst", dst);
blur(src, dst, Size(3, 3), Point(0, 0), 4);
一般情况下我们使用第二种方式要好一些,第二种Mat内部是有数据的。
//! Matlab-style matrix initialization
static MatExpr zeros(int rows, int cols, int type);
static MatExpr zeros(Size size, int type);
static MatExpr zeros(int ndims, const int* sz, int type);
//返回一个数据内容全部都为1的类型
static MatExpr ones(int rows, int cols, int type);
static MatExpr ones(Size size, int type);
static MatExpr ones(int ndims, const int* sz, int type);
//返回一个单位矩阵
static MatExpr eye(int rows, int cols, int type);
static MatExpr eye(Size size, int type);
这个是Opencv的一些静态函数,所以要用Mat::来调用。