1
# -*- coding: utf-8 -*-
4
from pycvf.core import genericnode
8
r=I[max(int(x[1]-L),0):int(x[1]+L),
9
max(int(x[0]-L),0):int(x[0]+L),:]
13
class SpecificKeypoint(object):
15
This class allows you to combine a keypoint extractor
16
with a keypoint descriptor.
18
Of course exploded may have been used that for, but sometimes things need to be made easier and simpler
20
Two modes are supported :
21
The mode "c" will pass a couple made out of the image and of the coordinates of the keypoints.
22
The mode "b" where a block will be cropped at the keypoint position and this block will be passed to the model
23
in mode"b" the half-size of the block is defined by keypointhalfsize
27
TODO : this maybe improved so that the element of the dataflow actually enters the dataflow
29
def __init__(self,keypointmodel, descriptormodel,mode="c",as_couple=True,keypointhalfsize=(10,10)):
30
self.keypointmodel=keypointmodel
31
self.descriptormodel=descriptormodel
34
self.keypointhalfsize=keypointhalfsize
35
def set_model_node(self,model):
37
self.db=self.model_node.get_curdb()
39
self.keypointmodel=(pycvf_builder(self.keypointmodel) if type(self.keypointmodel) in [str,unicode] else self.keypointmodel)
40
self.keypointmodel.init("/",self.db,self)
41
keypointmodelpath=self.keypointmodel.resolve_modelpath(0)
42
metak= self.keypointmodel.get_features_meta().keys()
43
self.keypointmodel.metainfo_curdb=self.db
44
self.keypointmodelpathno=metak.index(keypointmodelpath)
46
self.descriptormodel=(pycvf_builder(self.descriptormodel) if type(self.descriptormodel) in [str,unicode] else self.descriptormodel)
47
self.descriptormodel.init("/",self.db,self)
48
descriptormodelpath=self.descriptormodel.resolve_modelpath(0)
49
metak= self.descriptormodel.get_features_meta().keys()
50
self.descriptormodel.metainfo_curdb=self.db
51
self.descriptormodelpathno=metak.index(descriptormodelpath)
53
def on_model_destroy(self,model):
56
kp=self.keypointmodel.process(x,addr=self.model_node.get_curaddr())[self.keypointmodelpathno]
59
kp=filter(lambda k:(k[0]>=self.keypointhalfsize[0]) and (k[0]<(x.shape[1]-self.keypointhalfsize[0])) and (k[1]>self.keypointhalfsize[1]) and (k[1]<(x.shape[0]-self.keypointhalfsize[1])),kp)
60
desc=[self.descriptormodel.process(getpatch(x,p))[self.descriptormodelpathno] for p in kp]
62
desc=self.descriptormodel.process((x,kp))[self.descriptormodelpathno]
64
raise ValueError, "Invalid Mode"
68
return numpy.hstack([kp,desc])
70
Node=genericnode.pycvf_node_class(None,None)(SpecificKeypoint)
b'\\ No newline at end of file'