Skip to content

Instantly share code, notes, and snippets.

@DZESU
Created September 5, 2019 08:29
Show Gist options
  • Select an option

  • Save DZESU/a188dffd01c9797df926284994ceb31c to your computer and use it in GitHub Desktop.

Select an option

Save DZESU/a188dffd01c9797df926284994ceb31c to your computer and use it in GitHub Desktop.
# Need to draw only good matches, so create a mask
matches_mask = [[0, 0] for i in range(len(flann_matches))]
# ratio test as per Lowe's paper
good = []
for index in range(len(flann_matches)):
if len(flann_matches[index]) == 2:
m, n = flann_matches[index]
if m.distance < 0.8 * n.distance: # 0.8 is threshold of ratio testing
matches_mask[index] = [1, 0]
good.append(flann_matches[index])
draw_params = dict(
singlePointColor=(255, 0, 0),
matchesMask=matches_mask,
flags=2)
img3 = cv2.drawMatchesKnn(image_train, kp_logo, image_query, kp_img, flann_matches, None, **draw_params)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment