一 有关 Mat 类型的属性变量
在 Opencv中,用 Mat 二维数组 存储二维图像。
1)获取Mat 类型的行数、列数
cv::Mat gray,;
int rows=gray.rows;
int cols=gray.cols;
2) Mat 类型的通道数、深度
cv:: Mat gray ;
int channel=gray.channels();
如果图像是三通道的,则 channel=3,如果是单通道,则 channel=1;
如果是三通道的话,顺序分别是BGR。
图像的深度,代表图像灰度值可达到的范围,目前常用的是 8、16、32、64;
int depth=gray.depth;
比如深度等于8,代表灰度值范围 0-255,也就是有2^8个灰度值。
3) Mat 类型的大小
cv::Mat gray;
cv::Size size=gray.size();
int cols=size.width;//图像的列数
int rows=size.height;//图像的行数
4)判断图像是否为空
cv::Mat gray;
gray.empty();
若 Mat 为空,则返回false,反之返回 true.
二 灰度转化
cv::cvtColor( InputArray src, OutputArray dst, int code, int dstCn = 0 );
其中
@param src input image: 8-bit unsigned, 16-bit unsigned ( CV_16UC… ), or single-precision
Opencv基础知识
最新推荐文章于 2024-04-22 11:35:36 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)