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

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),
flags = 0)
outImage = cv2.drawMatchesKnn(sample,kp1,display,kp2,matches,None,**draw_params)
outImage = cv2.cvtColor(outImage, cv2.COLOR_BGR2RGB)
plt.imshow(outImage), plt.show()

edit retag 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

1

btw, code.opencv.org does no more exist.

issues go here, (python)tutorials are here

( 2017-11-20 05:20:22 -0500 )edit

Sort by ยป oldest newest most voted

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

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 .

( 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

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

Official site

GitHub

Wiki

Documentation