当前位置:   article > 正文

windows下,opencv4.8.0+cuda编译及在vs2022中使用的详细教程_vs2022打包cuda程序

vs2022打包cuda程序

1、准备好opencv、opencv_contrib-4.8.0、cmake、vs2022,cuda

        配置不好的话,可直接找我要配置好的build文件:可进群:482742815,也可加qq:1401682937,请备注好,否则不同意

        另外,我上传了一部分文件,可以查看链接:https://download.csdn.net/download/Word_And_Me_/88605111

        opencv:Release OpenCV 4.8.0 · opencv/opencv · GitHub

        opencv:Release OpenCV 4.8.0 · opencv/opencv · GitHub

        opencv_contrib:Release 4.8.0 · opencv/opencv_contrib · GitHub

        cmake:https://cmake.org/files/v3.23/cmake-3.23.0-rc1-windows-i386.msi

        cuda我使用的是11.7,可以配置其他版本一样,具体不再介绍

2、开始使用cmake编译

首先,选择好路径,source为本来就有的,cuda_build为自定义名称,设置好点击configure

点击configure之后会弹出选择编译器,选好之后finish

编译过程中,或出现一些错误(红字体),这里第一个关于python的不用理会

另外一些问题是因为一些包不能下载,例如ffmpeg,ippicv

对应的文件可以在source源码中,找到对应的cmake文件,里面有下载地址,如果实在下不下来,我后面将提供文件

文件下载的地址为:(注意:新下载的文件命名需要在前面再加一段哈希字符,可在上面所说的cmake文件中找到)

cmake中需要查找的信息:

缺失的包下载完毕,并存储到相应位置后,点击generate

generate之后,配置opencv_ex目录,如下图:

搜索cuda,全部勾选,如图:

搜索test,取消勾选前三个,没有用,如图:

完成以上内容后,继续点击configure,如图:(注意,这一次的configure时间稍微较长)

configure完成之后,搜索cuda,会发现有一堆东西,这里我们找到cuda_fast_math勾选,其余不要动,如图:

在上个configure之后,你还会发现一些错误,这里也是因为下载失败,需要手动下载:(这里我选择不要face,其余两个尝试下载,同样方法找到cmake文件,找url,这里的cmake文件在opencv_contrib/moudules中)

这里如果你不用xfeatures2d,wechat_qrcode,也可以搜索相应的文件,取消勾选;以上操作完成之后,点击gengrate,如下图:

generate完成之后,进入对应的文件夹(cuda_build),打开opencv.sln

将debug改为release,生成对应的文件,如图:(生成一般需要1-2个小时,我使用了3个半小时,这里根据自己的设备不同,时间不一样,我了解到有人使用8个小时)

all_build生成完毕:

install生成完毕:

使用配置

1、打开自己创建的项目,右键-->属性-->vc++目录

包含目录:

库目录:

2、打开自己创建的项目,右键-->属性-->链接器-->输入-->编辑附加依赖项

这里依赖项可能是一堆,没有集成起来,可以使用Python获得所有的.lib文件,如果想要一个文件可以在编译阶段勾选,然后生成即可获得一个封装好的,但是存在风险,一旦有一个编译不成功,则不会生成这一个集成的文件,勾选项如下图:

我的有.lib文件有:

  1. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_aruco480.lib
  2. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_bgsegm480.lib
  3. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_bioinspired480.lib
  4. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_calib3d480.lib
  5. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_ccalib480.lib
  6. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_core480.lib
  7. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_cudaarithm480.lib
  8. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_cudabgsegm480.lib
  9. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_cudacodec480.lib
  10. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_cudafeatures2d480.lib
  11. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_cudafilters480.lib
  12. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_cudaimgproc480.lib
  13. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_cudalegacy480.lib
  14. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_cudaobjdetect480.lib
  15. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_cudaoptflow480.lib
  16. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_cudastereo480.lib
  17. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_cudawarping480.lib
  18. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_cudev480.lib
  19. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_datasets480.lib
  20. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_dnn480.lib
  21. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_dnn_objdetect480.lib
  22. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_dnn_superres480.lib
  23. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_dpm480.lib
  24. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_features2d480.lib
  25. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_flann480.lib
  26. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_fuzzy480.lib
  27. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_gapi480.lib
  28. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_hdf480.lib
  29. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_hfs480.lib
  30. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_highgui480.lib
  31. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_imgcodecs480.lib
  32. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_imgproc480.lib
  33. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_img_hash480.lib
  34. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_intensity_transform480.lib
  35. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_line_descriptor480.lib
  36. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_mcc480.lib
  37. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_ml480.lib
  38. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_objdetect480.lib
  39. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_optflow480.lib
  40. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_phase_unwrapping480.lib
  41. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_photo480.lib
  42. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_plot480.lib
  43. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_quality480.lib
  44. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_rapid480.lib
  45. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_reg480.lib
  46. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_rgbd480.lib
  47. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_saliency480.lib
  48. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_shape480.lib
  49. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_stereo480.lib
  50. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_stitching480.lib
  51. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_structured_light480.lib
  52. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_superres480.lib
  53. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_surface_matching480.lib
  54. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_text480.lib
  55. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_tracking480.lib
  56. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_video480.lib
  57. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_videoio480.lib
  58. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_videostab480.lib
  59. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_wechat_qrcode480.lib
  60. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_xfeatures2d480.lib
  61. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_ximgproc480.lib
  62. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_xobjdetect480.lib
  63. D:/Program Files (x86)/opencv/cuda_build/install/x64/vc17/lib/opencv_xphoto480.lib

提供一个代码:

  1. import os
  2. path = os.getcwd()
  3. for file in os.listdir(path):
  4.    with open('all.txt', 'a', encoding='utf-8') as f:
  5.        if file.endswith('.lib'):
  6.            newpath = path + "/" + file
  7.            newpath = newpath.replace("\\", "/")
  8.            print(newpath)
  9.            f.write(f"{newpath}\n")

我目前完成的测试:

  1. #include <iostream>
  2. #include <opencv2/opencv.hpp>
  3. #include <opencv2/core/cuda.hpp>
  4. #include <opencv2/cudaimgproc.hpp> // cvtColor
  5. #include <opencv2/cudafilters.hpp> // createGaussianFilter()
  6. #include <opencv2/cudafeatures2d.hpp>
  7. #include <opencv2/xfeatures2d.hpp>
  8. #include <opencv2/xfeatures2d/cuda.hpp>
  9. #include <opencv2/cudaimgproc.hpp>
  10. #include <opencv2/cudaarithm.hpp>
  11. #include <vector>
  12. int main() {
  13. // =================================cuda 测试=======================================
  14. /*cv::cuda::printCudaDeviceInfo(cv::cuda::getDevice());
  15. int count = cv::cuda::getCudaEnabledDeviceCount();
  16. std::cout << "可以使用的数量:" << count << std::endl;
  17. return 0;*/
  18. // ==================================灰度转换=======================================
  19. /*cv::Mat src_host = cv::imread("C:/Users/admin/Desktop/lena.jpg");
  20. cv::cuda::GpuMat src, gray;
  21. src.upload(src_host);
  22. cv::cuda::cvtColor(src, gray, cv::COLOR_BGR2GRAY);
  23. cv::Mat gray_host;
  24. gray.download(gray_host);
  25. cv::imshow("src", src_host);
  26. cv::imshow("gray", gray_host);
  27. cv::waitKey();
  28. cv::destroyAllWindows();
  29. return 0;*/
  30. // ==================================高斯模糊=======================================
  31. /*cv::Mat h_img1 = cv::imread("C:/Users/admin/Desktop/lenasp.jpg");
  32. cv::cuda::GpuMat d_img1, d_result3x3, d_result5x5, d_result7x7;
  33. // 加载数据
  34. d_img1.upload(h_img1);
  35. // 创建高斯
  36. auto filter3x3 = cv::cuda::createGaussianFilter(CV_8UC3, CV_8UC3, cv::Size(3, 3), 5);
  37. auto filter5x5 = cv::cuda::createGaussianFilter(CV_8UC3, CV_8UC3, cv::Size(5, 5), 5);
  38. auto filter7x7 = cv::cuda::createGaussianFilter(CV_8UC3, CV_8UC3, cv::Size(7, 7), 5);
  39. // 执行
  40. filter3x3->apply(d_img1, d_result3x3);
  41. filter5x5->apply(d_img1, d_result5x5);
  42. filter7x7->apply(d_img1, d_result7x7);
  43. // 获取结果
  44. cv::Mat h_result3x3, h_result5x5, h_result7x7;
  45. d_result3x3.download(h_result3x3);
  46. d_result5x5.download(h_result5x5);
  47. d_result7x7.download(h_result7x7);
  48. // 显示
  49. cv::imshow("original image", h_img1);
  50. cv::imshow("Blurred with kernel size 3x3", h_result3x3);
  51. cv::imshow("Blurred with kernel size 5x5", h_result5x5);
  52. cv::imshow("Blurred with kernel size 7x7", h_result7x7);
  53. cv::waitKey();
  54. cv::destroyAllWindows();
  55. return 0;*/
  56. // ==============================shi-tomas角点检测============================
  57. /*cv::Mat src_host = cv::imread("C:/Users/admin/Desktop/jianzhu.jpg");
  58. cv::imshow("input", src_host);
  59. cv::cuda::GpuMat src, gray, corners;
  60. cv::Mat dst;
  61. src.upload(src_host);
  62. cv::cuda::cvtColor(src, gray, cv::COLOR_BGR2GRAY);
  63. auto corner_detector = cv::cuda::createGoodFeaturesToTrackDetector(gray.type(), 1000, 0.01, 15, 3);
  64. corner_detector->detect(gray, corners);
  65. corners.download(dst);
  66. printf("detected corners %d....\n", corners.cols);
  67. printf("detected corners %d....\n", dst.cols);
  68. cv::RNG rng(123456);
  69. for (int i = 0; i < dst.cols; i++) {
  70. int r = rng.uniform(0, 255);
  71. int g = rng.uniform(0, 255);
  72. int b = rng.uniform(0, 255);
  73. cv::Point2f pt = dst.at<cv::Point2f>(0, i);
  74. circle(src_host, pt, 3, cv::Scalar(b, g, r), 2, 8, 0);
  75. }
  76. imshow("corner detect", src_host);
  77. cv::waitKey();
  78. cv::destroyAllWindows();
  79. return 0;*/
  80. // ================================双边模糊(美颜)===========================
  81. /*try {
  82. cv::Mat src_host = cv::imread("C:/Users/admin/Desktop/hh.jpg");
  83. cv::imshow("input", src_host);
  84. cv::cuda::GpuMat src(src_host);
  85. cv::cuda::GpuMat dst;
  86. cv::cuda::bilateralFilter(src, dst, 0, 100, 15, 4);
  87. cv::Mat dst_host;
  88. dst.download(dst_host);
  89. cv::imshow("result", dst_host);
  90. }
  91. catch (const cv::Exception& ec) {
  92. std::cout << "Error" << ec.what() << std::endl;
  93. }
  94. cv::waitKey();
  95. return 0;*/
  96. // ==============================ORB 特征匹配==========================
  97. /*// cpu data
  98. cv::Mat h_object_image = cv::imread("C:/Users/admin/Desktop/jianzhu1.jpg", 0);
  99. cv::Mat h_scene_image = cv::imread("C:/Users/admin/Desktop/jianzhu.jpg", 0);
  100. assert(h_object_image != nullptr && h_scene_image != nullptr), "======没有读取成功=====";
  101. cv::waitKey();
  102. // gpu data
  103. cv::cuda::GpuMat d_object_image;
  104. cv::cuda::GpuMat d_scene_image;
  105. cv::cuda::GpuMat d_keypoints_scene, d_keypoints_object;       // GPU key points
  106. std::vector<cv::KeyPoint> h_keypoints_scene, h_keypoints_object; // CPU key points
  107. cv::cuda::GpuMat d_descriptors_scene, d_descriptors_object;   // GPU descriptor
  108. // Image CPU uploaded to GPU
  109. d_object_image.upload(h_object_image);
  110. d_scene_image.upload(h_scene_image);
  111. // 对象检测
  112. auto orb = cv::cuda::ORB::create();
  113. // 检测特征点并提取相应的描述符
  114. // Detect feature points and extract corresponding descriptors
  115. orb->detectAndCompute(d_object_image, cv::cuda::GpuMat(), h_keypoints_object, d_descriptors_object);
  116. orb->detectAndCompute(d_scene_image, cv::cuda::GpuMat(), h_keypoints_scene, d_descriptors_scene);
  117. // 暴力匹配器
  118. // Brute Force Violence Matcher
  119. cv::Ptr<cv::cuda::DescriptorMatcher> matcher = cv::cuda::DescriptorMatcher::createBFMatcher(cv::NORM_HAMMING);
  120. std::vector<std::vector<cv::DMatch> > d_matches;
  121. matcher->knnMatch(d_descriptors_object, d_descriptors_scene, d_matches, 2);
  122. std::cout << "match size:" << d_matches.size() << std::endl;
  123. std::vector< cv::DMatch > good_matches;
  124. for (int k = 0; k < std::min(h_keypoints_object.size() - 1, d_matches.size()); k++)
  125. {
  126. if ((d_matches[k][0].distance < 0.9 * (d_matches[k][1].distance)) &&
  127. ((int)d_matches[k].size() <= 2 && (int)d_matches[k].size() > 0))
  128. {
  129. good_matches.push_back(d_matches[k][0]);
  130. }
  131. }
  132. std::cout << "size:" << good_matches.size() << std::endl;
  133. cv::Mat h_image_result;
  134. cv::drawMatches(h_object_image, h_keypoints_object, h_scene_image, h_keypoints_scene,
  135. good_matches, h_image_result, cv::Scalar::all(-1), cv::Scalar::all(-1),
  136. std::vector<char>(), cv::DrawMatchesFlags::DEFAULT);
  137. std::vector<cv::Point2f> object, scene;
  138. for (int i = 0; i < good_matches.size(); i++) {
  139. object.push_back(h_keypoints_object[good_matches[i].queryIdx].pt);
  140. scene.push_back(h_keypoints_scene[good_matches[i].trainIdx].pt);
  141. }
  142. cv::Mat Homo = cv::findHomography(object, scene, cv::RANSAC);
  143. std::vector<cv::Point2f> corners(4), scene_corners(4);
  144. corners[0] = cv::Point(0, 0);
  145. corners[1] = cv::Point(h_object_image.cols, 0);
  146. corners[2] = cv::Point(h_object_image.cols, h_object_image.rows);
  147. corners[3] = cv::Point(0, h_object_image.rows);
  148. cv::perspectiveTransform(corners, scene_corners, Homo);
  149. cv::line(h_image_result, scene_corners[0] + cv::Point2f(h_object_image.cols, 0), scene_corners[1] + cv::Point2f(h_object_image.cols, 0), cv::Scalar(255, 0, 0), 4);
  150. cv::line(h_image_result, scene_corners[1] + cv::Point2f(h_object_image.cols, 0), scene_corners[2] + cv::Point2f(h_object_image.cols, 0), cv::Scalar(255, 0, 0), 4);
  151. cv::line(h_image_result, scene_corners[2] + cv::Point2f(h_object_image.cols, 0), scene_corners[3] + cv::Point2f(h_object_image.cols, 0), cv::Scalar(255, 0, 0), 4);
  152. cv::line(h_image_result, scene_corners[3] + cv::Point2f(h_object_image.cols, 0), scene_corners[0] + cv::Point2f(h_object_image.cols, 0), cv::Scalar(255, 0, 0), 4);
  153. cv::imshow("Good Matches & Object detection", h_image_result);
  154. cv::waitKey(0);
  155. return 0;*/
  156. // ==============================surf 特征检测==============================
  157. cv::Mat h_object_image = cv::imread("C:/Users/admin/Desktop/jianzhu1.jpg", 0);
  158. cv::Mat h_scene_image = cv::imread("C:/Users/admin/Desktop/jianzhu.jpg", 0);
  159. cv::cuda::GpuMat d_object_image;
  160. cv::cuda::GpuMat d_scene_image;
  161. cv::cuda::GpuMat d_keypoints_scene, d_keypoints_object;
  162. std::vector<cv::KeyPoint> h_keypoints_scene, h_keypoints_object;
  163. cv::cuda::GpuMat d_descriptors_scene, d_descriptors_object;
  164. d_object_image.upload(h_object_image);
  165. d_scene_image.upload(h_scene_image);
  166. // 对象检测
  167. cv::cuda::SURF_CUDA surf(100);
  168. // 检测特征点并提取相应的描述符
  169. surf(d_object_image, cv::cuda::GpuMat(), d_keypoints_object, d_descriptors_object);
  170. surf(d_scene_image, cv::cuda::GpuMat(), d_keypoints_scene, d_descriptors_scene);
  171. // 暴力匹配器
  172. cv::Ptr<cv::cuda::DescriptorMatcher> matcher = cv::cuda::DescriptorMatcher::createBFMatcher();
  173. std::vector<std::vector<cv::DMatch>> d_matches;
  174. matcher->knnMatch(d_descriptors_object, d_descriptors_scene, d_matches, 2);
  175. surf.downloadKeypoints(d_keypoints_scene, h_keypoints_scene);
  176. surf.downloadKeypoints(d_keypoints_object, h_keypoints_object);
  177. std::vector<cv::DMatch> good_matches;
  178. for (int k = 0; k < std::min(h_keypoints_object.size() - 1, d_matches.size()); k++)
  179. {
  180. if ((d_matches[k][0].distance < 0.6 * (d_matches[k][1].distance)) && ((int)d_matches[k].size() <= 2 && (int)d_matches[k].size() > 0))
  181. {
  182. good_matches.push_back(d_matches[k][0]);
  183. }
  184. }
  185. std::cout << "size:" << good_matches.size();
  186. cv::Mat h_image_result;
  187. cv::drawMatches(h_object_image, h_keypoints_object, h_scene_image, h_keypoints_scene,
  188. good_matches, h_image_result, cv::Scalar::all(-1), cv::Scalar::all(-1),
  189. std::vector<char>(), cv::DrawMatchesFlags::DEFAULT);
  190. std::vector<cv::Point2f> object;
  191. std::vector<cv::Point2f> scene;
  192. for (int i = 0; i < good_matches.size(); i++)
  193. {
  194. object.push_back(h_keypoints_object[good_matches[i].queryIdx].pt);
  195. scene.push_back(h_keypoints_scene[good_matches[i].trainIdx].pt);
  196. }
  197. cv::Mat Homo = cv::findHomography(object, scene, cv::RANSAC);
  198. std::vector<cv::Point2f> corners(4);
  199. std::vector<cv::Point2f> scene_corners(4);
  200. corners[0] = cv::Point(0, 0);
  201. corners[1] = cv::Point(h_object_image.cols, 0);
  202. corners[2] = cv::Point(h_object_image.cols, h_object_image.rows);
  203. corners[3] = cv::Point(0, h_object_image.rows);
  204. cv::perspectiveTransform(corners, scene_corners, Homo);
  205. cv::line(h_image_result, scene_corners[0] + cv::Point2f(h_object_image.cols, 0), scene_corners[1] + cv::Point2f(h_object_image.cols, 0), cv::Scalar(255, 0, 0), 4);
  206. cv::line(h_image_result, scene_corners[1] + cv::Point2f(h_object_image.cols, 0), scene_corners[2] + cv::Point2f(h_object_image.cols, 0), cv::Scalar(255, 0, 0), 4);
  207. cv::line(h_image_result, scene_corners[2] + cv::Point2f(h_object_image.cols, 0), scene_corners[3] + cv::Point2f(h_object_image.cols, 0), cv::Scalar(255, 0, 0), 4);
  208. cv::line(h_image_result, scene_corners[3] + cv::Point2f(h_object_image.cols, 0), scene_corners[0] + cv::Point2f(h_object_image.cols, 0), cv::Scalar(255, 0, 0), 4);
  209. cv::imshow("Good Matches & Object detection", h_image_result);
  210. cv::waitKey(0);
  211. return 0;
  212. // =================================ORB特征检测================================
  213. /*cv::Mat h_image = cv::imread("C:/Users/admin/Desktop/jianzhu.jpg", 0);
  214. cv::Ptr<cv::cuda::ORB> detector = cv::cuda::ORB::create();
  215. std::vector<cv::KeyPoint> keypoints;
  216. cv::cuda::GpuMat d_image;
  217. d_image.upload(h_image);
  218. detector->detect(d_image, keypoints);
  219. cv::drawKeypoints(h_image, keypoints, h_image);
  220. cv::imshow("Final Result", h_image);
  221. cv::waitKey(0);
  222. return 0;*/
  223. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/839860
推荐阅读
相关标签
  

闽ICP备14008679号