一、打开图片流程分析
1、读取图片头,进行解码器的寻找
2、根据参数flags,确定图像通道和是否缩放
3、给解码器指定缩放参数和源
4、使用解码器读取图像的头,确保没有问题,失败则输出错误并返回
5、确定图像的宽高,并判断是否超出处理范围。
6、通过解码器获取图像类型
7、根据宽、高、图像类型创建mat
8、通过解码器把图像数据读取到mat中
9、判断是否需要调整大小
二、imread源码查看
源码位置:opencv\modules\imgcodecs\src\loadsave.cpp
入口方法:
/**
* Read an image
*
* This function merely calls the actual implementation above and returns itself.
*
* @param[in] filename File to load
* @param[in] flags Flags you wish to set.
*/
Mat imread( const String& filename, int flags )
{
//用于应用程序性能分析 参见https://github.com/opencv/opencv/wiki/Profiling-OpenCV-Applications
CV_TRACE_FUNCTION();
/// create the basic container
Mat img;