作者原创
jetson nano opencv3.4.x安装
概述
jetson nano 自带opencv4.x与很多程序不兼容,这里给出安装opencv3.4.x的安装流程,作者亲测3.4.2、3.4.9、3.4.10有效,方法都是一样的。
一、下载
-
opencv源码官方下载(github比较慢也可以直接在步骤2的百度云下载)
opencv下载地址:
https://github.com/opencv/opencv/tree/3.4.10
opencv contrib下载地址:
https://github.com/opencv/opencv_contrib/tree/3.4.10 -
下载编译时需要用到的文件,github比较慢我已经下载到了百度云
链接:https://pan.baidu.com/s/1l-wqB_l_ZilDMNfDKFQTjA 提取码:29ri -
总共需要下载3组文件
1>. opencv和contrib文件
2>. 编译时需要用到的文件 download.zip
3>. 自动编译脚本
二、依赖
(注:不需要手动下载,编译脚本会自动安装依赖)
sudo apt-get update
sudo apt-get install -y build-essential make cmake cmake-curses-gui git g++ pkg-config curl
sudo apt-get install -y libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libeigen3-dev libglew-dev libgtk2.0-dev
sudo apt-get install -y libtbb2 libtbb-dev libv4l-dev v4l-utils qv4l2 v4l2ucp
sudo apt-get install -y libdc1394-22-dev libxine2-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
# sudo apt-get install -y libjasper-dev
sudo apt-get install -y libjpeg8-dev libjpeg-turbo8-dev libtiff-dev libpng-dev
sudo apt-get install -y libxvidcore-dev libx264-dev libgtk-3-dev
sudo apt-get install -y libatlas-base-dev libopenblas-dev liblapack-dev liblapacke-dev gfortran
sudo apt-get install -y qt5-default
sudo apt-get install -y python3-dev python3-testresources
三、编译
- 下载文件创建目录
cd ~/
mkdir opencv
- 将压缩文件挨个解压到opencv
- 将download文件夹中的*.i文件全部放入/home//opencv/opencv_contrib-3.4.10/modules/xfeatures2d/src目录
4.修改face下载路径,修改下载路径为:“file:///home/ryan(自己的用户名)/opencv/download/”
sudo vim ~/opencv/opencv_contrib-3.4.10/modules/face/CMakeLists.txt
- 运行脚本:
./install_opencv3.4.10_Nano.sh
脚本内容
#!/bin/bash
#
# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
#
# NVIDIA Corporation and its licensors retain all intellectual property
# and proprietary rights in and to this software, related documentation
# and any modifications thereto. Any use, reproduction, disclosure or
# distribution of this software and related documentation without an express
# license agreement from NVIDIA Corporation is strictly prohibited.
#
folder="opencv-3.4.10"
version="3.4.10"
echo "** Install requirement"
sudo apt-get update
sudo apt-get install -y build-essential make cmake cmake-curses-gui git g++ pkg-config curl
sudo apt-get install -y libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libeigen3-dev libglew-dev libgtk2.0-dev
sudo apt-get install -y libtbb2 libtbb-dev libv4l-dev v4l-utils qv4l2 v4l2ucp
sudo apt-get install -y libdc1394-22-dev libxine2-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
sudo apt-get install -y libjasper-dev
sudo apt-get install -y libjpeg8-dev libjpeg-turbo8-dev libtiff-dev libpng-dev
sudo apt-get install -y libxvidcore-dev libx264-dev libgtk-3-dev
sudo apt-get install -y libatlas-base-dev libopenblas-dev liblapack-dev liblapacke-dev gfortran
sudo apt-get install -y qt5-default
#sudo apt-get install -y python3-dev python3-testresources
echo "** cd Download $folder"
cd $folder/
echo "** Building..."
mkdir release
cd release/
cmake -D WITH_CUDA=ON -D CUDA_ARCH_BIN="5.3" -D CUDA_ARCH_PTX="" \
-D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-$version/modules \
-D WITH_CUBLAS=ON -D ENABLE_FAST_MATH=ON -D CUDA_FAST_MATH=ON \
-D ENABLE_NEON=ON -D WITH_GSTREAMER=ON -D WITH_LIBV4L=ON \
-D WITH_GSTREAMER=ON -D WITH_LIBV4L=ON -D BUILD_opencv_python2=ON \
-D EIGEN_INCLUDE_PATH=/usr/include/eigen3 \
-D BUILD_opencv_python3=ON -D BUILD_TESTS=OFF \
-D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF \
-D WITH_QT=ON -D WITH_OPENGL=ON ..
-D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make -j3
sudo make install
sudo ldconfig
sudo apt-get install -y python-opencv python3-opencv
echo "** Install $folder successfully"
四、编译问题
问题1
boostdesc.cpp:654:20 fatal error: boostdesc_bgm.i
解决:
将download中间的*.i文件放入/home/user/opencv/opencv_contrib-3.4.10/modules/xfeatures2d/src
user为你的实际用户名
问题2
stitching/detail/matchers.hpp:52:12: fatal error: opencv2/xfeatures2d/cuda.hpp: No such file or directory
解决:
modules/python2 modules/python3 modules/stitching等模块中的CMakeLists.txt加入:
INCLUDE_DIRECTORIES("/home/ryan/opencv/opencv_contrib-3.4.10/modules/xfeatures2d/include")