cmake 配置 opencv4.5.2 contrib gpu 版本

cmake 配置 opencv4.5.2 contrib gpu 版本

首先要配置好环境,cuda 和 cudnn 的配置自行百度,这里默认是装好的

环境:

Win10 + Python3.8.8 + cuda11.1 + cudnn8.1 + cmake3.21.0 + opencv4.5.2 + visual studio 2017

下载 OpenCV 和 OpenCV-contrib

OpenCV 链接:
链接: https://github.com/opencv/opencv
OpenCV-contrib-4.x 链接:
链接: https://github.com/opencv/opencv_contrib
下载后解压到文件夹,如下结构:

配置目录结构
opencv
----build # 默认编译的文件
----mybuild # 用来存放自己编译的文件
----source
|_ _ _ modules
|_ _ _ opencv_contrib # 解压的 OpenCV-contrib-4.x
|_ _ _ modules

选择 cmake 源文件 和 build 路径

cmake 配置 opencv4.5.2 contrib gpu 版本_第1张图片

cmake 配置编译器

cmake 配置 opencv4.5.2 contrib gpu 版本_第2张图片

配置

勾选 cuda 相关项,再次 config
BUILD_CUDA_STUBS
OPENCV_DNN_CUDA
WITH_CUDA
cmake 配置 opencv4.5.2 contrib gpu 版本_第3张图片

配置 OPENCV_EXTRA_MODULES_PATH
注意路径不要 \ 要 \
cmake 配置 opencv4.5.2 contrib gpu 版本_第4张图片

该勾的都勾上
WITH_NVCUVID
CUDA_FAST_MATH
CUDA_ARCH_BIN 根据显卡算力匹配
cmake 配置 opencv4.5.2 contrib gpu 版本_第5张图片

【Configure】不报错 →【Generate】成功 →【Open Project】,选择 Release x64,右键【All_BUILD】→【生成】,需要很长时间,大概一个半小时吧,然后右键【INSTALL】→【生成】

cmake 配置 opencv4.5.2 contrib gpu 版本_第6张图片

编译完成后

python 端部署

拷贝模块,将:

opencv/mybuild/lib/python3/Release/cv2.cp38-win_amd64.pyd
opencv/mybuild/x64/vc15/bin/*.dll 

cmake 配置 opencv4.5.2 contrib gpu 版本_第7张图片

cmake 配置 opencv4.5.2 contrib gpu 版本_第8张图片

拷贝到

D:\Artificial_Intelligence\anaconda\Lib\site-packages\cv2

并替换掉原来的 .pyd 和 .dll
就可以了

补充:python端部署,除了这种方式,还可以一条命令搞定,省去了自己编译的步骤:

pip3 install opencv-contrib-python

C++ 端部署

visual studio 系列:

C/C+±-常规–附加包含目录:
opencv\build\include
opencv\build\include\opencv2

链接器–常规–附加库目录:
opencv\mybuild\lib\Release

链接器–输入–附加库目录:
opencv_aruco454.lib
opencv_barcode454.lib
opencv_bgsegm454.lib
opencv_bioinspired454.lib
opencv_calib3d454.lib
opencv_ccalib454.lib
opencv_core454.lib
opencv_cudaarithm454.lib
opencv_cudabgsegm454.lib
opencv_cudacodec454.lib
opencv_cudafeatures2d454.lib
opencv_cudafilters454.lib
opencv_cudaimgproc454.lib
opencv_cudalegacy454.lib
opencv_cudaobjdetect454.lib
opencv_cudaoptflow454.lib
opencv_cudastereo454.lib
opencv_cudawarping454.lib
opencv_cudev454.lib
opencv_datasets454.lib
opencv_dnn454.lib
opencv_dnn_objdetect454.lib
opencv_dnn_superres454.lib
opencv_dpm454.lib
opencv_face454.lib
opencv_features2d454.lib
opencv_flann454.lib
opencv_fuzzy454.lib
opencv_hfs454.lib
opencv_highgui454.lib
opencv_imgcodecs454.lib
opencv_imgproc454.lib
opencv_img_hash454.lib
opencv_intensity_transform454.lib
opencv_line_descriptor454.lib
opencv_mcc454.lib
opencv_ml454.lib
opencv_objdetect454.lib
opencv_optflow454.lib
opencv_phase_unwrapping454.lib
opencv_photo454.lib
opencv_plot454.lib
opencv_quality454.lib
opencv_rapid454.lib
opencv_reg454.lib
opencv_rgbd454.lib
opencv_saliency454.lib
opencv_shape454.lib
opencv_stereo454.lib
opencv_stitching454.lib
opencv_structured_light454.lib
opencv_superres454.lib
opencv_surface_matching454.lib
opencv_text454.lib
opencv_tracking454.lib
opencv_ts454.lib
opencv_video454.lib
opencv_videoio454.lib
opencv_videostab454.lib
opencv_wechat_qrcode454.lib
opencv_xfeatures2d454.lib
opencv_ximgproc454.lib
opencv_xobjdetect454.lib
opencv_xphoto454.lib

补充:如果不想要这么多的 lib CMake构建的时候勾选编译选项 BUILD_opencv_world, 则只会生成一个 opencv_world452.lib。

你可能感兴趣的:(OpenCV,环境配置,源码编译,opencv,计算机视觉,visual,studio)