【已解决】error: ‘CV_GRAY2BGR’ was not declared in this scope

这是运行高翔 slambook2 代码出现的问题,有两种方法解决。

error: ‘CV_GRAY2BGR’ was not declared in this scope

/home/diyu/slambook2/ch8/optical_flow.cpp: In function ‘int main(int, char**)’:
/home/diyu/slambook2/ch8/optical_flow.cpp:145:37: error: ‘CV_GRAY2BGR’ was not declared in this scope
145 | cv::cvtColor(img2, img2_single, CV_GRAY2BGR);
| ^~~~~~~~~~~
/home/diyu/slambook2/ch8/direct_method.cpp: In function ‘void DirectPoseEstimationSingleLayer(const cv::Mat&, const cv::Mat&, const VecVector2d&, std::vector

这个实验由于代码使用的是opencv2,而cmkelists.txt文件中是opencv4

error: ‘CV_GRAY2BGR’ was not declared in this scope
这是opencv2的用法,现在opencv3和4是COLOR_GARY2BGR

因此有两种选择

  1. 要么将代码中opencv2的用法改成opencv3或者4的用法。即将代码中的CV_GRAY2BGR改成COLOR_GRAY2BGR,这里不确定是不是只需修改这个就可以。
  2. 要么将cmakelists文件中的opencv4改成opencv2。

这里选择第二种做法,修改成opencv2

【已解决】error: ‘CV_GRAY2BGR’ was not declared in this scope

Original: https://blog.csdn.net/qq_45945548/article/details/124754325
Author: 缔宇diyu
Title: 【已解决】error: ‘CV_GRAY2BGR’ was not declared in this scope

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/637983/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球