OpenCV3 之 显式创建Mat对象的几种方法
发布日期:2021-07-01 03:59:36
浏览次数:2
分类:技术文章
本文共 1615 字,大约阅读时间需要 5 分钟。
指定存储元素的数据类型以及每个矩阵点的通道数:
CV_[位数][是否带符号][类型前缀]C[通道数]
#include#include using namespace std;using namespace cv;int main() { // 指定存储元素的数据类型以及每个矩阵点的通道数: // CV_[位数][是否带符号][类型前缀]C[通道数] // 方法1:使用Mat()构造函数 Mat M(2, 2, CV_8UC3, Scalar(0, 0, 255)); cout << "M = " << endl << " " << M << endl << endl; cout << "---------------------------------------" << endl; // 方法2:利用create()函数 M.create(4, 4, CV_8UC(3)); cout << "M = " << endl << " " << M << endl << endl; cout << "---------------------------------------" << endl; // 方法3:采用Matlab式的初始化方式 Mat E = Mat::eye(4, 4, CV_64F); cout << "E = " << endl << " " << E << endl << endl; cout << "---------------------------------------" << endl; Mat O = Mat::ones(2, 2, CV_32F); cout << "O = " << endl << " " << O << endl << endl; cout << "---------------------------------------" << endl; Mat Z = Mat::zeros(3, 3, CV_8UC1); cout << "Z = " << endl << " " << Z << endl << endl; cout << "---------------------------------------" << endl; // 方法4:对小矩阵使用逗号分隔式初始化函数 // 分隔式顺序按列从左到右 Mat C = (Mat_ (3, 3) << 0, -1, 0, -1, 5, -1, 0, -1, 0); cout << "C = " << endl << " " << C << endl << endl; cout << "---------------------------------------" << endl; // 方法5:为已存在的对象创建新信息头 Mat RowClone = C.row(1).clone(); cout << "RowClone = " << endl << " " << RowClone << endl << endl; cout << "---------------------------------------" << endl; // 使用randu()方法填充矩阵 Mat r = Mat(10, 3, CV_8UC3); randu(r, Scalar::all(0), Scalar::all(255)); cout << r< << endl; cout << "------------------------------" << endl; system("pause");}
参考书籍《OpenCV3编程入门》
转载地址:https://miracle.blog.csdn.net/article/details/100557022 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
表示我来过!
[***.240.166.169]2024年04月22日 04时06分09秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
x265-1.7版本-common/quant.cpp注释
2019-05-02
x265-1.7版本-common/scalinglist.cpp注释
2019-05-02
x265-1.7版本-common/slice.cpp注释
2019-05-02
x265-1.7版本-common/slice.h注释
2019-05-02
x265-1.7版本-encoder/bitcost.h注释
2019-05-02
x265-1.7版本-encoder/dpb.cpp注释
2019-05-02
x265-1.7版本-encoder/dpb.h注释
2019-05-02
x265-1.7版本-encoder/encoder.cpp注释
2019-05-02
x265-1.7版本-encoder/encoder.h注释
2019-05-02
x265-1.7版本-encoder/frameencoder.cpp注释
2019-05-02
x265-1.7版本-encoder/frameencoder.h注释
2019-05-02
x265-1.7版本-encoder/motion.cpp注释
2019-05-02
高阶函数
2019-05-02
继承和多态
2019-05-02
获取对象信息
2019-05-02
实例属性和类属性
2019-05-02
使用__slots__
2019-05-02
使用@property
2019-05-02
多重继承
2019-05-02
定制类
2019-05-02