Jetson cuda build opencv

1- compiled CUDA: YES

 - NVIDIA Jetson Xavier NX (Developer Kit Version)
   * Jetpack 4.4 [L4T 32.4.3]
   * NV Power Mode: MODE_10W_2CORE - Type: 3
   * jetson_stats.service: active
 - Libraries:
   * CUDA: 10.2.89
   * cuDNN: 8.0.0.180
   * TensorRT: 7.1.3.0
   * Visionworks: 1.6.0.501
   * OpenCV: 4.1.1 compiled CUDA: NO
   * VPI: 0.4.4
   * Vulkan: 1.2.70

目标:compiled CUDA: NO --> compiled CUDA: YES

2 如何安装opencv

Install需要10G 以上,因此保证硬盘足够

卸载原来opencv:
sudo apt purge libopencv*
sudo apt autoremove

安装opencv 依赖库:
sudo apt-get update
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
sudo apt-get install -y libeigen3-dev
sudo apt-get install -y  libjasper-dev

下载opencv 安装包:
curl -L https://github.com/opencv/opencv/archive/4.1.1.zip -o opencv-4.1.1.zip
curl -L https://github.com/opencv/opencv_contrib/archive/4.1.1.zip -o opencv_contrib-4.1.1.zip

解压:
unzip opencv-4.1.0.zip 
unzip opencv_contrib-4.1.0.zip 
cd opencv-4.1.0/
mkdir release
cd release/

cmake: 指定安装路径/mnt/install_opencv
cmake -D WITH_CUDA=ON -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.1.1/modules  -D WITH_GSTREAMER=ON  -D WITH_LIBV4L=ON -D BUILD_opencv_python2=ON  -D BUILD_opencv_python3=ON  -D BUILD_TESTS=OFF  -D BUILD_PERF_TESTS=OFF  -D BUILD_EXAMPLES=OFF  -D CMAKE_BUILD_TYPE=RELEASE  -D CMAKE_INSTALL_PREFIX=/mnt/install_opencv ..

build 安装:
make -j4
sudo make install

备注如果按照到系统:
cmake -D WITH_CUDA=ON -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.1.1/modules  -D WITH_GSTREAMER=ON  -D WITH_LIBV4L=ON -D BUILD_opencv_python2=ON  -D BUILD_opencv_python3=ON  -D BUILD_TESTS=OFF  -D BUILD_PERF_TESTS=OFF  -D BUILD_EXAMPLES=OFF  -D CMAKE_BUILD_TYPE=RELEASE  -D CMAKE_INSTALL_PREFIX=/usr/local ..

sudo make install

3- 安装过程碰到的问题

  • 3.1 安装 libjasper-dev
    apt install libjasper1 libjasper-dev
 增加 /etc/apt/sources.list
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-security main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-updates main multiverse restricted universe
deb-src http://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ xenial-backports main multiverse restricted universe

更新:
sudo apt update
apt install libjasper1 libjasper-dev
  • 3.2安装过程出错:
[ 12%] Building CXX object 3rdparty/carotene/hal/carotene/CMakeFiles/carotene_objs.dir/src/dot_product.cpp.o
In file included from /mnt/opencv-4.1.1/modules/core/src/precomp.hpp:55:0,
                 from /mnt/opencv-4.1.1/release/modules/core/opencv_core_pch_dephelp.cxx:1:
/mnt/opencv-4.1.1/modules/core/include/opencv2/core/private.hpp:66:12: fatal error: Eigen/Core: No such file or directory
 #  include 
            ^~~~~~~~~~~~
compilation terminated.
modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/build.make:62: recipe for target 'modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/opencv_core_pch_dephelp.cxx.o' failed
make[2]: *** [modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/opencv_core_pch_dephelp.cxx.o] Error 1
CMakeFiles/Makefile2:2601: recipe for target 'modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/all' failed
make[1]: *** [modules/core/CMakeFiles/opencv_core_pch_dephelp.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

解决方法:
sudo ln -s /usr/include/eigen3/Eigen /usr/include/Eigen

  • 3.3 boostdesc_bgm.i 缺失
    OpenCV4 编译 fatal error: boostdesc_bgm.i: No such file or directory
/home/jetson/opencv/.cache/xfeatures2d/
├── boostdesc
│   ├── 0ae0675534aa318d9668f2a179c2a052-boostdesc_lbgm.i
│   ├── 0ea90e7a8f3f7876d450e4149c97c74f-boostdesc_bgm.i
│   ├── 202e1b3e9fec871b04da31f7f016679f-boostdesc_binboost_064.i
│   ├── 232c966b13651bd0e46a1497b0852191-boostdesc_bgm_bi.i
│   ├── 324426a24fa56ad9c5b8e3e0b3e5303e-boostdesc_bgm_hd.i
│   ├── 98ea99d399965c03d555cef3ea502a0b-boostdesc_binboost_128.i
│   └── e6dcfa9f647779eb1ce446a8d759b6ea-boostdesc_binboost_256.i
└── vgg
    ├── 151805e03568c9f490a5e3a872777b75-vgg_generated_120.i
    ├── 7126a5d9a8884ebca5aea5d63d677225-vgg_generated_64.i
    ├── 7cd47228edec52b6d82f46511af325c5-vgg_generated_80.i
    └── e8d0dcd54d1bcfdc29203d011a797179-vgg_generated_48.i

2 directories, 11 files


/home/jetson/opencv_contrib/modules/xfeatures2d/src/
├── affine_feature2d.cpp
├── boostdesc_bgm_bi.i
├── boostdesc_bgm_hd.i
├── boostdesc_bgm.i
├── boostdesc_binboost_064.i
├── boostdesc_binboost_128.i
├── boostdesc_binboost_256.i
├── boostdesc.cpp
├── boostdesc_lbgm.i
├── brief.cpp
├── cuda
│   └── surf.cu
├── daisy.cpp
├── ellipticKeyPoint.cpp
├── fast.cpp
├── freak.cpp
├── generated_16.i
├── generated_32.i
├── generated_64.i
├── gms.cpp
├── harris_lapace_detector.cpp
├── latch.cpp
├── logos
│   ├── Logos.cpp
│   ├── Logos.hpp
│   ├── Match.cpp
│   ├── Match.hpp
│   ├── Point.cpp
│   ├── Point.hpp
│   ├── PointPair.cpp
│   └── PointPair.hpp
├── logos.cpp
├── lucid.cpp
├── msd.cpp
├── opencl
│   └── surf.cl
├── pct_signatures
│   ├── constants.hpp
│   ├── distance.hpp
│   ├── grayscale_bitmap.cpp
│   ├── grayscale_bitmap.hpp
│   ├── pct_clusterizer.cpp
│   ├── pct_clusterizer.hpp
│   ├── pct_sampler.cpp
│   ├── pct_sampler.hpp
│   └── similarity.hpp
├── pct_signatures.cpp
├── pct_signatures_sqfd.cpp
├── precomp.hpp
├── sift.cpp
├── stardetector.cpp
├── surf.cpp
├── surf.cuda.cpp
├── surf.hpp
├── surf.ocl.cpp
├── vgg.cpp
├── vgg_generated_120.i
├── vgg_generated_48.i
├── vgg_generated_64.i
├── vgg_generated_80.i
└── xfeatures2d_init.cpp

4 directories, 57 files

链接:https://pan.baidu.com/s/1ihQggYXevvgw7kcMKT8Uvg 提取码:9491

检测上面的文件缺失情况:
我的缺失文件如下路径,放置进入,重新make -j4 就可以
/home/jetson/opencv_contrib/modules/xfeatures2d/src/
  • 3.4 nvidiaOpticalFlow 出现问题
[ 92%] Building CXX object modules/cudaoptflow/CMakeFiles/opencv_cudaoptflow.dir/src/nvidiaOpticalFlow.cpp.o
[ 92%] Built target opencv_visualisation
/mnt/opencv_contrib-4.1.1/modules/cudaoptflow/src/nvidiaOpticalFlow.cpp:19:10: fatal error: nvOpticalFlowCommon.h: No such file or directory
 #include "nvOpticalFlowCommon.h"
          ^~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
modules/cudaoptflow/CMakeFiles/opencv_cudaoptflow.dir/build.make:1014: recipe for target 'modules/cudaoptflow/CMakeFiles/opencv_cudaoptflow.dir/src/nvidiaOpticalFlow.cpp.o' failed
make[2]: *** [modules/cudaoptflow/CMakeFiles/opencv_cudaoptflow.dir/src/nvidiaOpticalFlow.cpp.o] Error 1
CMakeFiles/Makefile2:9702: recipe for target 'modules/cudaoptflow/CMakeFiles/opencv_cudaoptflow.dir/all' failed
make[1]: *** [modules/cudaoptflow/CMakeFiles/opencv_cudaoptflow.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 92%] Built target opencv_interactive-calibration
Makefile:162: recipe for target 'all' failed
make: *** [all] Error 2


下载:
https://github.com/NVIDIA/NVIDIAOpticalFlowSDK/archive/79c6cee80a2df9a196f20afd6b598a9810964c32.zip

解压路径:
/mnt/opencv-4.1.1/release/3rdparty/NVIDIAOpticalFlowSDK_1_0_Headers/NVIDIAOpticalFlowSDK-79c6cee80a2df9a196f20afd6b598a9810964c32

修改CMakeLists.txt:
/mnt/opencv_contrib-4.1.1/modules/cudaoptflow/CMakeLists.txt:
if(IOS OR WINRT OR (NOT HAVE_CUDA AND NOT BUILD_CUDA_STUBS))
  ocv_module_disable(cudaoptflow)
endif()

set(the_description "CUDA-accelerated Optical Flow")

ocv_warnings_disable(CMAKE_CXX_FLAGS /wd4127 /wd4324 /wd4512 -Wundef -Wmissing-declarations -Wshadow)

ocv_define_module(cudaoptflow opencv_video opencv_optflow opencv_cudaarithm opencv_cudawarping opencv_cudaimgproc OPTIONAL opencv_cudalegacy WRAP python)

set(NVIDIA_OPTICAL_FLOW_1_0_HEADERS_COMMIT "79c6cee80a2df9a196f20afd6b598a9810964c32")
set(NVIDIA_OPTICAL_FLOW_1_0_HEADERS_MD5 "ca5acedee6cb45d0ec610a6732de5c15")
set(NVIDIA_OPTICAL_FLOW_1_0_HEADERS_PATH "${OpenCV_BINARY_DIR}/3rdparty/NVIDIAOpticalFlowSDK_1_0_Headers")
#ocv_download(FILENAME "${NVIDIA_OPTICAL_FLOW_1_0_HEADERS_COMMIT}.zip"
#               HASH ${NVIDIA_OPTICAL_FLOW_1_0_HEADERS_MD5}
#               URL
#                 "https://github.com/NVIDIA/NVIDIAOpticalFlowSDK/archive/"
#               DESTINATION_DIR "${NVIDIA_OPTICAL_FLOW_1_0_HEADERS_PATH}"
#               STATUS NVIDIA_OPTICAL_FLOW_1_0_HEADERS_DOWNLOAD_SUCCESS
#               ID "NVIDIA_OPTICAL_FLOW"
#               UNPACK RELATIVE_URL)

#if(NOT NVIDIA_OPTICAL_FLOW_1_0_HEADERS_DOWNLOAD_SUCCESS)
if(1)
        #message(STATUS "Failed to download NVIDIA_Optical_Flow_1_0 Headers")
#else()
  add_definitions(-DHAVE_NVIDIA_OPTFLOW=1)
  message("xfwang------------------------------999999999999999999999999")
  message("xfwang------------------------------999999999999999999999999:""${NVIDIA_OPTICAL_FLOW_1_0_HEADERS_PATH}/NVIDIAOpticalFlowSDK-${NVIDIA_OPTICAL_FLOW_1_0_HEADERS_COMMIT}")
  ocv_include_directories(SYSTEM "${NVIDIA_OPTICAL_FLOW_1_0_HEADERS_PATH}/NVIDIAOpticalFlowSDK-${NVIDIA_OPTICAL_FLOW_1_0_HEADERS_COMMIT}")
endif()
  • 3.5其他
sudo apt install mount
如果需要安装mount 指令
sudo mount /dev/sda1 /mnt/

你可能感兴趣的:(Jetson cuda build opencv)