def calculate_feature(bin_data):
"""
calculate the feature data of an image
parameter :
'bin_data' is the binary stream format of an image
return value :
a tuple of ( keypoints, descriptors, (height,width) )
keypoints is like [ pt1, pt2, pt3, ... ]
descriptors is a numpy array
"""
buff=numpy.frombuffer(bin_data,numpy.uint8)
img_obj=cv2.imdecode(buff,cv2.CV_LOAD_IMAGE_GRAYSCALE)
surf=cv2.FeatureDetector_create("SURF")
surf.setInt("hessianThreshold",400)
surf_extractor=cv2.DescriptorExtractor_create("SURF")
keypoints=surf.detect(img_obj,None)
keypoints,descriptors=surf_extractor.compute(img_obj,keypoints)
res_keypoints=[]
for point in keypoints:
res_keypoints.append(point.pt)
del buff
del surf
del surf_extractor
del keypoints
return res_keypoints,numpy.array(descriptors),img_obj.shape
评论列表
文章目录