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

1.准备依赖库

1
2
3
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要在官网下载,版本号要对应,否则编译会出很多问题

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

3.Cmake构建并编译安装

1
2
3
4
5
6
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

安装完成  

检测是否安装成功

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

 

ERROR:

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

解决办法:

cmake命令加上

1
-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文件

1
2
3
4
5
6
7
8
9
10
11
12
①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)
1
2
3
4
5
6
7
8
9
10
11
12
②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)
1
2
3
4
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

注释掉#

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

③在 opencv\modules\cudev\include\opencv2\cudev\common.hpp中添加头文件

1
#include <cuda_fp16.h>

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

解决办法:

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

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

重新编译即可

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

作者:HaijianYang
欢迎任何形式的转载,但请务必注明出处。
限于本人水平,如果文章和代码有表述不当之处,还请不吝赐教。

posted @   HaijianYang  阅读(510)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
点击右上角即可分享
微信分享提示