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 <opencv2/imgcodecs.hpp>
  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.
     };

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

  • 2
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值