OpenCV - Surf Algorithm - Giving lots of false positives

╄→尐↘猪︶ㄣ 提交于 2019-11-28 20:58:39

Remember that the usual pipeline is this:

  1. Get features from two images.
  2. Compute putative correspondences with the neighbor ratio (as you do), or with cross matching (@user2746401).
  3. Find a subset of consistent correspondences that support some geometrical relation between the images.

You have done steps 1 and 2, but 3 is missing. Note that putative correspondences are very noisy. You will obtain a lot of correspondences, many of them wrong, but some correct. It is difficult to tell for sure if them are correctly computed just by drawing them. So, it is normal that you see apparently weird correspondences.

To do step 3, in your case you can find a homography with RANSAC, as @user3481173 says. It is very easy, because OpenCV already provides the function cvFindHomography that does both things at the same time. A homography should work well in your case, since you are dealing with perspective transformations of planar images.

By the way, it will be much easier to you in the future to use the C++ API of OpenCV. The same code will probably occupy half the lines you have.

I don't think you can easily match between two images with only simple pair matching. The cost of doing this is enormous. Which is why you might want to consider using RANSAC.

I can recommend an example in Matlab by Zisserman and Kovesi

You will need this function for RANSAC by Peter Kovesi

I don't think there is "an" answer to your question, sorry. I can give some suggestions to how to reduce the false positives:

  • Do cross checked matching. In this scheme you find the nearest match for a feature from image A in image B and then take the match the feature from image B and find the nearest neighbour back in image A. If these match both ways then you consider it a match.

  • Do ratio matching. Here you track the nearest distance and second nearest distance between feature descriptors. if the ratio of the nearest to second nearest satisfies some threshold (say, 0.8) then keep it as a good match.

They should make your feature matching only match "good" feature between images. Once you have these good feature matches you can see which images have the best average distance between features. You could either threshold (as you are doing now) or, again, do a ratio test to ensure the image you select is sufficiently better than another image.

If you want the feature matching to do image retrieval then have a search for papers on this topic.... it's a very open question so keep experimenting!

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!