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文件夹中,以便编译
https://opencv.org/releases.html
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")
③在 opencv\modules\cudev\include\opencv2\cudev\common.hpp中添加头文件
#include <cuda_fp16.h>
3.