下载和编译
这部分在前面有教程,需要在cmake中勾选CUDA的模块
https://www.jianshu.com/p/fc7113d821ea
查询相关算力:https://developer.nvidia.com/cuda-gpus
快捷查询:https://www.cnblogs.com/punkcure/p/7977864.html
在不需要兼容的情况下,只选择本机的版本可以减少编译时间
SURF+GPU加速使用
Mat a, b;
cv::cuda::SURF_CUDA surf(200);
//Detect the keypoints and descriptors
cv::cuda::GpuMat keypoints_1, keypoints_2;
cv::cuda::GpuMat descriptors_1, descriptors_2;
GpuMat img_1, img_2;
img_1.upload(a);
img_2.upload(b);
surf(img_1, cv::cuda::GpuMat(), keypoints_1, descriptors_1);
surf(img_2, cv::cuda::GpuMat(), keypoints_2, descriptors_2);
auto matcher = cv::cuda::DescriptorMatcher::createBFMatcher(cv::NORM_L2);
vector<DMatch> matches;
matcher->match(descriptors_1, descriptors_2, matches); //匹配
vector<KeyPoint> key1, key2;
surf.downloadKeypoints(keypoints_1, key1);
surf.downloadKeypoints(keypoints_2, key2);
Mat output;
drawKeypoints(a, key1, ouput);
imshow("output", output);
waitKey(0);
网友评论