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