当前位置:
首页 >
Opencv存图读图
发布时间:2023/12/20
49
豆豆
生活随笔
收集整理的这篇文章主要介绍了
Opencv存图读图
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
目录
一,存储图像
1,存储 imwrite
2,编码格式
3,图片位深
二,读取图像
1,读取 imread
2,读取类型 ImreadModes
一,存储图像
1,存储 imwrite
imwrite("D:/im2.jpg", image2);第三个参数缺省了。
2,编码格式
jpg是有损压缩,png是无损压缩,如果对图片要求很高的,还是用png好一点。
3,图片位深
32F类型的图片,像这样存下来之后会变成8U的,读取之后也是8U的,
即使再转换成32F的,也可能和原图有差异。
二,读取图像
1,读取 imread
string path = "D:/im2.jpg"; Mat image = imread(path, IMREAD_UNCHANGED); if (!image.data) {cout << "imread fail\n";return; }第二个参数是ImreadModes类型的枚举,表示读取的通道数
返回的是一个Mat类型的对象。
成员data是uchar的指针,如果读取失败那么指针为空
2,读取类型 ImreadModes
ImreadModes的源代码:
enum ImreadModes {IMREAD_UNCHANGED = -1, //!< If set, return the loaded image as is (with alpha channel, otherwise it gets cropped). Ignore EXIF orientation.IMREAD_GRAYSCALE = 0, //!< If set, always convert image to the single channel grayscale image (codec internal conversion).IMREAD_COLOR = 1, //!< If set, always convert image to the 3 channel BGR color image.IMREAD_ANYDEPTH = 2, //!< If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.IMREAD_ANYCOLOR = 4, //!< If set, the image is read in any possible color format.IMREAD_LOAD_GDAL = 8, //!< If set, use the gdal driver for loading the image.IMREAD_REDUCED_GRAYSCALE_2 = 16, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/2.IMREAD_REDUCED_COLOR_2 = 17, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/2.IMREAD_REDUCED_GRAYSCALE_4 = 32, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/4.IMREAD_REDUCED_COLOR_4 = 33, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/4.IMREAD_REDUCED_GRAYSCALE_8 = 64, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/8.IMREAD_REDUCED_COLOR_8 = 65, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/8.IMREAD_IGNORE_ORIENTATION = 128 //!< If set, do not rotate the image according to EXIF's orientation flag.};-1 IMREAD_UNCHANGED 表示按照图片本身的通道数
0 IMREAD_GRAYSCALE 表示灰度图像,即单通道
1 IMREAD_COLOR 表示按照3通道
总结
以上是生活随笔为你收集整理的Opencv存图读图的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 苏州新导_智慧养老解决方案_养老院解决方
- 下一篇: 重庆到西安谋划高铁 望融入西三角经济圈