1.1 Mat对象的概念
Mat是opencv中用来存储图像信息的内存对象,当通过Imgcodecs.imread()方法从文件读入图像文件是,IMread方法会返回Mat对象实例,或者通过Utils.bitmapToMat()方法有bitmap转换而来。
1.2 Mat读取图像基本信息
Mat对象除了存储图像的像素数据以外,还包括图像的其他属性,具体为宽、高、类型、维度、大小、深度等。具体获取API如下:
Mat src = Imgcodecs.imread(file.getPath());
int width = src.cols();//宽
int height = src.rows();//高
int dims = src.dims();//维度
int channels = src.channels();//通道数
int depth = src.depth();//深度
int type = src.type();//类型信息
Imgcodecs是OpenCV图像输入和输出模块 imread方法就输入图像的方法源码如下:
//javadoc: imread(filename)
public static Mat imread(String filename)
{
Mat retVal =new Mat(imread_1(filename));
return retVal;
}
imread_1(filename)则是一个native方法,暂时不做深究。
这里重点关注通道数、图像深度与图像类型、Op en C V 加载的Mat 类型图
像对象。
1.2.1 通道数
常见的通道数目有1 、3 ,