Python: OpenCV: SURF use cv2

30 10 2012

20121030

OS: Ubuntu 12.10

find feature descriptor by SURF
extract from http://stackoverflow.com/questions/10984313/opencv-2-4-1-computing-surf-descriptors-in-python and
http://docs.opencv.org/modules/nonfree/doc/feature_detection.html and
http://stackoverflow.com/questions/9131552/feature-detection-in-opencv-python-bindings

code

#
# feature descriptor by SURF use cv2
# enu
#
import cv2
filename = 'cappucinno2.jpg'
image = cv2.imread(filename, cv2.CV_LOAD_IMAGE_COLOR) #Load the image to grayscale color
# Convert them to grayscale
image_g =cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
surf = cv2.SURF(12000,2,3,1)
#keypoints, descriptors = surf.detect(image_g, None, useProvidedKeypoints = False)
keypoints, descriptors = surf.detect(image_g, None, useProvidedKeypoints = False)
descriptors = descriptors.reshape((-1,128))
print descriptors.shape, len(keypoints)
for i in keypoints:
  (x,y) = i.pt
  center = (int(x),int(y))
  size = int(i.size)
  cv2.circle(image,center, size, (0,0,255))
cv2.namedWindow('2.0 SURF by cv2', cv2.CV_WINDOW_AUTOSIZE)
cv2.imshow('2.0 SURF by cv2', image)
cv2.waitKey(0)

Image

compare with cv and cv2 (difference parameter setting)

Image


Actions

Information

2 responses

18 06 2013
iuliux

Are you sure `descriptors.reshape((-1,128))` is ok?
Because it seems to me that SURF descriptors have 64 integer values.

19 06 2013
enumap

i’m sure with that.
it work fine both Linux Ubuntu and Win7

.reshape is not for value of descriptors, it for re-arrange dimension of value descriptor array

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: