1、下载Cmake、VS、OpenCV、CUDA
(1)Cmake下载:Cmake
(2)VS,建议下载社区版,免费:VS
(3)CUDA下载的时候看要你的英伟达显卡是否支持,在这里找找:找找
2、打开Cmake,选择opencv源码路径,与编译目标路径,选择好之后点击configure
3、点击finish
3、完成后点击generate
4、找到OPENCV_EXTRA_MODULES_PATH,选择扩展包的路径,勾选OPENCV_ENABLE_NOFREE,然后在查找中输入cuda,勾选WITH_CUDA,BUILD_CUDA_STUBS,点击configure
5、勾选CUDA_FAST_MATH,然后将CUDA_ARCH_BIN中只留下显卡对应的算力值,然后点击configure
6、点击generate
7、在目标文件夹下打开OpenCV.sln
8、右击CmakeTargets里面的ALL_BUILD,点击生成,完成后再右击INSTALL,点击生成。成功后再切换到release,再把这一步操作一遍,就大功告成。可以看到目标文件夹中多了一个install文件夹,这个就是编译的结果了。然后在环境变量中添加路径(与你自己的一致即可)
9、VS配置OpenCV
(1)新建一个项目,,右击,在最底下选择属性
(2)点击VC++目录,选择包含目录和库目录,注意最上方的配置和平台要和项目的对应。
包含目录为:
库目录为:
(3)点击链接器中的输入,附加依赖项,我的如下:
opencv_aruco430d.lib
opencv_bgsegm430d.lib
opencv_bioinspired430d.lib
opencv_calib3d430d.lib
opencv_ccalib430d.lib
opencv_core430d.lib
opencv_cudaarithm430d.lib
opencv_cudabgsegm430d.lib
opencv_cudacodec430d.lib
opencv_cudafeatures2d430d.lib
opencv_cudafilters430d.lib
opencv_cudaimgproc430d.lib
opencv_cudalegacy430d.lib
opencv_cudaobjdetect430d.lib
opencv_cudaoptflow430d.lib
opencv_cudastereo430d.lib
opencv_cudawarping430d.lib
opencv_cudev430d.lib
opencv_datasets430d.lib
opencv_dnn430d.lib
opencv_dnn_objdetect430d.lib
opencv_dpm430d.lib
opencv_face430d.lib
opencv_features2d430d.lib
opencv_flann430d.lib
opencv_fuzzy430d.lib
opencv_gapi430d.lib
opencv_hfs430d.lib
opencv_highgui430d.lib
opencv_imgcodecs430d.lib
opencv_imgproc430d.lib
opencv_img_hash430d.lib
opencv_line_descriptor430d.lib
opencv_ml430d.lib
opencv_objdetect430d.lib
opencv_optflow430d.lib
opencv_phase_unwrapping430d.lib
opencv_photo430d.lib
opencv_plot430d.lib
opencv_quality430d.lib
opencv_reg430d.lib
opencv_rgbd430d.lib
opencv_saliency430d.lib
opencv_shape430d.lib
opencv_stereo430d.lib
opencv_stitching430d.lib
opencv_structured_light430d.lib
opencv_superres430d.lib
opencv_surface_matching430d.lib
opencv_text430d.lib
opencv_tracking430d.lib
opencv_video430d.lib
opencv_videoio430d.lib
opencv_videostab430d.lib
opencv_xfeatures2d430d.lib
opencv_ximgproc430d.lib
opencv_xobjdetect430d.lib
opencv_xphoto430d.lib
(4)测试
直接复制代码即可,记得把图片路径改了。
#include<opencv2/opencv.hpp>#include<iostream>using namespace cv;int main(int argc, char** argv) {Mat image = imread("C:\\Users\\YT\\Desktop\\lena.png");namedWindow("lena", WINDOW_NORMAL);imshow("lena", image);waitKey(0);return 0;}