Ask Your Question
0

hi,I want to write a python code using "freak" descriptor methods.I wrote this code

asked 2016-04-07 09:47:33 -0600

updated 2016-04-07 13:39:09 -0600

berak gravatar image
import sys
import cv2
import cv2.xfeatures2d
import numpy as np
from matplotlib import pyplot as plt
sys.path.append('/usr/lib/python2.7/site-packages')
img_bgr=cv2.imread('sc2.png')
img_gray=cv2.cvtColor(img_bgr,cv2.COLOR_BGR2GRAY)
template=cv2.imread('template.png',0)
freakExtractor = cv2.xfeatures2d.FREAK_create()
kp1,des1=freakExtractor.compute(img_bgr.png,None)
kp2,des2=freakExtractor.compute(template.png,None)
bf=cv2.BFMatcher()
matches=bf.knnmatch(des1,des2,k=2)
matches=sorted(matches,key=lambda x:x.distance)
img3=cv2.drawMatchesKnn(img1,kp1,img2,kp2,matches,None,flags=2)
plt.imshow(img3),plt.imshow()
cv2.waitKey(0)
cv2.destroyAllWindows()

Error: Traceback (most recent call last): File "test3.py", line 15, in <module> matches=bf.knnmatch(des1,des2,k=2) AttributeError: 'cv2.BFMatcher' object has no attribute 'knnmatch'

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-04-07 13:42:49 -0600

berak gravatar image

updated 2016-04-07 13:46:07 -0600

this is a simple typo.

see:

>>> help(cv2.BFMatcher())
Help on BFMatcher object:

class BFMatcher(DescriptorMatcher)
 ...
 |  knnMatch(...)
 |      knnMatch(queryDescriptors, trainDescriptors, k[, mask[, compactResult]])
 -> matches  or  knnMatch(queryDescriptors, k[, masks[, compactResult]]) -> matches
 |
 |  match(...)
 |      match(queryDescriptors, trainDescriptors[, mask]) -> matches  or  match(
queryDescriptors[, masks]) -> matches
 |
 |  train(...)
 |      train() -> None
 |
 ...

so, it should be:

matches=bf.knnMatch(des1,des2,k=2) # case sensitive !
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-04-07 09:39:47 -0600

Seen: 1,982 times

Last updated: Apr 07 '16