Referring to this answer to this question:
What is happening is that you're considering all the keypoints detected in the second image for the calculation of repeatability and actually only the keypoints within the homography should be used.
I don't understand how to get the
keypoints withing the homography
Someone can explain how to do it?
EDIT:
Actually looking at the code of evaluation.cpp
I think that this operation is already performed. In fact, looking at:
float overlapThreshold;
bool ifEvaluateDetectors = thresholdedOverlapMask == 0;
if( ifEvaluateDetectors )
{
overlapThreshold = 1.f - 0.4f;
// remove key points from outside of the common image part
Size sz1 = img1.size(), sz2 = img2.size();
filterEllipticKeyPointsByImageSize( keypoints1, sz1 );
filterEllipticKeyPointsByImageSize( keypoints1t, sz2 );
filterEllipticKeyPointsByImageSize( keypoints2, sz2 );
filterEllipticKeyPointsByImageSize( keypoints2t, sz1 );
}
else
{
overlapThreshold = 1.f - 0.5f;
thresholdedOverlapMask->create( (int)keypoints1.size(), (int)keypoints2t.size(), CV_8UC1 );
thresholdedOverlapMask->setTo( Scalar::all(0) );
}
Consider that thresholdedOverlapMask=0
by default. So the part inside the if
discard the point outside the homography. Is that correct?
keypoints withing the homography Those are points that considered as inliers for the result Homograph Matrix. In other words:
Supposing you are using an estimation technique like RANSAC to get your Homograph Matrix, some of your points will be used to construct this Homograph. The others are just a noise(outliers). You need to know which of your points that are not noise and that were used to construct this Homograph.
How to do that in OpenCV?
The cv::findHomography
function has the following signature:
Mat findHomography(InputArray srcPoints, InputArray dstPoints, int method=0, double ransacReprojThreshold=3, OutputArray mask=noArray() );
The parameter OutputArray mask
is what you are looking for. You can use it like this:
std::vector<uchar> homograph_mask;
auto H= cv::findHomography(set_of_points, other_set_of_points, cv::RANSAC, RANSAC_THRESHOLSD, homograph_mask);
std::vector<std::pair<cv::Point,cv::Point>> points_within_the_homograph;
points_within_the_homograph.reserve(homograph_mask.size());
for(size_t i=0; i < homograph_mask.size();++i){
if(homograph_mask[i]==static_cast<uchar>(1)){
points_within_the_homograph.emplace_back(set_of_points[i],other_set_of_points[i]);
}
}
points_within_the_homograph.shrink_to_fit();
points_within_the_homograph
will contain a set of pairs of matched points that are within the Homograph (inliers).