jetson nano安装镜像+ros-melodic+opencv3.4.10+darknet_ros
本文资源:
Melodic的ros.zip
jetson_nano-opencv.zip
基于jetson nano的darknet_ros包
官方镜像地址:https://developer.nvidia.com/embedded/downloads
安装教程:https://blog.csdn.net/m0_51004308/article/details/114747285
JP4.5.1具备了
因为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
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
参考:https://blog.csdn.net/u013617229/article/details/89645829
sudo apt-get install ibus-pinyin
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
jetson nano 自带opencv4.x与很多程序不兼容,这里给出安装opencv3.4.x的安装流程
参考:https://blog.csdn.net/wup422457601/article/details/113087266
/usr/bin/opencv_version
sudo apt-get purge libopencv*
sudo apt autoremove
sudo apt-get update
下载文件
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目录
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")
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"
cd /opt/opencv/
sudo /opt/opencv/install_opencv3.4.10_Nano.sh/opt/opencv// # 安装位置
# 大约需要编译2个小时
sudo -s
cd /etc/ld.so.conf.d/
echo /usr/local/lib >> opencv.conf
ldconfig -v
dpkg -l | grep opencv
pkg-config --modversion opencv
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
将.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
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")
sudo apt-get install ros-$(rosversion -d)-turtlesim
#打开一个终端,启动roscore:
roscore
#新建一个终端页,运行turtlesim_node:
rosrun turtlesim turtlesim_node
#新建一个终端页,运行turtle_teleop_key:
rosrun turtlesim turtle_teleop_key
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
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
查找:
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")
关于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
roslaunch darknet_ros darknet_ros.launch