1 | initial version |
Okay, so here one possible solution:
// given your mousepoint coordiantes x,y (e.g. through setMouseCallback)
cv::Point mouse(x,y);
int nearest_index = -1;
float min_dist = std::numeric_limits<float>::max();
for( size_t i = 0; i < keypoints.size(); i++ ) {
double distance = cv::norm(mouse - keypoints[i].pt);
if ( distance < min_dist ) {
min_dist = distance;
nearest_index = i;
}
}
cv::KeyPoint nearest = keypoints[nearest_index];
As also said in the comments, you can also use BFMatcher or FlannMatcher if this solution is too slow for you.