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
00019
00020
00021
00022
00023
00024 self.det_prog='opencv'
00025 self.det_args=''
00026
00027
00028
00029
00030 self.smalldesc_type='bof'
00031
00032
00033
00034 self.det_pre_filter=''
00035 self.det_pre_scale=None
00036
00037
00038
00039
00040 self.localdesc_format='siftgeo'
00041
00042
00043
00044
00045
00046
00047
00048
00049 self.smalldesc_format='fvecs'
00050
00051
00052 self.clusterfile=''
00053 self.nb_centroids=None
00054 self.descsize=None
00055 self.ma_k=1
00056
00057
00058 self.pca = None
00059
00060
00061
00062
00063 self.block_size=1000
00064
00065
00066 self.use_pcd = False
00067
00068
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):
00078 pass
00079 def gt_bbox(self, n, iclass):
00080 pass
00081 def thumb_filename(self,n):
00082
00083 return None
00084
00085
00086
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
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
00108
00109
00110
00111
00112
00113
00114
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
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
00156 locs={}
00157 mod=__import__(filename,globals(),locs)
00158 configclass=getattr(mod,classname)
00159 else:
00160
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