Ask Your Question

It'd be a nice addition in the Feature Detection tutorial using FlannBasedMatcher in Python (asking here since is down) [closed]

asked 2017-11-19 18:43:58 -0500

Eli gravatar image

updated 2017-11-22 16:38:26 -0500

Since FlannBasedMatcher.knnMatch requires CV_32F for descriptor arrays

It'd be nice to have one of the examples use ORB rather than SIFT for FlannBasedMatcher and then detect and computer with ORB

kp1 = orb.detect(sample, None)
kp2 = orb.detect(display, None)
# Compute the descriptors
kp1, des1 = orb.compute(sample, kp1)
kp2, des2 = orb.compute(display, kp2)
# Convert descriptor array to float32
des1 = des1.astype(np.float32)
des2 = des2.astype(np.float32)
# Finds the matches in order of increasing distance    
matches = fbm.knnMatch(des1,des2,k=2)
matchesMask = [[0,0] for i in range(len(matches))]

for i,(m,n) in enumerate(matches):
    if m.distance < 0.7*n.distance:
draw_params = dict(matchColor = (0,255,0),
               singlePointColor = (255,0,0),
               matchesMask = matchesMask,
               flags = 0)
outImage = cv2.drawMatchesKnn(sample,kp1,display,kp2,matches,None,**draw_params)
outImage = cv2.cvtColor(outImage, cv2.COLOR_BGR2RGB) 
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Eli
close date 2017-11-20 17:22:42.948761



btw, does no more exist.

issues go here, (python)tutorials are here

berak gravatar imageberak ( 2017-11-20 05:20:22 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2017-11-20 01:33:01 -0500

berak gravatar image

It'd be nice to have one of the examples use ORB rather than SIFT for FlannBasedMatcher and then detect and computer with ORB

no, that's a terrible idea, and simply wrong.

ORB BRIEF BRISK and such are binary descriptors, bitstrings, they do not represent numbers at all. you cannot take 32 of them, and cast that memory to float (that's what you're trying above)

the correct way is to use the BFMatcher for those, with NORM_HAMMING or NORM_HAMMING2.

please try to understand the concept of hamming distance here

edit flag offensive delete link more


I understand hamming. I understand that values may be representative of bit strings. Numpy.astype float32 does not take 32 of them and make some float. It'd take each uint value of an ndarray and makes them floats. Also, the results in des1/2 are not bitstrings, they have already been converted to integers by the . See: code and result .

Eli gravatar imageEli ( 2017-11-20 13:55:35 -0500 )edit

... "take 32 bits of them" was meant above. and it is no different, if you see it as 4 bytes or an integer. casting that to float (to use L2 distance) is still wrong

berak gravatar imageberak ( 2017-11-20 17:04:43 -0500 )edit

Question Tools

1 follower


Asked: 2017-11-19 18:43:26 -0500

Seen: 373 times

Last updated: Nov 22 '17