Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

comparing two images

here is my code i have used BF matcher : import numpy as np import cv2

filename1 = 'BMW.jpg' filename2 = 'BMW_logo.jpg'

img1 = cv2.imread(filename1) # queryImage img2 = cv2.imread(filename2) # trainImage

# Initiate SIFT detector

sift = cv2.xfeatures2d.SIFT_create()

# find the keypoints and descriptors with SIFT

kp1, des1 = sift.detectAndCompute(img1,None) kp2, des2 = sift.detectAndCompute(img2,None)

# BFMatcher with default params

bf = cv2.BFMatcher() matches = bf.match(des1,des2)

matches = sorted(matches, key=lambda val: val.distance)

img3 = drawMatches(img1,kp1,img2,kp2,matches[:25])

# Show the image

cv2.imshow('Matched Features', img3) cv2.waitKey(10000) cv2.destroyWindow('Matched Features')

the error displayed is: Traceback (most recent call last): File "compare.py", line 24, in <module> img3 = drawMatches(img1,kp1,img2,kp2,matches[:25]) NameError: name 'drawMatches' is not defined any changes in the code , do help. and please explain the mistake too.