#下载最新的opencv
git clone "https://github.com/opencv/opencv.git"
git clone "https://github.com/opencv/opencv_contrib.git"
#定义自己的生成目录
mkdir 20190509_cuda
mkdir -p opencv-master/build_cuda
cd opencv-master/build_cuda
#生成配置的时候选择带上opencv-contrib
# 注意 -DCUDA_CUDA_LIBRARY= 这个一定要加,这个是配置项的一个BUG,只能从这里绕过去。地址是cuda库中libcuda.so的绝对路径
cmake -DOPENCV_EXTRA_MODULES_PATH=/home/admin/opencv/opencv_contrib-master/modules -DCUDA_CUDA_LIBRARY=/usr/local/cuda-9.0/lib64/stubs/libcuda.so -DCMAKE_LIBRARY_PATH=/usr/local/cuda-9.0/lib64/stubs/ ..
#执行ccmake,配置编译选项
ccmake ..
#按t,切换进入高级模式
#主要修改的配置项如下:
1 //Build CUDA modules stubs when no CUDA SDK 2 BUILD_CUDA_STUBS:BOOL=OFF 3 4 //Create build rules for OpenCV Documentation 5 BUILD_DOCS:BOOL=OFF 6 7 //Build all examples 8 BUILD_EXAMPLES:BOOL=OFF 9 10 //Create Java wrapper exporting all functions of OpenCV library 11 // (requires static build of OpenCV modules) 12 BUILD_FAT_JAVA_LIB:BOOL=OFF 13 14 //Build IPP IW from source 15 BUILD_IPP_IW:BOOL=OFF 16 17 //Build Intel ITT from source 18 BUILD_ITT:BOOL=OFF 19 20 //Build libjasper from source 21 BUILD_JASPER:BOOL=OFF 22 23 //Enable Java support 24 BUILD_JAVA:BOOL=OFF 25 26 //Build libjpeg from source 27 BUILD_JPEG:BOOL=OFF 28 29 //Build openexr from source 30 BUILD_OPENEXR:BOOL=OFF 31 32 //Build performance tests 33 BUILD_PERF_TESTS:BOOL=OFF 34 35 //Build libpng from source 36 BUILD_PNG:BOOL=OFF 37 38 //Force to build libprotobuf from sources 39 BUILD_PROTOBUF:BOOL=OFF 40 41 //Build shared libraries (.dll/.so) instead of static ones (.lib/.a) 42 BUILD_SHARED_LIBS:BOOL=OFF 43 44 //Download and build TBB from source 45 BUILD_TBB:BOOL=OFF 46 47 //Build accuracy & regression tests 48 BUILD_TESTS:BOOL=OFF 49 50 //Build libtiff from source 51 BUILD_TIFF:BOOL=OFF 52 53 //Build WebP from source 54 BUILD_WEBP:BOOL=OFF 55 56 //Include debug info into release binaries ('OFF' means default 57 // settings) 58 BUILD_WITH_DEBUG_INFO:BOOL=OFF 59 60 //Enables dynamic linking of IPP (only for standalone IPP) 61 BUILD_WITH_DYNAMIC_IPP:BOOL=OFF 62 63 //Build zlib from source 64 BUILD_ZLIB:BOOL=OFF 65 66 //Include opencv_face module into the OpenCV build 67 BUILD_opencv_face:BOOL=OFF 68 69 //Include opencv_highgui module into the OpenCV build 70 BUILD_opencv_highgui:BOOL=OFF 71 72 //Include opencv_java_bindings_generator module into the OpenCV 73 // build 74 BUILD_opencv_java_bindings_generator:BOOL=OFF 75 76 //Include opencv_xfeatures2d module into the OpenCV build 77 BUILD_opencv_xfeatures2d:BOOL=OFF 78 79 //Choose the type of build, options are: None Debug Release RelWithDebInfo 80 // MinSizeRel ... 81 CMAKE_BUILD_TYPE:STRING=Debug 82 83 //Installation Directory 84 CMAKE_INSTALL_PREFIX:PATH=/home/admin/opencv/2019-05-09_cuda 85 86 //"cudart" library 87 CUDA_CUDART_LIBRARY:FILEPATH=/usr/local/cuda/lib64/libcudart.so 88 89 //Path to a program. 90 CUDA_NVCC_EXECUTABLE:FILEPATH=/usr/local/cuda/bin/nvcc 91 92 //Path to a file. 93 CUDA_TOOLKIT_INCLUDE:PATH=/usr/local/cuda/include 94 95 //Toolkit location. 96 CUDA_TOOLKIT_ROOT_DIR:PATH=/usr/local/cuda 97 98 //Use the static version of the CUDA runtime library if available 99 CUDA_USE_STATIC_CUDA_RUNTIME:BOOL=ON 100 101 //Enable ADE framework (required for Graph API module) 102 WITH_ADE:BOOL=OFF 103 104 //Include Aravis GigE support 105 WITH_ARAVIS:BOOL=OFF 106 107 //Include NVidia Cuda Runtime support 108 WITH_CUDA:BOOL=ON 109 110 //Include Intel Inference Engine support 111 WITH_INF_ENGINE:BOOL=OFF 112 113 //Include Intel IPP support 114 WITH_IPP:BOOL=OFF 115 116 //Include Intel ITT support 117 WITH_ITT:BOOL=OFF 118 119 //Include JPEG2K support 120 WITH_JASPER:BOOL=OFF 121 122 //Include JPEG support 123 WITH_JPEG:BOOL=OFF 124 125 //Include Lapack library support 126 WITH_LAPACK:BOOL=OFF 127 128 //Include NVidia Video Decoding library support 129 WITH_NVCUVID:BOOL=ON 130 131 //Include PNG support 132 WITH_PNG:BOOL=OFF 133 134 //Enable libprotobuf 135 WITH_PROTOBUF:BOOL=OFF 136 137 //Include Intel TBB support 138 WITH_TBB:BOOL=OFF 139 140 //Include TIFF support 141 WITH_TIFF:BOOL=OFF 142 143 //Include Vulkan support 144 WITH_VULKAN:BOOL=OFF 145 146 //Include WebP support 147 WITH_WEBP:BOOL=OFF
make -j 20
make install
=============================
2019-05-10补充:
//Build openexr from source
BUILD_OPENEXR:BOOL=ON
//Include ILM support via OpenEXR
WITH_OPENEXR:BOOL=ON
以上两项要打开,否则链接程序的时候出现大量如下错误:
/home/admin/opencv/opencv-master/modules/imgcodecs/src/grfmt_exr.cpp:250: undefined reference to `Im f::Slice::Slice(Imf::PixelType, char*, unsigned long, unsigned long, int, int, double, bool, bool)' /home/admin/opencv/opencv-master/modules/imgcodecs/src/grfmt_exr.cpp:252: undefined reference to `Im f::FrameBuffer::insert(char const*, Imf::Slice const&)' /home/admin/opencv/opencv-master/modules/imgcodecs/src/grfmt_exr.cpp:257: undefined reference to `Im f::Slice::Slice(Imf::PixelType, char*, unsigned long, unsigned long, int, int, double, bool, bool)' /home/admin/opencv/opencv-master/modules/imgcodecs/src/grfmt_exr.cpp:259: undefined reference to `Im f::FrameBuffer::insert(char const*, Imf::Slice const&)'