jetson nano运行darknet_ros的环境配置

jetson nano运行darknet_ros的环境配置

  • 1 安装镜像JP4.5
  • 2 环境设置
    • 2.1 Jetson Nano换国内源
    • 2.2 CUDA路径配置
    • 2.3 拼音输入法
    • 2.4 NFS
  • 3 安装opencv3.4.10
    • 3.1 卸载opencv4.1.1(不卸载也可以)
    • 3.2 准备文件
    • 3.3 创建文件夹作为安装目录
    • 3.4 修改face下载路径
    • 3.5 修改install脚本
    • 3.6 运行
    • 3.7 配置
    • 3.8 检查opencvlib是否安装上
  • 4 安装ros-melodic
    • 4.1 安装命令
    • 4.2 初始化
    • 4.3 配置cv_bridge,使其链接opencv3.4.10版本而非ros自带的opencv4.1.1
    • 4.4 第一个ros例程
    • 4.5 第一个工作空间
  • 5 安装darknet_ros
    • 5.1 依赖包
    • 5.2 配置opencv cmake桥接目录
    • 5.3 编译darknet_ros
    • 5.4 测试darknet_ros

jetson nano安装镜像+ros-melodic+opencv3.4.10+darknet_ros

本文资源:

Melodic的ros.zip

jetson_nano-opencv.zip

基于jetson nano的darknet_ros包

1 安装镜像JP4.5

官方镜像地址:https://developer.nvidia.com/embedded/downloads
安装教程:https://blog.csdn.net/m0_51004308/article/details/114747285

JP4.5.1具备了

  • CUDA 10.2
  • CUDNN 8.0.0
  • TensorRT 7.1.3
  • OpenCV 4.1.1

2 环境设置

2.1 Jetson Nano换国内源

因为jetson nano芯片是arm架构,软件源还不一样

sudo mv /etc/apt/sources.list /etc/apt/sources.list.bak

deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-security main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-updates main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ bionic-backports main multiverse restricted universe

sudo apt-get update

2.2 CUDA路径配置

gedit ~/.bashrc
# 添加
export PATH=/usr/local/cuda/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
export CUDA_ROOT=/usr/local/cuda

source .bashrc

2.3 拼音输入法

参考:https://blog.csdn.net/u013617229/article/details/89645829
sudo apt-get install ibus-pinyin

2.4 NFS

sudo apt-get install nfs-kernel-server
sudo apt-get install nfs-common

sudo -s
echo "/home/castle *(rw,sync,no_root_squash)" >> /etc/exports


sudo /etc/init.d/nfs-kernel-server restart

3 安装opencv3.4.10

jetson nano 自带opencv4.x与很多程序不兼容,这里给出安装opencv3.4.x的安装流程
参考:https://blog.csdn.net/wup422457601/article/details/113087266

3.1 卸载opencv4.1.1(不卸载也可以)

/usr/bin/opencv_version 

sudo apt-get purge libopencv*
sudo apt autoremove
sudo apt-get update

3.2 准备文件

下载文件

  • download.zip
  • opencv-3.4.10.zip
  • opencv_contrib-3.4.10.zip
  • install_opencv3.4.10_Nano.sh

3.3 创建文件夹作为安装目录

sudu mkdir /opt/opencv 
cd /opt/opencv
  • 将解压后的download,opencv-3.4.10,opencv_contrib-3.4.10,install_opencv3.4.10_Nano.sh拷贝到/opt/opencv

  • 将download文件夹中的*.i文件全部放入opencv_contrib-3.4.10/modules/xfeatures2d/src目录

3.4 修改face下载路径

vim /opt/opencv/opencv_contrib-3.4.10/modules/face/CMakeLists.txt
#注释掉"https://raw.githubusercontent.com/opencv/opencv_3rdparty/${__commit_hash}/"
#换成"file:///opt/opencv/download/"

在/opt/opencv/opencv-3.4.10/modules/CMakeLists.txt第1行加入:
INCLUDE_DIRECTORIES("/opt/opencv/opencv_contrib-3.4.10/modules/xfeatures2d/include")

3.5 修改install脚本

cd /usr/local/cuda/samples/1_Utilities/deviceQuery
sudo make
./deviceQuery
# 运行后find输出信息:CUDA Capability Major/Minor version number:    5.3
# 修改/opt/opencv/install_opencv3.4.10_Nano.sh中掉编译选项:
sudo gedit /opt/opencv/install_opencv3.4.10_Nano.sh

-D CUDA_ARCH_BIN="5.3"

user="user-name"			# 根据实际修改
passwd="password"		# 根据实际修改
version="3.4.10"

3.6 运行

cd /opt/opencv/
sudo  /opt/opencv/install_opencv3.4.10_Nano.sh/opt/opencv// # 安装位置
# 大约需要编译2个小时

3.7 配置

sudo -s
cd /etc/ld.so.conf.d/
echo /usr/local/lib >> opencv.conf
ldconfig -v

3.8 检查opencvlib是否安装上

dpkg -l  | grep opencv
pkg-config --modversion opencv

4 安装ros-melodic

4.1 安装命令

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'

sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
 
sudo apt update

sudo apt install ros-melodic-desktop-full

4.2 初始化

将.ros目录从U盘中拷出,覆盖掉目录下的.ros,这样就可以跳过2个步骤sudo rosdep init&&rosdep update

echo "source /opt/ros/melodic/setup.bash" >> ~/.bashrc
source ~/.bashrc
sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential

4.3 配置cv_bridge,使其链接opencv3.4.10版本而非ros自带的opencv4.1.1

ros使用opencv时不可避免会需要安装melodic-cv-bridge,则会自动安装opencv4

查找:
sudo find / -iname "*opencv4*"
看看有没有找到opencv4的目录,若有:
修改cv_bridge的配置文件,使得cv_bridge去调用我们自己安装的OpenCV版本

sudo gedit /opt/ros/melodic/share/cv_bridge/cmake/cv_bridgeConfig.cmake 

然后按ctrl+f,输入关键词cv_bridge_INCLUDE_DIRS找到以下内容并按图中的方式进行修改。

if(NOT "include;/usr/include;/usr/include/opencv " STREQUAL " ")
  set(cv_bridge_INCLUDE_DIRS "")
  set(_include_dirs "include;/usr/include;/usr/include/opencv")

修改为:

if(NOT "include;/usr/include;/opt/opencv/opencv-3.4.10 " STREQUAL " ")
  set(cv_bridge_INCLUDE_DIRS "")
  set(_include_dirs "include;/usr/include;/opt/opencv/opencv-3.4.10")

4.4 第一个ros例程


sudo apt-get install ros-$(rosversion -d)-turtlesim
#打开一个终端,启动roscore:
roscore
#新建一个终端页,运行turtlesim_node:
rosrun turtlesim turtlesim_node
#新建一个终端页,运行turtle_teleop_key:
rosrun turtlesim turtle_teleop_key 

4.5 第一个工作空间

mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
catkin_init_workspace
cd ~/catkin_ws/
catkin_make
echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc
source ~/.bashrc

5 安装darknet_ros

5.1 依赖包

sudo apt-get install  ros-melodic-usb-cam
sudo apt-get install  ros-melodic-image-view

libopencv避免不了,ros总会自动装上4.1.1,因此需要在后面对cv_bridge进行修改

从已有的板子拷贝darknet功能包, 将darknet_ros放进src

5.2 配置opencv cmake桥接目录

查找:
sudo find / -iname "*opencv4*"
看看有没有找到opencv4的目录,若有:
修改cv_bridge的配置文件,使得cv_bridge去调用我们自己安装的OpenCV版本

sudo gedit /opt/ros/melodic/share/cv_bridge/cmake/cv_bridgeConfig.cmake 

然后按ctrl+f,输入关键词cv_bridge_INCLUDE_DIRS找到以下内容并按图中的方式进行修改。

if(NOT "include;/usr/include;/usr/include/opencv " STREQUAL " ")
  set(cv_bridge_INCLUDE_DIRS "")
  set(_include_dirs "include;/usr/include;/usr/include/opencv")

修改为:

if(NOT "include;/usr/include;/opt/opencv/opencv-3.4.10 " STREQUAL " ")
  set(cv_bridge_INCLUDE_DIRS "")
  set(_include_dirs "include;/usr/include;/opt/opencv/opencv-3.4.10")

5.3 编译darknet_ros

关于cv::Mat 和IplImage的转换问题:在编译时加入选项:-DCMAKE_CXX_FLAGS=-DCV__ENABLE_C_API_CTORS

编译

cd ~/catkin_ws
catkin_make -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS=-DCV__ENABLE_C_API_CTORS

5.4 测试darknet_ros

roslaunch darknet_ros darknet_ros.launch

你可能感兴趣的:(jetson,nano,ROS,linux操作系统,jetson,nano)