Jack Simpson
Jack Simpson

Reputation: 1711

Finding matches between images with OpenCV dense SIFT

I've implemented a dense feature detector using OpenCV following one of the answers to this question.

sift = cv2.SIFT()
dense=cv2.FeatureDetector_create("Dense")
kp1=dense.detect(template_detect)
des1=sift.compute(template_detect,kp1)
kp2=dense.detect(image_detect)
des2=sift.compute(image_detect,kp2)

It works well, however, I'm interested in comparing these two images to try and find matches between them. However when try to implement it like below I get the error "TypeError: queryDescriptors is not a numerical tuple".

bf = cv2.BFMatcher(cv2.NORM_L2, crossCheck=True)
matches = bf.match(des1,des2)
matches = sorted(matches, key = lambda x:x.distance)
img3 = cv2.drawMatches(template_detect,kp1,image_detect,kp2,matches[:4], 2, None)

Is there a better way I should be trying to implement key point matches between the images?

Upvotes: 1

Views: 3285

Answers (1)

Poyan
Poyan

Reputation: 6643

You might have dropped this by now, but the error is that the signature for compute() is

Python: cv2.SIFT.compute(image, keypoints[, descriptors]) → keypoints, descriptors

Your code assigns des1/des2 with a tuple of both the keypoints and the descriptors, which is not what you want. Correction to your code would be;

sift = cv2.SIFT()
dense=cv2.FeatureDetector_create("Dense")
kp1=dense.detect(template_detect)
_, des1=sift.compute(template_detect,kp1)
kp2=dense.detect(image_detect)
_, des2=sift.compute(image_detect,kp2)

This would drop the keypoints from the return.

Upvotes: 1

Related Questions