SLAM十四讲 第七讲orb_cv代码 使用OpenCV 4.0 报错 identifier "CV_LOAD_IMAGE_COLOR" is undefined

SLAM十四讲 第七讲orb_cv代码 使用OpenCV 4.0 报错 identifier “CV_LOAD_IMAGE_COLOR” is undefined

Imread()函数在OpenCV中存在如下定义

CV_EXPORTS_W Mat imread( const String& filename, int flags = IMREAD_COLOR );

参数中第一项为文件地址及文件名构成的字符串,第二项用于确定文件读入方式,默认设置为 "IMREAD_COLOR"官方解释为:
convert image to the 3 channel BGR color image. 将图像转换为3通道 RGB 图像

而"CV_LOAD_IMAGE_COLOR" 为旧版本中的宏定义名
因此,可以对代码进行如下修改

  1. 添加头文件
#include 
  1. 将高博代码中的
Mat img_1 = imread(argv[1], CV_LOAD_IMAGE_COLOR);
Mat img_2 = imread(argv[2], CV_LOAD_IMAGE_COLOR);

修改为

Mat img_1 = imread(argv[1], IMREAD_COLOR);
Mat img_2 = imread(argv[2], IMREAD_COLOR);

Mat img_1 = imread(argv[1], 1);
Mat img_2 = imread(argv[2], 1);

第二种方式之所以可行,是因为OpenCV 4.0 源码中定义如下

//! Imread flags
enum ImreadModes {
       IMREAD_UNCHANGED            = -1, //!< If set, return the loaded image as is (with alpha channel, otherwise it gets cropped).
       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.
     };

如果需要设置其他文件读入方式,也可以从此代码片寻找官方有无规定

你可能感兴趣的:(SLAM十四讲 第七讲orb_cv代码 使用OpenCV 4.0 报错 identifier "CV_LOAD_IMAGE_COLOR" is undefined)