c++ - 使用不带第二个参数的 imread 打开图像时,颜色模式是什么? BGR 还是 RGB?

标签 c++ opencv

问题是当我需要将它转换为 HSV 时,CV_BGR2HSV 和 CV_RGB2HSV 给我不同的结果: 所以我真的需要知道用 imread 打开时颜色的顺序是什么,或者如何强制 imread 按任何特定顺序打开图像。

enter image description here

最佳答案

imread 的 OpenCV 文档说明默认情况下,对于 3 channel 彩色图像,数据以 BGR 顺序存储,例如在您的 Mat 中,数据存储为一维无符号字符指针,这样索引处的任何给定颜色像素 px_idx是 3 个元素的顺序,[px_idx + 0] :蓝色 channel ,[px_idx + 1] : 绿色 channel , [px_idx + 2] : 红色 channel

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

通过传递给 imread 的标志参数,您可以(有限地)控制颜色类型,尽管您不能指定 channel 顺序(您应该假设所有彩色图像都是 BGR)

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. (same as CV_LOAD_IMAGE_COLOR)

=0 Return a grayscale image. (same as CV_LOAD_IMAGE_GRAYSCALE)

<0 Return the loaded image as is (with alpha channel). (same as CV_LOAD_IMAGE_ANYDEPTH)

关于c++ - 使用不带第二个参数的 imread 打开图像时,颜色模式是什么? BGR 还是 RGB?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16410127/

相关文章:

c++ - 类成员函数的堆栈,但该类尚不清楚

c++ - 如何最好地重载运算符 < > <= >= 但只写一两个比较函数?

c# - C#OpenCV:检测 parking 标志

python - 如何在图像的人脸/ body 区域中检测太阳镜

python - 构建 mask 应用程序时 OpenCV 索引错误

c++ - weak_ptr 是基类的,而 shared_ptr 是派生类的?

c++ - 是否允许递归 boost spirit 语法?

c++ - c++中的多态——通过指针访问函数

java - openCV 中 BROWN 颜色的 HSV 值范围是多少?

multithreading - 对于多线程视频教练程序来说,这是一个合适的结构吗?