1. 通用问题
问题一
编译时报错 error: ‘CV_GRAY2RGB’ was not declared in this scope 等
解决方法
在报错文件上添加头文件 #include <opencv2/imgproc/imgproc_c.h>
单独遇到CV_AA的报错时,也可以将 CV_AA 改为 cv::LINE_AA
问题二
编译时报错 error: ‘CV_CALIB_CB_ADAPTIVE_THRESH’ was not declared in this scope 、error: ‘CV_CALIB_CB_NORMALIZE_IMAGE’ was not declared in this scope、error: ‘CV_CALIB_CB_FILTER_QUADS’ was not declared in this scope 和 error: ‘CV_CALIB_CB_FAST_CHECK’ was not declared in this scope
解决方法
将CV_CALIB_CB_ADAPTIVE_THRESH、CV_CALIB_CB_NORMALIZE_IMAGE、CV_CALIB_CB_FILTER_QUADS和CV_CALIB_CB_FAST_CHECK修改为 cv::CALIB_CB_ADAPTIVE_THRESH 、 cv::CALIB_CB_NORMALIZE_IMAGE 、cv::CALIB_CB_FILTER_QUADS 和cv::CALIB_CB_FAST_CHECK
问题三
编译时报错 error: ‘CV_RGB2GRAY’ was not declared in this scope
解决方法
在报错文件上添加头文件 #include<opencv2/imgproc/types_c.h>
问题四
编译时遇到报错 error: ‘CV_FONT_HERSHEY_SIMPLEX’ was not declared in this scope
解决方法
将报错文件上的 CV_FONT_HERSHEY_SIMPLEX 参数改为 cv::FONT_HERSHEY_SIMPLEX
问题五
‘CV_CALIB_CB_ADAPTIVE_THRESH’ was not declared in this scope
解决方法
试一下重新下一个cv_bridge,下载编译安装,在VINS_Mono代码的CMakeLists.txt中改变cv_bridge的路径即可,即加一句
set(cv_bridge_DIR “/home/xxx/codes/catkin_ws/devel/share/cv_bridge/cmake”)#写入自己的路径
上面摘自https://zhuanlan.zhihu.com/p/432167383
2. 多版本opencv导致的问题
我的电脑安装了opencv4.2 opencv3.2和opencv3.5, 如果只用find_package(OpenCV REQUIRED), 我这边找到的是OpenCV3, 而且vins找到的OpenCV4, 导致出现如下问题
运行的时候会出现core问题, gdb可以发现:
可以发现camera模块和vins模块实际上用的opencv版本不一样, vins模块链接的是opencv4, 但是camera链接的是opencv3. 改camera模块的CMakeLists中opencv的版本让两个模块的opencv版本一致, 则可以解决这个问题.