< >
Home » Xavier入门教程软件篇 » Xavier入门教程软件篇-源码安装带GPU支持的opencv3.2.0版本

Xavier入门教程软件篇-源码安装带GPU支持的opencv3.2.0版本

Xavier入门教程软件篇-源码安装带GPU支持的opencv3.2.0版本

说明:

  • 介绍如何在xavier下源码安装带GPU支持的opencv3.2.0版本

环境:

  • xavier使用sdk manager安装jetpack4.2
  • 默认已经安装opencv3.3.1
  • cuda 10
  • cuda9不再支持2.0架构,会导致后面的问题2

步骤:

  • 安装依赖:
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
sudo apt-get install -y python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
sudo apt-get install -y libv4l-dev v4l-utils qv4l2 v4l2ucp
sudo apt-get install -y curl
sudo apt-get update
  • 下载源码
mkdir -p ~/tools/
cd ~/tools/
curl -L https://github.com/opencv/opencv/archive/3.2.0.zip -o opencv-3.2.0.zip
unzip opencv-3.2.0.zip 
cd opencv-3.2.0/
  • 下载其他模块
git clone https://github.com/opencv/opencv_contrib.git
cd opencv_contrib
git checkout -b v3.2.0 3.2.0
  • 找到FindCUDA.cmake文件
  • 找到行,find_cuda_helper_libs(nppi)
  • 替换为
  find_cuda_helper_libs(nppial)
  find_cuda_helper_libs(nppicc)
  find_cuda_helper_libs(nppicom)
  find_cuda_helper_libs(nppidei)
  find_cuda_helper_libs(nppif)
  find_cuda_helper_libs(nppig)
  find_cuda_helper_libs(nppim)
  find_cuda_helper_libs(nppist)
  find_cuda_helper_libs(nppisu)
  find_cuda_helper_libs(nppitc)
  • 找到行,
set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppi_LIBRARY};${CUDA_npps_LIBRARY}")
  • 替换为:
set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppial_LIBRARY};${CUDA_nppicc_LIBRARY};${CUDA_nppicom_LIBRARY};${CUDA_nppidei_LIBRARY};${CUDA_nppif_LIBRARY};${CUDA_nppig_LIBRARY};${CUDA_nppim_LIBRARY};${CUDA_nppist_LIBRARY};${CUDA_nppisu_LIBRARY};${CUDA_nppitc_LIBRARY};${CUDA_npps_LIBRARY}")
  • 找到行
unset(CUDA_nppi_LIBRARY CACHE)
  • 替换为
unset(CUDA_nppial_LIBRARY CACHE)
unset(CUDA_nppicc_LIBRARY CACHE)
unset(CUDA_nppicom_LIBRARY CACHE)
unset(CUDA_nppidei_LIBRARY CACHE)
unset(CUDA_nppif_LIBRARY CACHE)
unset(CUDA_nppig_LIBRARY CACHE)
unset(CUDA_nppim_LIBRARY CACHE)
unset(CUDA_nppist_LIBRARY CACHE)
unset(CUDA_nppisu_LIBRARY CACHE)
unset(CUDA_nppitc_LIBRARY CACHE)
  • 找到文件OpenCVDetectCUDA.cmake文件
  • 找到
 ...
  set(__cuda_arch_ptx "")
  if(CUDA_GENERATION STREQUAL "Fermi")
    set(__cuda_arch_bin "2.0")
  elseif(CUDA_GENERATION STREQUAL "Kepler")
    set(__cuda_arch_bin "3.0 3.5 3.7")
  ...
  • 修改为
  ...
  set(__cuda_arch_ptx "")
  if(CUDA_GENERATION STREQUAL "Kepler")
    set(__cuda_arch_bin "3.0 3.5 3.7")
  elseif(CUDA_GENERATION STREQUAL "Maxwell")
    set(__cuda_arch_bin "5.0 5.2")
  ...
  • cuda9后的版本中有一个单独的halffloat(cuda_fp16.h)头文件,也应该被包括在opencv的目录里
  • 将头文件cuda_fp16.h添加至 opencv\modules\cudev\include\opencv2\cudev\common.hpp
#include <cuda_fp16.h>
  • 编译源码
mkdir release
cd release/
cmake -D WITH_CUDA=ON -D CUDA_ARCH_BIN="7.2" -D ENABLE_PRECOMPILED_HEADERS=OFF  -D CUDA_ARCH_PTX="" -D WITH_GSTREAMER=ON -D WITH_LIBV4L=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 -D OPENCV_EXTRA_MODULES_PATH=~/tools/opencv_contrib/modules ..

make
sudo make install 

问题:

  • 问题1:
if you get stdlib error use -DENABLE_PRECOMPILED_HEADERS=OFF flag on cmake
  • 问题2:
in the CMake files:
CUDA_nppi_LIBRARY (ADVANCED)
  • 需要更改多个文件,参考:
  • https://stackoverflow.com/questions/46584000/cmake-error-variables-are-set-to-notfound
  • https://blog.csdn.net/u014613745/article/details/78310916

纠错,疑问,交流: 请进入讨论区点击加入Q群

获取最新文章: 扫一扫右上角的二维码加入“创客智造”公众号


标签: xavier入门教程软件篇