Created
July 9, 2020 19:08
-
-
Save simogasp/551441c55a13906b5aa9d9244291161c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// these contains the descriptors from the two images | |
// so you need to convert the AliceVision data structure for descriptors into GpuMat | |
cv::cuda::GpuMat inputGPUDescriptors1; | |
cv::cuda::GpuMat inputGPUDescriptors2; | |
// match the features | |
// this creates a brute force matcher (it matches each feature against all the others in the other image (more efficient in GPU) | |
cv::Ptr<cv::cuda::DescriptorMatcher> matcher= cv::cuda::DescriptorMatcher::createBFMatcher(); | |
// this contains for each descriptor a vector of size knn (in this case 2) with the best and second best match for the descriptor | |
std::vector<std::vector<cv::DMatch>> matchesknn; | |
const float ratioThreshold{.6f}; | |
const int knn{2}; | |
// do the knn match | |
matcher->knnMatch(inputGPUDescriptors1, inputGPUDescriptors2, matchesknn, knn); | |
// apply the ratio test | |
std::vector<cv::DMatch> matches; | |
matches.reserve(matchesknn.size()); | |
for(const auto& m : matchesknn) | |
{ | |
// test the ratio between the distances of the best and second best, if lower than a threshold it add the best match | |
if(m[0].distance < ratioThreshold*m[1].distance) | |
matches.push_back(m[0]); | |
} | |
matches.shrink_to_fit(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment