OpenCV中imread函数

本文深入探讨了OpenCV中imread函数的使用及其参数flags的作用,详细解释了如何根据flags参数加载不同类型的图像,并特别强调了在读取RGB图像时通道的排列顺序以及图像通道处理的相关知识。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

OpenCV中imread函数如下所示:

C++: Mat imread(const string& filename, int flags=1 )


其中flags可以为:

flags –

Flags specifying the color type of a loaded image:

  • CV_LOAD_IMAGE_ANYDEPTH - If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.
  • CV_LOAD_IMAGE_COLOR - If set, always convert image to the color one
  • CV_LOAD_IMAGE_GRAYSCALE - If set, always convert image to the grayscale one
  • >0 Return a 3-channel color image.

    Note

     

    In the current implementation the alpha channel, if any, is stripped from the output image. Use negative value if you need the alpha channel.

  • =0 Return a grayscale image.
  • <0 Return the loaded image as is (with alpha channel).


注意的是如果是读入RGB的三色图像,其channel的排列如下:

Note

 

In the case of color images, the decoded images will have the channels stored in B G R order.


即: 

      flowu = nocGTFlow.at<Vec3s>(i,j)[0];  B通道
      flowv = nocGTFlow.at<Vec3s>(i,j)[1];  G通道
      valid = nocGTFlow.at<Vec3s>(i,j)[2];   R通道

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值