📜  OpenCV-IMREAD_XXX标志

📅  最后修改于: 2020-11-23 03:37:05             🧑  作者: Mango


OpenCV支持各种类型的图像,例如彩色,二进制,灰度等。使用imread()方法和Imgcodecs类的预定义字段,可以将给定图像读取为另一种类型。

imread()方法的标志参数(IMREAD_XXX)

在前面的章节中,我们已经了解了Imgcodecs类的imread()方法的语法。它接受一个表示要读取图像位置的字符串参数。

imread(filename)

imread()方法具有另一种语法。

imread(filename, int flags)

此语法接受两个参数-

  • filename-它接受参数(文件名) ,这是String类型的变量,表示要读取的文件的路径。

  • flags-代表预定义标志值的整数值。对于每个值,这会将给定图像读取为特定类型(灰度颜色等)。

下表列出了Imgproc类中作为此参数值提供的各个字段。

S.No Fields and Description
1

IMREAD_COLOR

If the flag is set to this value, the loaded image will be converted to a 3-channel BGR (Blue Green Red) color image.

2

IMREAD_GRAYSCALE

If the flag is set to this value, the loaded image will be converted to a single-channel grayscale image.

3

IMREAD_LOAD_GDAL

If the flag is set to this value, you can load the image using the gdal driver.

4

IMREAD_ANYCOLOR

If the flag is set to this value, the image is read in any possible color format.

5

IMREAD_REDUCED_COLOR_2

IMREAD_REDUCED_COLOR_4

IMREAD_REDUCED_COLOR_8

If the flag is set to this value, the image is read as three-channel BGR, and the size of the image is reduced to ½, ¼th or ⅛th of the original size of the image with respect to the field used.

6

IMREAD_REDUCED_GRAYSCALE_2

IMREAD_REDUCED_GRAYSCALE_4

IMREAD_REDUCED_GRAYSCALE_8

If the flag is set to this value, the image is read as a single-channel grayscale image, and the size of the image is reduced to ½, ¼th or ⅛th of the original size of the image with respect to the field used.

7

IMREAD_UNCHANGED

If the flag is set to this value, the loaded image is returned as it is.