Jetson Xavier NX配置全过程——系统与SDK烧录(一)
Jetson Xavier NX配置全过程——安装jtop和OpenCV4.5.3(二)
Jetson Xavier NX配置全过程——D435i驱动安装(三)

目录

一、前言

二、安装jtop

三、卸载OpenCV

四、安装OpenCV4.5.3

1、安装依赖库

2、更换国内源

3、下载 OpenCV 和 opencv_contrib 源码

4、检验安装结果

一、前言

通过Jetson SDK Components安装的OpenCV 4.1.1版本是不带 CUDA 加速的,无法充分利用 NX 的 GPU 性能,所以先卸载OpenCV 4.1.1后再安装OpenCV 4.5.3。

二、安装jtop

jtop工具在查看jetson边缘计算产品的cpu,gpu,以及内存使用率时非常方便,而且还能查看cuda,cudnn,opencv等相关工具的详细版本号,基本是使用jetson边缘计算产品必装的工具。

我们使用python3的安装方式

sudo apt install python3-pipsudo -H pip3 install jetson-statssudo systemctl restart jetson_stats.service

安装后重启,即可以使用

三、卸载OpenCV

sudo apt purge libopencv*
sudo apt autoremove
sudo apt update

四、安装OpenCV4.5.3

1、安装依赖库

在终端输入以下命令:

sudo apt install -y build-essential checkinstall cmake pkg-config yasm git gfortran
sudo apt install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
sudo apt install -y libjpeg8-dev libjasper-dev libpng12-dev libtiff5-dev libavcodec-dev libavformat-dev libswscale-dev libxine2-dev libv4l-dev
sudo apt install -y libgtk2.0-dev libtbb-dev libatlas-base-dev libfaac-dev libmp3lame-dev libtheora-dev libvorbis-dev libxvidcore-dev libopencore-amrnb-dev libopencore-amrwb-dev x264 v4l-utils
sudo apt install -y python-dev python-numpy libtbb2 libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev
sudo apt update

不出意外应该会报错:E: 无法定位软件包 librealsense2-dkms,这时候我们换源即可解决问题。

2、更换国内源

将以前的源备份一下,以防以后可以用的。

sudo cp /etc/apt/sources.list /etc/apt/sources_init.list

使用gedit打开文档。

sudo gedit /etc/apt/sources.list

将下边的清华源复制进去,然后点击保存关闭。

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

更新软件列表。

sudo apt update

3、下载 OpenCV 和 opencv_contrib 源码

1、源码下载

分别前往OpenCV和opencv_contrib的 github 仓库下载源码 (点击超链接跳转)

注意 OpenCV 和 opencv_contrib 的版本要对应正确

2、编译和安装

将 opencv-4.5.3.zip 和 opencv_contrib-4.5.3.zip 放在同一文件夹(很重要)

cd opencv-4.5.3
mkdir build
cd build

执行cmake

cmake \-DCMAKE_BUILD_TYPE=Release \-DCMAKE_INSTALL_PREFIX=/usr/local \-DOPENCV_ENABLE_NONFREE=1 \-DBUILD_opencv_python2=1 \-DBUILD_opencv_python3=1 \-DWITH_FFMPEG=1 \-DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda \-DCUDA_ARCH_BIN=7.2 \-DCUDA_ARCH_PTX=7.2 \-DWITH_CUDA=1 \-DENABLE_FAST_MATH=1 \-DCUDA_FAST_MATH=1 \-DWITH_CUBLAS=1 \-DOPENCV_GENERATE_PKGCONFIG=1 \-DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-4.5.3/modules \..

进行 make,然后等待2~3个小时

make -j4 # 四线程编译

make编译完成后,进行安装

sudo make install

4、检验安装结果

在终端中输入

pythonimport cv2cv2.__version__

打印出本次安装版本号即安装正确。