《opencv学习笔记》-- CV::Mat类

目录

Mat初始化函数

访问像素

方法一:使用at函数

方法二:使用迭代器


Mat初始化函数

//默认构造函数
cv::Mat  
//拷贝构造
cv::Mat(const Mat& mat)
// 指定行和列的拷贝构造
cv::Mat(const Mat& mat, const cv::Range& rows, const cv::Range& cols);
// 指定ROI(感兴趣的区域)的拷贝构造
cv::Mat(const Mat& mat, const cv::Rect& roi);
// 使用n维数组中指定范围内的数据的拷贝构造
cv::Mat(const Mat& mat, const cv::Range* ranges);
// 指定类型的二维数组
cv::Mat(int rows, int cols, int type);
// 指定类型的二维数据,并指定初始化值
cv::Mat(int rows, int cols, int type, const Scalar& s);
// 使用预先存在的数据,并指定类型的二维数组
cv::Mat(int rows, int cols, int type, void *data, size_t step = AUTO_STEP);
// 指定大小和类型的二维数组
cv::Mat(cv::Size sz, int type)
// 指定大小和类型的二维数组,并指定初始值
cv::Mat(cv::Size sz, int type, const Scalar& s);
// 使用预先存在的数据,指定类型的二维数组
cv::Mat(cv::Size sz, int type, void *data, size_t step = AUTO_STEP);
// 指定类型的多维数据
cv::Mat(int ndims, const int *sizes, int type);
// 指定类型的多维数据,并初始值
cv::Mat(int ndims, const int *sizes, int type, const Scalar& s);
// 使用预先存在的数据,指定类型的多维数组
cv::Mat(int ndims, const int* sizes, int type, void* data, size_t step = AUTO_STEP);

//mat的模板构造函数
// 构造如同cv::Vec所指定的数据类型、大小为n的一维数组
cv::Mat(const cv::Vec<T, n>& vec, bool copyData = true);
// 构造如同cv::Matx所指定的数据类型、大小为mXn的二维数组
cv::Mat(const cv::Matx<T, m, n>& vec, bool copyData = true);
// 构造STL的vector所指定的数据类型的一维数组
cv::Mat mat(const std::vector<T>& vec, bool copyData = true);

//构造mat的静态方法
// 使用zeros()函数定义指定大小(rows X cols)和类型(type)的cv::Mat(全为0)的矩阵
cv::Mat::zeros(int rows, int cols, int type);
// 使用ones()函数定义指定大小(rows X cols)和类型(type)的cv::Mat(全为1)的矩阵
cv::Mat::ones(int rows, int cols, int type);
// 使用eye()函数定义指定大小(rows X cols)和类型(type)的单位矩阵
cv::Mat::eye(int rows, int cols, int type);

访问像素

方法一:使用at函数

//直接访问  at函数
cv::Mat mat = cv::Mat::eye(10, 10, 32FC1);
m.at<float>(3, 3)

//多通道数组操作
cv::Mat mat = cv::Mat::eye(10, 10, 32FC2);
m.at<cv::Vec2f>(3, 3)[0];
m.at<cv::Vec2f>(3, 3)[1];

方法二:使用迭代器

int sz[3] = {4, 4, 4};
Mat m(3, sz, CV_32FC3);
cv::MatIterator<cv::Vec3b>  it = m.begin();

while(it != m.end()) {
    cout << (*)it[0];
    it++;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值