opencv 读取图片(C/C++/python)
2016-07-18 14:07
477 查看
参考:
http://www.opencv.org.cn/opencvdoc/2.3.2/html/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imread#Mat imread(const string& filename, int flags)
############################################################
函数功能:读取一张图片
C++版本:
参数解析:
filename:图片名
flags:
1)当flags > 0时,表示得到一个3通道颜色图像
2)当flags = 0时,表示得到一个灰度图像
3)当flags < 0时,得到原图像
flags很重要。如果你想要得到源图像的话,必须设置flags<0,而默认情况下,flags>0,所以当你想加载一张灰度图,可能得到的是一张彩色图;或者当你想要加载一个RGBA模式的4通道图像,由于没有设置flags,那么得到的图像仅为3通道RGB图像。
#################################################################
例子:加载一张灰度图
由图可知,没有设置flags参数时,默认值>0,所以将灰度图转换为3通道彩色图
所以,正确的读取原图像的方式为:
C++:
http://www.opencv.org.cn/opencvdoc/2.3.2/html/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imread#Mat imread(const string& filename, int flags)
############################################################
函数功能:读取一张图片
C++版本:
Mat imread(const string& filename, int flags=1)Python 版本:
cv2.imread(filename[, flags]) -> retvalC语言版本:
IplImage* cvLoadImage(const char* filename, int flags=CV_LOAD_IMAGE_COLOR)
参数解析:
filename:图片名
flags:
1)当flags > 0时,表示得到一个3通道颜色图像
2)当flags = 0时,表示得到一个灰度图像
3)当flags < 0时,得到原图像
flags很重要。如果你想要得到源图像的话,必须设置flags<0,而默认情况下,flags>0,所以当你想加载一张灰度图,可能得到的是一张彩色图;或者当你想要加载一个RGBA模式的4通道图像,由于没有设置flags,那么得到的图像仅为3通道RGB图像。
#################################################################
例子:加载一张灰度图
由图可知,没有设置flags参数时,默认值>0,所以将灰度图转换为3通道彩色图
所以,正确的读取原图像的方式为:
C++:
imread(filename, -1)Python:
cv2.imread(filename, -1)C语言:
cvLoadImage(filename, -1)
相关文章推荐
- leetcode_c++:链表:Sort List(148)
- C++ 将进程运行在指定的CPU上
- leetcode_c++:链表:Insertion Sort List(147)
- c++面试题经典
- leetcode_c++:链表:Reorder List(143)
- C/C++的开发环境安装
- leetcode_c++:链表:Linked List Cycle II(142)
- leetcode_c++:链表:Linked List Cycle II(142)
- std::string用法总结
- leetcode_c++:链表:Linked List Cycle(141)
- C语言开发注意事项
- 素数环 搜索
- 23 DesignPatterns学习笔记:C++语言实现
- C++ —— 入门
- C++PP Chapter XVI String类和标准模板库
- effective c++读书笔记 条款3
- C++学习
- C++学习
- Base64Code.cpp
- 详细配置C++借助ADO连接Access数据库