Opencv存图读图
        【摘要】 
                    目录 
一,存储图像 
1,存储 imwrite 
2,编码格式 
3,图片位深 
二,读取图像 
1,读取 imread 
2,读取类型 ImreadModes 
一,存储图像 
1,存储 imwrite 
imwrite("D:/im2.jpg", image2); 
第三个参数缺省了。 
2,编码格式 
jpg是有损压缩,png...
    
    
    
    目录
一,存储图像
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通道
文章来源: blog.csdn.net,作者:csuzhucong,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/nameofcsdn/article/details/122966084
        【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
            cloudbbs@huaweicloud.com
        
        
        
        
        
        
        - 点赞
- 收藏
- 关注作者
 
             
           
评论(0)