Ask Your Question
0

How to find the co-ordinates of keypoints in python?

asked 2014-06-12 05:39:45 -0600

lolbylol gravatar image

Hello,

I am programming in python with OpenCV 2.4.5. My program is as follows:

fast = cv2.FastFeatureDetector()
kp = fast.detect(crop)
img2 = cv2.drawKeypoints(crop, kp, color=(255,0,0))
print kp

Now I would like to find the X and Y co-ordinates from 'kp'. The type of kp is list and the value which is directly printed is '[< KeyPoint 04ACDBD8>]'. Can you please help me finding the co-ordinates.

Thank you.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-06-12 08:33:47 -0600

Guanta gravatar image

updated 2014-06-12 10:59:56 -0600

You get a list of Keypoint-instances from a feature-detector. To access the points, you can use the pt-attribute, for example kp[0].pt would be the first point, where kp[0].pt[0] is the x coordinate and kp[0].pt[1] the y-coordinate of that point.

Example:

im =  cv2.imread('example.jpg', cv2.CV_LOAD_IMAGE_GRAYSCALE)
fast = cv2.FastFeatureDetector()
kpts = fast.detect(im)
print kpts[0].pt
(336.0, 13.0)
edit flag offensive delete link more

Comments

I tried this method but it didn't worked.It comes that pt is not recognised. Do I have to use it with another command? like cv2.keypoint as cv2.Keypoint is also unrecognised.

lolbylol gravatar imagelolbylol ( 2014-06-12 09:01:27 -0600 )edit

It works for me (using OpenCV 2.4.8), you can check the attributes of a keypoint with dir(kpts[0]), for me pt is one attribute.

Guanta gravatar imageGuanta ( 2014-06-12 11:10:59 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2014-06-12 05:39:45 -0600

Seen: 8,877 times

Last updated: Jun 12 '14