Jetson nano/NX安裝Opencv Cuda版

one_DS 2022-01-08 02:26:54 阅读数:309

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 <GL/gl.h>
//#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

有輸出就是成功了。

版权声明:本文为[one_DS]所创,转载请带上原文链接,感谢。 https://gsmany.com/2022/01/202201080226540080.html