opencv安装cuda遇到的报错

写在前面:安装成功的各版本号
ubuntu 18.04
opencv 3.4.3 (无论是下载opencv还是opencv contrib都记得在github分支下找到对应版本的源码)
CUDA 10.2
首先需要已经安装好NVIDIA驱动和CUDA,其次还需要opencv的拓展包contrib,将下载好的contrib放入opencv文件夹中,重新编译。
最开始,我的CUDA版本是11.2,opencv3.4.3,按照网上其他教程,对opencv重新编译

cmake -D CMAKE_INSTALL_PREFIX=/usr/local -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=ON -D ENABLE_CXX11=1 -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules -D OPENCV_ENABLE_NONFREE=True -D INSTALL_PYTHON_EXAMPLES=ON -D INSTALL_C_EXAMPLES=ON -D WITH_CUDA=ON -D WITH_TBB=ON -D ENABLE_FAST_MATH=1 -D WITH_OPENMP=ON -D WITH_CUFFT=ON -D WITH_CUBLAS=ON ..

在cmake过程中遇到类似的下载,因为一些大家都懂的原因没有办法真正下载成功,因此需要手动添加进去

– xfeatures2d/boostdesc: Download: boostdesc_bgm_bi.i
– xfeatures2d/vgg: Download: vgg_generated_48.i

因此我把需要添加的几个文件放在了百度网盘:
链接: https://pan.baidu.com/s/17SkrbfCRZYCqyxstGC6GMg
提取码: mdjw
文件格式如下
opencv安装cuda遇到的报错_第1张图片将这几个文件放入opencv/opencv_contrib/modules/xfeatures2d/src
到这里cmake可以正常进行,在make时又有了新的问题
报错如下:
opencv安装cuda遇到的报错_第2张图片

/usr/bin/ld: cannot find -ltrue

我就在网上复制粘贴了这句话,相似的报错解决方法并没有用,最后的最后,我换成了CUDA 10.2版本,这个错误没了,,,竟然就这样解决了,,,
原因不清楚,不知道为什么不兼容,可能是cuda11.2版本太新了吧。

版本问题解决了以后,编译过程中可能还会遇到另一个错误:

/home/xxx/library_codes/opencv/modules/cudacodec/src/precomp.hpp:60:18: fatal error: dynlink_nvcuvid.h: No such file or directory
#include

opencv安装cuda遇到的报错_第3张图片解决方法在这里

装好之后可以用以下代码测试一下:
CMakeLists.txt :

# cmake needs this line
cmake_minimum_required(VERSION 2.8)
 
# Define project name
project(test)
# Find OpenCV, you may need to set OpenCV_DIR variable
# to the absolute path to the directory containing OpenCVConfig.cmake file
# via the command line or GUI
#set(OpenCV_DIR "/home/karry/library_codes/opencv/build-c")
find_package(OpenCV 3 REQUIRED)
 
# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS "    version: ${OpenCV_VERSION}")
message(STATUS "    libraries: ${OpenCV_LIBS}")
message(STATUS "    include path: ${OpenCV_INCLUDE_DIRS}")
 
if(CMAKE_VERSION VERSION_LESS "2.8.11")
  # Add OpenCV headers location to your include paths
  include_directories(${OpenCV_INCLUDE_DIRS})
endif()
 
# Declare the executable target built from your sources
add_executable(opencv_example main.cpp)
 
# Link your application with OpenCV libraries
target_link_libraries(opencv_example ${OpenCV_LIBS})
 

main.cpp :

using namespace std;
#include "opencv2/opencv.hpp"
#include "opencv2/core/cuda.hpp"
using namespace cv;
 
int main()
{
    int num_devices = cv::cuda::getCudaEnabledDeviceCount();//得到已安装CUDA设备的数量
 
    cout<<num_devices<<endl;
}

输出为1则表示安装成功,如果此时Opencv仍不支持CUDA则会输出0

你可能感兴趣的:(cuda,opencv)