当前位置:   article > 正文

cv::Mat类型的定义初始化方法汇总_cv::mat 初始化

cv::mat 初始化

原文链接:https://blog.csdn.net/guduruyu/article/details/66973415
cv::Mat 是Opencv2和OpenCV3中基本的数据类型,在cv::Mat类中,关于cv::Mat的定义和初始化有多种不同的形式,下面对其进行总结。
一、无数据拷贝的cv::Mat的定义和初始化
1、默认形式
cv::Mat m;
2、指定类型和大小(行列)的二维数组
cv::Mat m(int cols,int rows,int type);
或者 cv::Mat m(Size(int cols,int rows),int type);
for example,
cv::Mat m(2,3,CV_64FC1);
cv::Mat m(Size(2,3),CV_64FC1);
注:Size(width, height), 宽
3、有初始化值的指定类型和大小(行列)的二维数组
cv::Mat m(int cols,int rows,int type,const Scalar& s);
4、使用预先存在数据定义的指定类型和大小(行列)的二维数组
cv::Mat m(int rows,int cols,int type,void
data,size_t step = AUTO_STEP)
5、指定大小(size)和类型的二维数组
cv::Mat m(cv::Size sz, int type,const Scalar& s);
6、使用预先存在的数据定义的制定大小(size)和类型的二维数组
cv::Mat m(cv::Size sz, int type,voiddata,size_t step=AUTO_STEP);
7、指定类型多维数组
cv::Mat m(int ndims, const int
sizes, int type);
8、有初始化值的指定类型多维数组
cv::Mat m(int ndims, const int* sizes, int type, const Scalar& s);
二、从其他cv::Mat进行数据拷贝的定义和初始化
1、拷贝构造形式
cv::Mat m(const cv::Mat& mat);
2、指定行列范围的拷贝构造
cv::Mat m(const cv::Mat& mat,const cv::Range& rows, const cv::Range& cols);
3、指定ROI的拷贝构造
cv::Mat m(const cv::Mat& mat, const cv::Rect& roi);
4、使用多维数组中指定范围内的数据的拷贝构造
cv::Mat(const cv::Mat& mat, const cv::Range* ranges);
三、使用Opencv中的模板进行定义和初始化
1、使用cv::Vec定义相同类型、大小为n的一维数组
cv::Mat m(const cv::Vec<T, n>& vec, bool=copyData=true);
2、使用cv::Matx定义相同类型、大小为m*n的二维数组
cv::Mat m(const cv::Matx<T,m,n>& vec, bool copyData=true);
3、使用STL vector定义相同的一维数组
cv::Mat (const std::vector& vec, bool copyData=true);
四、直接使用静态函数创建cv::Mat
1、使用zeros()函数定义指定大小和类型的cv::Mat(全为0)
cv::Mat m = cv::Mat::zeros(int rows,int cols,int type);
2、使用ones()函数定义指定大小和类型的cv::Mat(全为1)
cv::Mat m = cv::Mat::ones(int rows,int cols,int type);
3、使用eye()函数定义指定大小和类型的cv::Mat (恒等矩阵)
cv::Mat m = cv::Mat::eye(int rows,int cols,int type);

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/在线问答5/article/detail/886823
推荐阅读
相关标签
  

闽ICP备14008679号