ubuntu 16.04 安装Opencv-3.2.0_GPU 与 opencv_contrib-3.2.0

1.准备依赖库

sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev

2.下载对应的版本的Opencv与Opencv_contrib并解压,将Opencv_contrib解压到Opencv文件夹中,以便编译

※Opencv_contrib要在官网下载,版本号要对应,否则编译会出很多问题

Opencv: https://opencv.org/releases.html
Opencv_contrib: https://github.com/opencv/opencv_contrib/releases?after=3.4.3

3.Cmake构建并编译安装

cd opencv-3.2.0
mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=/home/×××/opencv-3.2.0/opencv_contrib/modules/ ..
sudo make -j8  (8指8线程,尽量用sudo获取权限)
sudo make install

安装完成  

检测是否安装成功

python -c "import cv2; print cv2.__version__"

ERROR:

1.遇到:nvcc fatal:Unsupported gpu architecture 'compute_20

解决办法:

cmake命令加上

-D CUDA_GENERATION=Kepler 

2.遇到

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.  Please set them or make sure they are set and tested correctly in the CMake files:  CUDA_nppi_LIBRARY (ADVANCED)

解决办法:

在Opencv文件夹:

(1)找到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)
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)
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}")

(2)找到文件OpenCVDetectCUDA.cmake

注释掉#

if(CUDA_GENERATION STREQUAL "Fermi")
set(__cuda_arch_bin "2.0")

③在 opencvmodulescudevincludeopencv2cudevcommon.hpp中添加头文件

#include <cuda_fp16.h>

3.遇到××××××.hpp无法找到文件opencv2/xfeatures2d/cuda.hpp

解决办法:

在opencv/modules/stitching/CMakeLists.txt文件中加入xfeatures2d/include的指定路径,即

INCLUDE_DIRECTORIES("××××××[绝对路径]××××××/opencv_contrib/modules/xfeatures2d/include")

重新编译即可

4.如果网络不好,出现ippicv_linux_20151201.tgz无法在终端下载的情况,则可以先单独下载ippicv_linux_20151201.tgz之后,把其移动到终端所提示的路径(终端会提示该路径找不到文件如果同样有其他类似的文件无法下载,方法同上。

原文地址:https://www.cnblogs.com/haijian/p/10863180.html