Ask Your Question
0

Flann KNN Matcher in OpenCV returns only one point instead of a pair

asked 2015-07-08 22:28:29 -0600

When I run the Flann KNN matcher, then there are certain times when the KNN matcher only returns one point because of which code after the matcher that relies on there being two points fails:

flann = cv2.FlannBasedMatcher(index_params, search_params)

matches = flann.knnMatch(descriptors1, descriptors2, k=2)

# Retrieve good matches
good_matches = []

# ratio test as per Lowe's paper
for i, (m, n) in enumerate(matches):
    if m.distance < 0.7*n.distance:
        good_matches.append((m, n))

Throws this error:

Traceback (most recent call last):
  File "main.py", line 161, in <module>
    main(vid, video_file)
 ...
  File "main.py", line 73, in consume_for_homography_error
    matches = flann_matcher(descriptors1, descriptors2)
  File "main.py", line 48, in flann_matcher
    for i, (m, n) in enumerate(matches):
ValueError: need more than 1 value to unpack

What seems to be the problem here?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-03-28 04:14:41 -0600

4yo post, but facing the same issue.

Sorry, I am not able to understand why - or even if it's correct - for the FLANN KNN matcher to retrieve "lonely points"

A workaround could be to filter the matching "lonely point" :

( found at https://stackoverflow.com/questions/2... )

good = []
for i, m_n in enumerate(matches):
  if len(m_n) != 2:
    continue
  (m,n) = m_n
  if m.distance < 0.7 * n.distance:
    good.append(m)

NB : in your snippet you don't use the indices, so you don't need to enumerate matches

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-07-08 22:28:29 -0600

Seen: 744 times

Last updated: Jul 08 '15