详解VS2019+OpenCV-4-1-0+OpenCV-contrib-4-1-0

时间:2021-10-14 07:24:31

一、软件需求

VS2019社区版、win10操作系统、opencv4.1.0、opencv_contrib_4.1.0、cmake3.15.3

VS2019社区版(免费) 下载地址
OpenCV4.1.0 下载地址
OpenCV_contrib_4.1.0 下载地址
CMAKE 下载地址

二、CMAKE编译

在 D:\opencv_4.1.0 目录下创建个newbuild文件夹

进入cmake,配置OpenCV_4.1.0

详解VS2019+OpenCV-4-1-0+OpenCV-contrib-4-1-0

配置OpenCV_contrib_4.1.0

注意:第2步操作时后面的路径不要手打

详解VS2019+OpenCV-4-1-0+OpenCV-contrib-4-1-0

三、VS2019编译

进入 D:\opencv_4.1.0\newbuild 目录 找到 OpenCV.sln 双击

详解VS2019+OpenCV-4-1-0+OpenCV-contrib-4-1-0

四、系统环境变量配置

右键电脑-属性 -> 高级系统设置 ->环境变量 -> 系统变量 -> path

点击新建 填入 D:\opencv_4.1.0\newbuild\install\x64\vc16\bin

详解VS2019+OpenCV-4-1-0+OpenCV-contrib-4-1-0

五、VS2019环境变量配置

  1. 打开vs2019,新建一个空项目,打开属性管理器(视图-属性管理器\视图-其他-属性管理器)
  2. 双击 Microsoft.Cpp.x64.user

详解VS2019+OpenCV-4-1-0+OpenCV-contrib-4-1-0

配置包含目录(通用属性-VC++目录-包含目录),库目录(通用属性-VC++目录-库目录)

在包含目录中添加

D:\opencv_4.1.0\newbuild\install\include

D:\opencv_4.1.0\newbuild\install\include\opencv2

库目录中添加

D:\opencv_4.1.0\newbuild\install\x64\vc16\lib

详解VS2019+OpenCV-4-1-0+OpenCV-contrib-4-1-0

配置附加依赖项(链接器-输入-附加依赖项)

获取链接器的方法

  1. opencv_world410d.lib
  2. opencv_aruco410d.lib
  3. opencv_bgsegm410d.lib
  4. opencv_bioinspired410d.lib
  5. opencv_calib3d410d.lib
  6. opencv_ccalib410d.lib
  7. opencv_core410d.lib
  8. opencv_datasets410d.lib
  9. opencv_dnn410d.lib
  10. opencv_dnn_objdetect410d.lib
  11. opencv_dpm410d.lib
  12. opencv_face410d.lib
  13. opencv_features2d410d.lib
  14. opencv_flann410d.lib
  15. opencv_fuzzy410d.lib
  16. opencv_gapi410d.lib
  17. opencv_hfs410d.lib
  18. opencv_highgui410d.lib
  19. opencv_imgcodecs410d.lib
  20. opencv_imgproc410d.lib
  21. opencv_img_hash410d.lib
  22. opencv_line_descriptor410d.lib
  23. opencv_ml410d.lib
  24. opencv_objdetect410d.lib
  25. opencv_optflow410d.lib
  26. opencv_phase_unwrapping410d.lib
  27. opencv_photo410d.lib
  28. opencv_plot410d.lib
  29. opencv_quality410d.lib
  30. opencv_reg410d.lib
  31. opencv_rgbd410d.lib
  32. opencv_saliency410d.lib
  33. opencv_shape410d.lib
  34. opencv_stereo410d.lib
  35. opencv_structured_light410d.lib
  36. opencv_superres410d.lib
  37. opencv_surface_matching410d.lib
  38. opencv_text410d.lib
  39. opencv_tracking410d.lib
  40. opencv_video410d.lib
  41. opencv_videoio410d.lib
  42. opencv_videostab410d.lib
  43. opencv_ximgproc410d.lib
  44. opencv_xobjdetect410d.lib
  45. opencv_xphoto410d.lib

六、程序验证

  1. #include <opencv2/opencv.hpp>
  2. #include <iostream>
  3.  
  4. using namespace cv;
  5. using namespace std;
  6.  
  7. int main(int argc, char** argv) {
  8. Mat box = imread("1.jpg");
  9. Mat box_in_sence = imread("2.jpg");
  10.  
  11. // 创建AKAZE
  12. auto akaze_detector = AKAZE::create();
  13. vector<KeyPoint> kpts_01, kpts_02;
  14. Mat descriptors1, descriptors2;
  15. akaze_detector->detectAndCompute(box, Mat(), kpts_01, descriptors1);
  16. akaze_detector->detectAndCompute(box_in_sence, Mat(), kpts_02, descriptors2);
  17.  
  18. // 定义描述子匹配 - 暴力匹配
  19. Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create(DescriptorMatcher::BRUTEFORCE);
  20. std::vector< DMatch > matches;
  21. matcher->match(descriptors1, descriptors2, matches);
  22.  
  23. // 绘制匹配
  24. Mat img_matches;
  25. drawMatches(box, kpts_01, box_in_sence, kpts_02, matches, img_matches);
  26. imshow("AKAZE-Matches", img_matches);
  27. imwrite("D:/result.png", img_matches);
  28.  
  29. waitKey(0);
  30. return 0;
  31. }

七、VS2019属性页没有Microsoft.Cpp.x64.user解决办法

可以查看我写过的另一篇博客 VS2019属性管理器没有Microsoft.Cpp.x64.user的解决办法

参考博客

到此这篇关于详解VS2019+OpenCV-4-1-0+OpenCV-contrib-4-1-0的文章就介绍到这了,更多相关VS2019 OpenCV OpenCV-contrib 内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/Jayuee/article/details/105538253