Jetson nano/NX安装Opencv Cuda版

一、卸载系统自带的opencv

sudo apt-get purge libopencv* python-opencv 
sudo apt-get update
sudo apt-get install -y build-essential pkg-config

二、查看是否卸载干净

查看opencv安装库:pkg-config opencv --libs
查看opencv安装版本:pkg-config opencv --modversion

没有什么输出就是正常的。

三、下载opencv和opencv_contrib库(v3.4.1)

contrib库:https://github.com/opencv/opencv_contrib/releases
opencv版本:https://opencv.org/releases.html

把两个包解压并把opencv_contrib-3.4.1这整个文件夹拷贝到opencv-3.4.1文件夹里面

unzip opencv-3.4.1.zip 
unzip opencv_contrib-3.4.1.zip
cp -r opencv_contrib-3.4.1 opencv-3.4.1

再把opencv-3.4.1移动至主目录

四、安装opencv所需要的依赖项

sudo apt-get install -y cmake libavcodec-dev libavformat-dev libavutil-dev \
    libglew-dev libgtk2.0-dev libgtk-3-dev libjpeg-dev libpng-dev libpostproc-dev \
    libswscale-dev libtbb-dev libtiff5-dev libv4l-dev libxvidcore-dev \
    libx264-dev qt5-default zlib1g-dev libgl1 libglvnd-dev pkg-config \
    libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev mesa-utils     
sudo apt-get install python2.7-dev python3-dev python-numpy python3-numpy

五、修改OpenGL

cd /usr/lib/aarch64-linux-gnu/
sudo ln -sf libGL.so.1.0.0 libGL.so
sudo gedit /usr/local/cuda/include/cuda_gl_interop.h

修改(line #62~68) of cuda_gl_interop.h

//#if defined(arm) || defined(aarch64)
//#ifndef GL_VERSION
//#error Please include the appropriate gl headers before including cuda_gl_interop.h
//#endif
//#else
#include
//#endif

六、编译

cd ~/opencv-3.4.1
mkdir build
cd build

以下是编译命令:

cmake -D CMAKE_BUILD_TYPE=RELEASE \
        -D CMAKE_INSTALL_PREFIX=/usr/local \
        -D WITH_CUDA=ON \
        -D CUDA_ARCH_BIN=6.2 \
        -D CUDA_ARCH_PTX="" \
        -D ENABLE_FAST_MATH=ON \
        -D CUDA_FAST_MATH=ON \
        -D WITH_CUBLAS=ON \
        -D WITH_LIBV4L=ON \
        -D WITH_GSTREAMER=ON \
        -D WITH_GSTREAMER_0_10=OFF \
        -D WITH_QT=ON \
        -D WITH_OPENGL=ON \
        -D CUDA_NVCC_FLAGS="--expt-relaxed-constexpr" \
        -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-10.2 \
        -D WITH_TBB=ON \
        -D OPENCV_EXTRA_MODULES_PATH=~/Dowmload/opencv-3.4.1/opencv_contrib-3.4.1/modules \
         ../
sudo make -j4
sudo make install

七、链接库共享

sudo ldconfig -v 

八、将OpenCV的库添加到路径

sudo gedit /etc/ld.so.conf.d/opencv.conf 

(打开是个空文件)

添加以下:

/usr/local/lib

九、使配置路径生效

sudo ldconfig 

十、配置环境变量

sudo gedit /etc/bash.bashrc

在最末尾添加:

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH

保存,执行如下命令使得配置生效

source /etc/bash.bashrc 

更新(可能出现找不到该命令,自行搜索解决)

sudo updatedb

十一、检查是否安装成功

查看opencv安装库:pkg-config opencv --libs
查看opencv安装版本:pkg-config opencv --modversion

有输出就是成功了。

你可能感兴趣的:(Jetson,opencv,python,计算机视觉)