config.py
Go to the documentation of this file.
00001 
00002 import sys,os
00003 import math
00004 
00005 class Config:
00006     """
00007     Base config class. Largely inspired in bigimbaz.
00008     Must be able to return:
00009     - img filename
00010     - descriptor filename
00011     - detector/descriptor params
00012     - ...
00013     """
00014     
00015     def __init__(self):
00016         self.dbname=self.__class__.__name__[:-6]
00017 
00018         # detector/descriptor type and params:
00019         # [] 'lava'
00020         # [] 'opencv'
00021         # [] 'obsidian'
00022         # [] 'miko'
00023         # [] 'koen'
00024         self.det_prog='opencv'
00025         self.det_args=''
00026 
00027 
00028         # smalldesc type
00029         # [] BOF
00030         self.smalldesc_type='bof'
00031 
00032         # Pre-filter image
00033         # Used to restrict size and improve quality
00034         self.det_pre_filter=''
00035         self.det_pre_scale=None
00036 
00037         # Disk storage format for local descs
00038         # [] 'siftgeo'
00039         # [] 'geofvec'
00040         self.localdesc_format='siftgeo'
00041         
00042 
00043         # Disk storage format for smalldescs (it implies wether det params are also
00044         # saved):
00045         # [] 'fvecs'
00046         # [] 'opencv' (yaml.gz)
00047         # [] 'koen' ?
00048         # [] 'siftgeo'
00049         self.smalldesc_format='fvecs'
00050         
00051         # Cluster
00052         self.clusterfile=''
00053         self.nb_centroids=None #"Visual words" of the cluster
00054         self.descsize=None #Number of dimensions of the final descriptor (for SPM when available)
00055         self.ma_k=1 #for if I use multiple assignment in the furture, as of now, useless...
00056 
00057         # Use PCA compression (specifies filenameor None)
00058         self.pca = None
00059         
00060         ## The visual words part is not (also) implemented here (as opposed to the bigimbaz case)
00061     
00062         # blocked bofs
00063         self.block_size=1000
00064     
00065     # for pcl descriptors
00066         self.use_pcd = False
00067 
00068     # Find image and desc files
00069     def smalldesc_filename(self,n):
00070         pass
00071     def desc_filename(self,n):
00072         pass
00073     def img_filename(self,n):
00074         pass
00075     def vw_filename(self,n):
00076         pass
00077     def pcd_filename(self,n): #for pcl computers
00078         pass
00079     def gt_bbox(self, n, iclass):
00080         pass
00081     def thumb_filename(self,n):
00082         #no thumbnail by default
00083         return None
00084         
00085 
00086     #working with smalldescs in blocks
00087     def smalldesc_block_filename(self,n):
00088         pass
00089     def block_to_imno(self,b):
00090         n=b*self.block_size
00091         if n>self.nimg:
00092             return self.nimg
00093         else:
00094             return n
00095     def imno_to_block(self,n):
00096         if n>self.nimg:
00097             n=self.nimg
00098         b=math.floor(n/self.block_size)
00099         
00100     ## may be useful
00101     def display_name(self,n):
00102         return self.img_filename(n).split('/')[-1]
00103         
00104     def set_default_compute_descriptors(self):
00105         self.det_prog='miko'
00106         self.det_args="-hesaff -thres 500 -sift"
00107         #tbi
00108         #self.det_pre_filter=(
00109         #    'djpeg "%s" | ppmtopgm | '+
00110         #    'pnmnorm -bpercent=0.01 -wpercent=0.01 -maxexpand=400 |'+
00111         #    'pamscale -pixels $[1024*768] > "%s"')
00112         #self.det_pre_scale=('maxpix',1024*768)    
00113             
00114 ### select_config (taken from bigimbaz)            
00115 def select_config(dbname):
00116   """
00117   returns a config object from a configuration name. The name can be
00118   either:
00119   - XXXX gives classname XXXXConfig which must be defined in
00120   this file
00121   - YYYY:XXXX loads XXXXConfig from imported module YYYY. To
00122   subclass the Config clas in module YYYY, import config
00123   - YYYY.py:XXXX is expanded as XXXXConfig class defined in file
00124   YYYY.py. Nothing special is needed to access the Config class: it is
00125   passed with the module name
00126   """
00127   if not dbname:
00128     sys.stderr.write("weird dbname %s\n"%dbname)
00129     sys.exit(1)
00130 
00131   if "(" in dbname and dbname[-1]==")":
00132     ba=dbname.index("(")
00133     dbsuff=dbname[ba:]
00134     dbargs=[eval(a) for a in dbname[ba+1:-1].split(',')]
00135     dbname=dbname[:ba]
00136   else:
00137     dbargs=()
00138     dbsuff=""
00139 
00140   if not dbname.endswith('Config'):
00141     dbname+="Config"
00142 
00143   if ':' not in dbname:
00144     try:
00145       # build config class and convert to object (=constructor)                                                                                              
00146       configclass=globals()[dbname]
00147     except KeyError:
00148       raise RuntimeError("unknown config %s\n"%dbname)
00149   else:
00150     colon=dbname.index(':')
00151     filename=dbname[:colon]
00152     classname=dbname[colon+1:]
00153     if '.' not in filename:
00154       if not filename.startswith('config_'): filename='config_'+filename
00155       # load from this directory                                                                                                                             
00156       locs={}
00157       mod=__import__(filename,globals(),locs)
00158       configclass=getattr(mod,classname)
00159     else:
00160       # load from arbitrary file                                                                                                                             
00161       globs=globals()
00162       execfile(filename,globs,globs)
00163       configclass=globs[classname]
00164 
00165   c=configclass(*dbargs)
00166   c.dbname=c.__class__.__name__[:-6]+dbsuff
00167 
00168   return c
00169     


iri_bow_object_detector
Author(s): dmartinez
autogenerated on Fri Dec 6 2013 22:45:45