3

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?

Community
  • 1
  • 1
justHelloWorld
  • 6,478
  • 8
  • 58
  • 138

1 Answers1

2

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).

anotherdave
  • 6,656
  • 4
  • 34
  • 65
Humam Helfawi
  • 19,566
  • 15
  • 85
  • 160
  • Thanks for your answer. Anyway the signature of the function that the question talks about is `void cv::evaluateFeatureDetector( const Mat& img1, const Mat& img2, const Mat& H1to2, std::vector* _keypoints1, std::vector* _keypoints2, float& repeatability, int& correspCount, const Ptr& _fdetector )` which seems different from `points_within_the_homograph` that you defined in your answer. – justHelloWorld Jun 02 '16 at 09:30
  • From what I understood from the linked answer, What I would need is that `_keypoints2` contains only the points within the homography. – justHelloWorld Jun 02 '16 at 09:33
  • @justHelloWorld in orde to get the points wihting the homography you should use cv::findHomography this another step that should be taken – Humam Helfawi Jun 02 '16 at 09:37
  • Actually looking at the [evaluation.cpp](https://github.com/Itseez/opencv/blob/master/modules/features2d/src/evaluation.cpp) code I think that this operation (discard the points that doesn't belong to the common image part) is already done. Look at my **Edit** section – justHelloWorld Jun 02 '16 at 10:02
  • Could you look please [this](http://stackoverflow.com/questions/37588341/how-can-i-compile-the-evaluation-cpp-in-opencv) question also please? – justHelloWorld Jun 02 '16 at 10:08
  • The call to `emplace_back()` here contains `set_of_points[i]` twice — should the second one be `other_set_of_points`? Just wondering how it's creating a pair of matched points otherwise, as it looks like it's just going to have 2 references to keypoints1 – anotherdave Jan 27 '21 at 17:09
  • 1
    @anotherdave definitely! edited, thanks for notifying! – Humam Helfawi Jan 28 '21 at 07:54