解决cv_bridge依赖opencv版本问题

1. 问题来源

在安装ros的过程中,系统会默认安装cv_bridge库,但该库指定了依赖的opencv库路径,拿ros melodic版本来说,默认依赖opencv库: /usr/lib/x86_64-linux-gnu/libopencv_core.so.3.2.0,但我们在进行开发过程中难免会更换opencv的版本,此时就会导致在编译的时候出现 Project ‘cv_bridge’ specifies ‘/usr/include/opencv’ as an include dir问题,原因是利用源码安装opencv时会默认安装在 /usr/local 目录下,此时就需要源码编译安装cv_bridge,使其依赖新的opencv库.

2. 解决方法

2.1 卸载原有库
sudo apt-get remove ros-melodic-cv-bridge
2.2 下载对应版本源码
git clone -b melodic https://github.com/ros-perception/vision_opencv.git
2.3 生成新的安装包\

2.3.1 安装打包工具

sudo apt-get install python-bloom fakeroot

2.3.2 拷贝下面脚本文件到 build.sh

#!/bin/bash

echo $1
cd $1 || die
bloom-generate rosdebian --os-version `echo $(lsb_release -sc)` --ros-distro `echo ${ROS_DISTRO}`
sed -i 's/dh_shlibdeps -l.*/& --dpkg-shlibdeps-params=--ignore-missing-info/g' debian/rules
fakeroot debian/rules binary
rm debian -rf || die
rm obj-x86_64-linux-gnu -rf || die

2.3.3 生成安装包

chmod 777 build.sh
build.sh vision_opencv/cv_bridge

2.3.4 安装安装包

sudo dpkg -i vision_opencv/ros-melodic-cv-bridge_1.13.0-0bionic_amd64.deb

2.3.5 查看依赖是否更新

cd /opt/ros/melodic/lib
ldd libcv_bridge.so | grep opencv

libopencv_imgcodecs.so.3.4 => /usr/local/lib/libopencv_imgcodecs.so.3.4 (0x00007fa46bdee000)
libopencv_imgproc.so.3.4 => /usr/local/lib/libopencv_imgproc.so.3.4 (0x00007fa469d19000)
libopencv_core.so.3.4 => /usr/local/lib/libopencv_core.so.3.4 (0x00007fa468b42000)=

可见cv_bridge已经被成功的安装到ros系统目录,并且依赖的opencv版本已更新,至此问题得到解决。

你可能感兴趣的:(人工智能,算法,计算机视觉)