【已解决】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, Sophus::SE3d&)’:
/home/diyu/slambook2/ch8/direct_method.cpp:206:35: error: ‘CV_GRAY2BGR’ was not declared in this scope
206 | cv::cvtColor(img2, img2_show, CV_GRAY2BGR);
| ^~~~~~~~~~~
make[2]: *** [CMakeFiles/optical_flow.dir/build.make:63:CMakeFiles/optical_flow.dir/optical_flow.cpp.o] 错误 1
make[1]: *** [CMakeFiles/Makefile2:105:CMakeFiles/optical_flow.dir/all] 错误 2
make[1]: *** 正在等待未完成的任务…
make[2]: *** [CMakeFiles/direct_method.dir/build.make:63:CMakeFiles/direct_method.dir/direct_method.cpp.o] 错误 1
make[1]: *** [CMakeFiles/Makefile2:78:CMakeFiles/direct_method.dir/all] 错误 2
make: *** [Makefile:84:all] 错误 2

这个实验由于代码使用的是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_第1张图片

你可能感兴趣的:(其它,c++,opencv)