Ask Your Question

Revision history [back]

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

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 "", line 161, in <module>
    main(vid, video_file)
  File "", line 73, in consume_for_homography_error
    matches = flann_matcher(descriptors1, descriptors2)
  File "", 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?