一、编译darknet_ros时报错:OpenCV 4.x+ requires enabled C++11 support
安装的ubuntu版本是20.04,对应安的noetic包里自带的是Opencv4.2,因此需要更改ros编译时使用的opencv版本。
1、安装opencv3.4.5
下载opencv3.4.5 和opencv-contrib-3.4.5
下载opencv各版本连接:opencv 标签 - Gitee.com
下载opencv-conterib各版本连接:opencv_contrib 标签 - Gitee.com
2、安装依赖
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
如果报错 add-apt-repository: command not found
输入以下命令
sudo apt-get install software-properties-common
sudo apt-get update
重新执行sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
,又报错 E: Failed to fetch
先查看自己板卡是什么系统,如下
cat /etc/debian_version
我的输出 bullyseye/sid
bullseye/sid 2019年07月06日,Debian代号为“buster”发布Stable稳定版本,同日Debian代号为“bullseye”进入testing版本通道,2019年10月24日,Ubuntu20.04LTS建立代号“FocalFossa”,所以Ubuntu20.04LTS基于Debian代号为“bullseye”的Testing通道,而不是基于Unstable通道。
这里给出了国内一些 bullseye/sid 依赖下载源
输入
sudo gedit /etc/apt/sources.list
刚才如果是bullyseye/sid用下面替换全部内容,不是的话需要另外找源
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-proposed main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe
deb http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-proposed main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe
deb-src http://mirrors.ustc.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe
然后输入命令安装依赖
sudo apt update
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg.dev libtiff5.dev libswscale-dev libjasper-dev
sudo apt install libcanberra-gtk-module libcanberra-gtk3-module
3、解压
解压opencv3.4.5和opencv_contrib3.4.5文件,将后者移动到opencv3.4.5文件夹中;
将opencv3.4.5更名为opencv,opencv_contrib3.4.5文件更名为opencv_contrib;
在opencv文件中新建文件夹build
cd ~/opencv/build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=~/opencv/opencv_contrib/modules/ ..
/usr/local 是指默认将要 install 的路径
OPENCV_EXTRA_MODULES_PATH=~/opencv/opencv_contrib/modules/ … 是指 opencv_contrib3.4.5 中 modules所在的路径,后面的两点不可省略
4、编译安装
sudo make -j4
sudo make install
可能问题:fatal error: boostdesc_bgm.i: No such file or directory compilation terminated
还会出现fatal error: boostdesc_bgm.i: No such file or directory compilation terminated.的问题
解决办法:
直接用别人分享的,链接: https://pan.baidu.com/s/1LwuXsAAHIizlHVx7Obd9fw 提取码: 3sw1 ,
把下载好的这几个文件复制到opencv_contrib/modules/xfeatures2d/src/路径重新编译、安装就大功告成了!
重新编译
make -j4
sudo make install
就可以拉
5、查看opencv版本
pkg-config opencv --modversion
6、设置opencv的环境变量
6.1 添加库路径(创建opencv.conf文件)
输入命令:
sudo gedit /etc/ld.so.conf.d/opencv.conf
在里面添加
/usr/local/lib
保存并推出。
6.2 添加环境变量
输入命令
sudo gedit /etc/profile
在末尾添加
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
更新环境变量
source /etc/profile
6.3 设置另外环境变量
输入命令
sudo gedit /etc/bash.bashrc
在末尾加入
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
更新环境变量
source /etc/profile
6.4 更新系统库缓存
输入命令:
ldconfig
7.进入/opt/ros/noetic/share/cv_bridge/cmake/
打开cv_bridgeConfig.cmake文件,做以下更改:(注释掉的是源代码,后边是更改后的)
#if(NOT "include;/usr/include/opencv4 " STREQUAL " ")
if(NOT "include;/usr/local/include/opencv; /usr/local/include/opencv2 " STREQUAL " ")
set(cv_bridge_INCLUDE_DIRS "")
#set(_include_dirs "include;/usr/include/opencv4")
set(_include_dirs "include;/usr/local/lib;/usr/local/include/opencv;/usr/local/include/opencv2;/usr/local/include;/usr/include")
将/opt/ros/noetic/share/cv_bridge/cmake/ 下的 cv_bridge-extras.cmake替换为/usr/local/share/cv_bridge/cmake/ 下的cv_bridge-extras.cmake
8、回到工作空间重新编译darkin_ros功能包
还有报错:OpenCV 4.x+ requires enabled C++11 support
找到工作空间 catkin_ws/devel/share/cv_bridge/cmake
打开cv_bridgeConfig.cmake文件,做类似第7步更改
将cv_bridge-extras.cmake替换为/usr/local/share/cv_bridge/cmake/ 下的cv_bridge-extras.cmake
9、回到工作空间重新编译darkin_ros功能包就可以成功了
参考
05-旭日X3派测评——Open Cv &Pangolin等库安装&ORB_SLAM2 安装运行_旭日派x3 opencv 加速-CSDN博客