Jetson TX2 安装opencv4.1 包含其他依赖项

环境描述

tx2系统为Ubuntu18.04,原Opencv版本为3.31

卸载旧版本opencv

sudo apt-get purge libopencv*
sudo apt autoremove
sudo apt-get update

#查看是否卸载成功
pkg-config opencv --modversion

下载opencv4.1的安装包

解压openc.zip、opencv_contrib.zip,将解压后的opencv_contrib文件夹放至opencv文件夹的根目录。

安装相关依赖

sudo apt-get install -y build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

sudo apt-get install -y libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev
sudo apt-get install -y python2.7-dev python3.6-dev python-dev python-numpy python3-numpy
sudo apt-get install -y libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libdc1394-22-dev
sudo apt-get install -y libv4l-dev v4l-utils qv4l2 v4l2ucp
sudo apt-get install -y curl

编译和安装

在opencv目录下,打开终端 创建build 文件:

mkdir build
cd build

创建 .sh脚本

touch cv_cmake.sh
vim cv_cmake.sh
 

将以下命令写入cv_cmake.sh中

#!/bin/bash
cmake \
    -D CMAKE_BUILD_TYPE=Release \
    -D CMAKE_INSTALL_PREFIX=/usr \
    -D BUILD_PNG=OFF \
    -D BUILD_TIFF=OFF \
    -D BUILD_TBB=OFF \
    -D BUILD_JPEG=OFF \
    -D BUILD_JASPER=OFF \
    -D BUILD_ZLIB=OFF \
    -D BUILD_EXAMPLES=ON \
    -D BUILD_opencv_java=OFF \
    -D BUILD_opencv_python2=OFF \
    -D BUILD_opencv_python3=ON \
    -D ENABLE_PRECOMPILED_HEADERS=OFF \
    -D WITH_OPENCL=OFF \
    -D WITH_OPENMP=OFF \
    -D WITH_FFMPEG=ON \
    -D WITH_GSTREAMER=ON \
    -D WITH_GSTREAMER_0_10=OFF \
    -D WITH_CUDA=ON \
    -D WITH_GTK=ON \
    -D WITH_VTK=OFF \
    -D WITH_TBB=ON \
    -D WITH_1394=OFF \
    -D WITH_OPENEXR=OFF \
    -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-10.0 \
    -D CUDA_ARCH_BIN=6.2 \
    -D CUDA_ARCH_PTX="" \
    -D OPENCV_EXTRA_MODULES_PATH=/home/nvidia/tx2/py/opencv/opencv-4.1.0/opencv_contrib-4.1.0/modules/ \
    ../
**#注意  OPENCV_EXTRA_MODULES_PATH  为各自的目录**  

#修改脚本权限:
chmod u+x cv_cmake.sh

#执行脚本:
./cv_cmake.sh

# make -j4  j8 均可    
sudo make -j8
sudo make install

你以为这就能成功 开玩耍呢 兄嘚!!!

以下内容重中之重,建议在编译前 操作这波

报错1

modules/xfeatures2d/src/boostdesc.cpp:673:20: fatal error: boostdesc_bgm.i: No such file or directory

将 文件(免费)放到 opencv_contrib/modules/xfeatures2d/src/ 路径下

报错2

CMakeFiles/Makefile2:13314: recipe for target ‘modules/xfeatures2d/CMakeFiles/opencv_test_xfeatures2d.dir/all’ failed
来 点进去下载 免费的哦

解压入文件夹,
将nvcuvid.h 、cuviddec.h复制 到 /usr/local/cuda/include/

sudo cp nvcuvid.h /usr/local/cuda/include/
sudo cp cuviddec.h /usr/local/cuda/include/

我跳过的坑 就这些吧
至此 祝你成功!

你可能感兴趣的:(Jetson,nano,TX2,机器学习)