jetson nano装opencv4.1.1

一:下载opencv4.1.1及其相关的安装包,修改一下
可以去官网下载(opencv4和opencv-contrib的版本要对应):
opencv4.1.1: https://github.com/opencv/opencv/tags?after=4.3.0
opencv-contrib-4.1.1: https://github.com/opencv/opencv_contrib/tags?after=3.4.12

也可以去这里下载:https://download.csdn.net/download/weixin_45235219/87408870。

修改URL地址为本地文件
分别修改opencv_contrib-4.1.1/modules/xfeatures2d/cmake/download_vgg.cmake和opencv_contrib-4.1.1/modules/face/CMakeLists.txt中的URL地址

把"https://raw.githubusercontent.com/opencv/opencv_3rdparty/KaTeX parse error: Expected 'EOF', got '#' at position 67: …/installFile/" #̲"https://raw.gi…{OPENCV_3RDPARTY_COMMIT}/"
在这里插入图片描述

二:卸载系统中已有的opencv

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

三:查看opencv是否卸载完成

1.pkg-config opencv --libs(查看opencv安装库)
2.pkg-config opencv --modversion(查看opencv安装版本)

没有版本信息输出就可以了。

四:安装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

五:更新一下
1.sudo apt update
2.sudo apt upgrade

六:修改openGL

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

把62-68段代码改成以下代码:
#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

七:配置编译

把下载的文件解压到jetson nano,用终端打开opencv_4.1.1,然后
1.mkdir build
2.cd build
3.
sudo cmake
-DCMAKE_BUILD_TYPE=Release
-DBUILD_PNG=OFF
-DBUILD_TIFF=OFF
-DBUILD_TBB=ON
-DBUILD_JPEG=OFF
-DBUILD_JASPER=OFF
-DBUILD_ZLIB=OFF
-DBUILD_EXAMPLES=ON
-DBUILD_opencv_java=OFF
-DBUILD_opencv_python2=OFF
-DBUILD_opencv_python3=ON
-DENABLE_PRECOMPILED_HEADERS=OFF
-DWITH_OPENCL=OFF
-DWITH_OPENMP=OFF
-DWITH_LIBV4L=ON
-DWITH_FFMPEG=ON
-DWITH_GSTREAMER=OFF
-DWITH_GSTREAMER_0_10=OFF
-DWITH_CUDA=ON
-DWITH_GTK=ON
-DWITH_VTK=OFF
-DWITH_V4L=ON
-DWITH_TBB=ON
-DWITH_QT=ON
-DWITH_OPENGL=ON
-DWITH_1394=OFF
-DWITH_OPENEXR=OFF
-DCUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-10.2
-DCUDA_ARCH_BIN=5.3
-DCUDA_ARCH_PTX=“”
-DINSTALL_C_EXAMPLES=ON
-DOPENCV_ENABLE_NONFREE=ON
-DINSTALL_TESTS=OFF
-DWITH_GTK_2_X=ON
-DOPENCV_EXTRA_MODULES_PATH=…/…/opencv_contrib-4.1.1/modules

4.sudo make -j8(等到100就可以了)
jetson nano装opencv4.1.1_第1张图片

5.sudo make install
等待完成就可以了。

八:检测是否安装成功
opencv_version # 会输出opencv版本号

cd opencv-4.1.1/smaples/cpp/example_cmake
cmake .
make
./opencv_example # 测试代码,如果有摄像头会打开摄像头

九:如果测试不成功,尝试一下修改路径

sudo gedit /etc/ld.so.conf.d/opencv.conf # 将opencv库添加到路径,从而可以让系统找到
sudo ldconfig # 使上述配置命令生效
sudo gedit /etc/bash.bashrc # 配置bash 在末尾添加如下命令

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

source /etc/bash.bashrc # 使bash配置生效
sudo updatedb # 更新

看了几篇优秀文章,也装了有好几次,然后把自己成功安装的过程记录了下来。
Jetson Nano 从头配置OpenCV+CUDA+QT完整流程
jetson nano和jetson nx 重装opencv(opencv4.1.1+opencv-contrib安装)
Jetson nano/NX安装Opencv
Jetson nano编译安装OpenCV4.1.1和OpenCV_contirb-4.1.1
Using GTK 2.x and GTK 3 in the same process is not supported
gtk3+安装

你可能感兴趣的:(opencv,python,ubuntu)