Ask Your Question
0

to get th coordinates of sift keypoints

asked 2018-06-17 02:53:17 -0600

sfredv gravatar image

updated 2018-06-17 03:48:52 -0600

berak gravatar image

this is my code to detect and display keypoints (im using opencv 3.1.0 and python 2.7 )

import cv2
import numpy as np

img = cv2.imread('info-tabs3.jpg')
gray= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

sift = cv2.xfeatures2d.SIFT_create()
kp = sift.detect(gray,None)
pts = np.float([kp[idx].pt for idx in len(kp)]).reshape(-1, 1, 2)
print 'The list of detected keypoints is:' pts.pt

img=cv2.drawKeypoints(gray,kp,img)

cv2.imwrite('sift_keypoints.jpg',img)
cv2.imshow('window',img)
cv2.waitKey(10000)
cv2.destroyAllWindows()

the erreor displayed is :

File "sift.py", line 10
    print 'The list of detected keypoints is:' pts.pt
    ^
SyntaxError: invalid syntax

as you can see im getting a syntax error, any corrections in the code then please do tell .

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-06-17 04:00:57 -0600

berak gravatar image

there is both a python syntax error (a comma missing) and a conceptual one: you already extracted the pt members in the line above , so you have a simple list of 2d points (without .pt):

 print 'The list of detected keypoints is:',  pts, "and it has ", len(pts), "elements."
edit flag offensive delete link more

Comments

print 'The list of detected keypoints is:', pts, "and it has ", len(pts), "elements." there is still an error

sfredv gravatar imagesfredv ( 2018-06-17 04:05:26 -0600 )edit

ah, sorry, of. there is always more than one error ...

but instead of this:

pts = np.float([kp[idx].pt for idx in len(kp)]).reshape(-1, 1, 2)

(where on earth did you find that ?) make it a simple:

pts = [k.pt for k in kp]
print ('The list of detected keypoints is:', pts)

have a look at the tutorials, too !

berak gravatar imageberak ( 2018-06-17 04:32:09 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-06-17 02:53:17 -0600

Seen: 1,348 times

Last updated: Jun 17 '18