Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BFMatcher raises error for Python interface when crossCheck option is enabled #46

Closed
erogol opened this issue Dec 7, 2014 · 6 comments

Comments

@erogol
Copy link

erogol commented Dec 7, 2014

bf = cv2.BFMatcher(cv2.NORM_L2, crossCheck=True)
matches = bf.knnMatch(descs,descs2, k=2)

raises

in ()
24 # BFMatcher with default params
25 bf = cv2.BFMatcher(cv2.NORM_L2, crossCheck=True)
---> 26 matches = bf.knnMatch(descs,descs2, k=2)
27
28 # Apply ratio test

error: /home/retina18/Downloads/Install-OpenCV-master/Ubuntu/OpenCV/opencv-2.4.10/modules/core/src/stat.cpp:2500: error: (-215) K == 1 && update == 0 && mask.empty() in function batchDistance

If I remove crossCheck option this works fine but I really need cross checking :(

@dereks
Copy link

dereks commented Sep 15, 2015

I get this same error. Compiled OpenCV 3.0.0 from source on Ubuntu 14.04.

@dereks
Copy link

dereks commented Sep 15, 2015

Found explanation here: #5

crossCheck is an alternative to the ratio test. It breaks knnMatch. So either use crossCheck=False and then do the ratio test, or use crossCheck=True and use bf.match() instead of bf.knnMatch().

@BloodAxe
Copy link
Member

Cross-check does matching of two sets of descriptors D1 and D2 in both directions (D1 -> D2 and D2 <- D1) retaining matches that exists in both.

Knn-match searches for N-best candidate for each descriptor. But it's impossible to make Cross-check between D1 and D2[N]. Therefore you have exception. As @dereks mentioned either you make cross-check or do knn-match with ratio test.

@dereks
Copy link

dereks commented Sep 15, 2015

But it's impossible to make Cross-check between D1 and D2[N].

I think it would be reasonable for crossCheck to compare D1[0] <-> D2[0] in the case of knnMatch(). That would validate the points by making sure the "best" matches were all crossChecked, and furthermore, they would then be subject to the distance ratio test between D[0] and D[1].

If I understand the algorithms correctly, this would apply two types of quality filtering, giving (perhaps?) better matching results with fewer outliers.

Consider this a request to re-open this bug as a new wishlist feature.

@sakthigeek
Copy link

I too would like this feature of combining ratio test and crosscheck to improve matching results to be added to a new wishlist feature. If it would help in decreasing the outliers, then it is worth the effort.

@sabarishkumaramaravadi
Copy link

I am getting the same error(in opencv 3.x). I tried in opencv 2.x with crossCheck=True and bf.matcher.knnMatch(instead of bf.matcher.match). I got better results(less outliers). Is this problem, resolved or anyone has a solution?, please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants