参考文章:https://www.cnblogs.com/xsy123/p/14488021.html
错误描述
出现错误如下:
CMake Error at /opt/ros/melodic/share/cv_bridge/cmake/cv_bridgeConfig.cmake:113 (message):
Project 'cv_bridge' specifies '/usr/include/opencv4/opencv' as an include
dir, which is not found. It does neither exist as an absolute directory
nor in '${prefix}//usr/include/opencv4/opencv'. Check the issue tracker
'https://github.com/ros-perception/vision_opencv/issues' and consider
creating a ticket if the problem has not been reported yet.
Call Stack (most recent call first):
CMakeLists.txt:54 (find_package)
-- Configuring incomplete, errors occurred!
或者出现如下错误:
undefined reference to `cv::FileStorage::FileStorage(std::__cxx11::basic_string<char, std::char_traits<char>,
分析原因
出现错误可能在于多版本OpenCV并存产生的冲突。
我的环境是TX2,自带OpenCV4,又在自己的目录下安装了OpenCV3。编译ORBSLAM3的时候,把CMakeList中的OpenCV定向到了自己的OpenCV3文件夹。而安装ROS的时候,cvbridge会默认链接/usr目录下的默认版本。
解决方法
首先检查 opencv cflags:
$ pkg-config --cflags opencv
-I/home/nvidia/opencv-3.4.14/include/opencv -I/home/nvidia/opencv-3.4.14/include
$ pkg-config --cflags opencv4
-I/usr/include/opencv4/opencv -I/usr/include/opencv4
然后修改cv_bridgeConfig.cmake中的内容
cd /opt/ros/melodic/share/cv_bridge/cmake/
sudo gedit cv_bridgeConfig.cmake
找到cv_bridgeConfig.cmake (94行),原内容如下(方便备份):
if(NOT "include;/usr/include;/usr/include/opencv " STREQUAL " ")
set(cv_bridge_INCLUDE_DIRS "")
set(_include_dirs "include;/usr/include;/usr/include/opencv")
如果要用 opencv3 改成:
if(NOT "include;/usr/include;/usr/include/opencv " STREQUAL " ")
set(cv_bridge_INCLUDE_DIRS "")
set(_include_dirs "include;/home/nvidia/opencv-3.4.14/include/opencv;/home/nvidia/opencv-3.4.14/include")
如果要用 opencv4 改成:
if(NOT "include;/usr/include;/usr/include/opencv4 " STREQUAL " ")
set(cv_bridge_INCLUDE_DIRS "")
set(_include_dirs "include;/usr/include/opencv4/opencv;/usr/include/opencv4")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)