ubuntu下安装opencv,cuda9.0下

xiaoxiao2021-03-01  4

一、安装Qt5

sudo apt-get install Qt5-default

二、Cmake版本3.8以上

1、移除久版本

 

sudo apt-get autoremove cmake

2、文件下载

 

wget https://cmake.org/files/v3.9/cmake-3.9.1-Linux-x86_64.tar.gz

3、创建软链接

 

mv cmake-3.9.1-Linux-x86_64 /opt/cmake-3.9.1 ln -sf /opt/cmake-3.9.1/bin/* /usr/bin/

4、查看版本

cmake --version

三、安装opencv

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、编译安装

下载:https://opencv.org/releases.html

选择source

解压:

unzip opencv-2.4.13.zip

mv opencv-2.4.13 path

# 打开文件夹"opencv-2.4.13": cd opencv-2.4.13 # 新建一个文件夹用于存放临时文件: mkdir release # 切换到该临时文件夹: cd release # 开始编译: cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local .. make -j4 # 开启线程 按照自己的配置 sudo make install

3、常见错误:

(1)在这个过程中,由于是cuda的64位和32位的问题,会出现 no found nppi...的问题(

 

CMake Error: Variables are set to NOTFOUND)。

解决方法为:https://stackoverflow.com/questions/46584000/cmake-error-variables-are-set-to-notfound

在opencv-2.4.13/cmake下找到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)

同时,由于cuda9.0不支持2.0,所以,在该目录下找到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") ...

去掉第一个if句,去掉elseif的else

 

set(__cuda_arch_bin "2.0 3.0 3.5 3.7 5.0 5.2 6.0 6.1")

去掉2.0

(2)如果cmake遇到unsupport “compute_20”

nvcc fatal : Unsupported gpu architecture 'compute_20'

用以下方式编译:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CUDA_GENERATION=Kepler ..

 

转载请注明原文地址: https://www.6miu.com/read-3849997.html

最新回复(0)