Package pyvision :: Package point :: Module DetectorSURF
[hide private]
[frames] | no frames]

Source Code for Module pyvision.point.DetectorSURF

 1  ''' 
 2  Created on Apr 16, 2009 
 3   
 4  @author: bolme 
 5  ''' 
 6  from pyvision.point.DetectorROI import DetectorROI 
 7  #import pyvision as pv 
 8  #from scipy import weave 
 9  import cv 
10   
11 -def ExtractSURF(im,min_hessian=300):
12 ''' 13 Uses OpenCV to extract SURF keypoints. Currently does not compute SURF features. 14 15 TODO: An option should be added to also compute and return the SURF descriptors. 16 TODO: This should be extended with options for octaves and levels. 17 TODO: I believe there are no memory leaks but this should be checked. cvSURFParams? 18 ''' 19 cvim= im.asOpenCVBW() 20 #mat = int(cvim.this) 21 min_hessian = float(min_hessian) 22 #TODO: OpenCV python interface now includes cv.ExtractSURF(cvim, mask, storage, params) 23 #This is my (Steve's) attempt at this, but I am concerned we're not returning the 24 # some of the information once this gets back to the caller...perhaps the parent 25 # class is filtering out the addtnl data that SURF points provide? 26 27 #TODO: Now that we have the descriptors, we need to return them to user if desired. 28 (keypts, _) = cv.ExtractSURF(cvim, None, cv.CreateMemStorage(), (0, min_hessian, 3, 1)) 29 30 keypoints = list() 31 for ((x, y), laplacian, size, direction, hessian) in keypts: 32 keypoints.append((hessian,x,y,size,direction,laplacian) ) 33 34 return keypoints
35 # keypoints = weave.inline( 36 # ''' 37 # CvMat* im = (CvMat*)mat; 38 # 39 # CvMemStorage* storage = cvCreateMemStorage(); 40 # CvSeq* keypoints = cvCreateSeq(0,sizeof(CvSeq),sizeof(CvSURFPoint),storage); 41 # cvExtractSURF(im,NULL,&keypoints,NULL,storage,cvSURFParams(min_hessian)); 42 # 43 # 44 # int n = keypoints->total; 45 # PyObject* list = PyList_New(n); 46 # CvSURFPoint pt; 47 # for(int i = 0 ; i < n; i++){ 48 # cvSeqPop(keypoints,&pt); 49 # 50 # PyObject* tuple = PyTuple_New(5); 51 # PyTuple_SetItem(tuple, 1, PyFloat_FromDouble(pt.pt.x)); 52 # PyTuple_SetItem(tuple, 2, PyFloat_FromDouble(pt.pt.y)); 53 # PyTuple_SetItem(tuple, 3, PyInt_FromLong(pt.size)); 54 # PyTuple_SetItem(tuple, 4, PyFloat_FromDouble(pt.dir)); 55 # PyTuple_SetItem(tuple, 0, PyFloat_FromDouble(pt.hessian)); 56 # 57 # PyList_SetItem(list,i,tuple); 58 # //printf("%5d %10.5f %10.5f %5d %10.5f %10.5f\\n", i, pt.pt.x, pt.pt.y, pt.size, pt.dir, pt.hessian); 59 # 60 # 61 # cvClearMemStorage(storage); 62 # cvReleaseMemStorage(&storage); 63 # 64 # return_val = list; 65 # ''', 66 # arg_names=['mat','min_hessian'], 67 # include_dirs=['/usr/local/include'], 68 # headers=['<opencv/cv.h>'], 69 # library_dirs=['/usr/local/lib'], 70 # libraries=['cv'] 71 # ) 72 73 #return keypoints 74 75
76 -class DetectorSURF(DetectorROI):
77 - def __init__(self, min_hessian=400.0, **kwargs):
78 ''' 79 ''' 80 self.min_hessian = min_hessian 81 DetectorROI.__init__(self,**kwargs)
82 83
84 - def _detect(self,im):
85 keypoints = ExtractSURF(im,min_hessian=self.min_hessian) 86 keypoints.sort(lambda x,y: -cmp(x[0],y[0])) 87 return keypoints
88