1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 import os
35 import pyvision as pv
36 from pyvision.analysis.FaceAnalysis.FaceDetectionTest import is_success
37
39 '''
40 Reads and manages the data in an eye coordinate file.
41 '''
42
44 '''
45 Inits and reads in the data.
46 '''
47 self.filename = filename
48 self.images = {}
49
50 self._readEyesFile()
51
53 '''
54 Returns the list of file names.
55 '''
56 names = self.images.keys()
57 names.sort()
58 return names
59
61 fname = self._parseName(filename)
62 if self.images.has_key(fname):
63 faces = self.images[fname]
64 for each in faces:
65 truth_rect = each[3]
66 if is_success(truth_rect,rect):
67 return each
68 return None
69
71 fname = self._parseName(filename)
72 if self.images.has_key(fname):
73 faces = self.images[fname]
74 boxes = []
75 for _,_,_,box in faces:
76 boxes.append(box)
77 return boxes
78 return []
79
81 fname = self._parseName(filename)
82 if self.images.has_key(fname):
83 faces = self.images[fname]
84 eyes = []
85 for _,left,right,_ in faces:
86 eyes.append([left,right])
87 return eyes
88 return []
89
91 '''
92 Private: Do not call directly. Reads the eye file.
93 '''
94 if self.filename[-4:] == '.csv':
95 f = open(self.filename,'r')
96 for line in f:
97
98 line = line.split(',')
99 fname = self._parseName(line[0])
100 eye1 = pv.Point(float(line[1]),float(line[2]))
101 eye2 = pv.Point(float(line[3]),float(line[4]))
102
103 truth_rect = pv.BoundingRect(eye1,eye2)
104 truth_rect.w = 2.0 * truth_rect.w
105 truth_rect.h = truth_rect.w
106 truth_rect.x = truth_rect.x - 0.25*truth_rect.w
107 truth_rect.y = truth_rect.y - 0.3*truth_rect.w
108
109
110
111 if not self.images.has_key(fname):
112 self.images[fname] = []
113
114 self.images[fname].append([fname,eye1,eye2,truth_rect])
115
116 else:
117 f = open(self.filename,'r')
118 for line in f:
119
120 line = line.split()
121 fname = self._parseName(line[0])
122 eye1 = pv.Point(float(line[1]),float(line[2]))
123 eye2 = pv.Point(float(line[3]),float(line[4]))
124
125 truth_rect = pv.BoundingRect(eye1,eye2)
126 truth_rect.w = 2.0 * truth_rect.w
127 truth_rect.h = truth_rect.w
128 truth_rect.x = truth_rect.x - 0.25*truth_rect.w
129 truth_rect.y = truth_rect.y - 0.3*truth_rect.w
130
131
132
133 if not self.images.has_key(fname):
134 self.images[fname] = []
135
136 self.images[fname].append([fname,eye1,eye2,truth_rect])
137
139 '''
140 Private: Do not call directly. Parses the base filename.
141 '''
142 fname = os.path.basename(fname)
143 fname = os.path.splitext(fname)[0]
144 return fname
145
146
148
150 - def __init__(self,filename,subject_id,image_id):
151 self.filename = filename
152 self.subject_id = subject_id
153 self.image_id = image_id
154
156 '''Process a Subject Replicate Table file'''
157 self.images = []
158 self.filenames = {}
159
160 f = open(filename,'r')
161
162 subject_id = 0
163 image_id = 0
164 filename = None
165 for line in f:
166 images = line.split()
167 if images:
168 for image in images:
169 name = image.split('.')[0]
170 image_id += 1
171 print name, image_id, subject_id
172 ir = CSU_SRT.ImageRecord(name,subject_id,image_id)
173 self.images.append(ir)
174 self.filenames[name] = ir
175 subject_id += 1
176
177 self.total_subjects = subject_id
178 self.total_images = image_id
179
181 tmp = self.filenames.keys()
182 tmp.sort()
183 return tmp;
184
186 if self.filenames.has_key(name):
187 return self.filenames[name]
188
189 return None
190
191
193 - def __init__(self,directory,srt,extention='.sfi'):
194
195 self.matrix = {}
196 self.srt = srt
197
198 count = 0
199 for iname in srt.getNames():
200 self.matrix[iname] = {}
201 filename = directory+'/'+iname+extention
202 print "Reading:",iname
203 f = open(filename,'r')
204 for line in f:
205 jname,dist = line.split()
206 jname = jname.split('.')[0]
207 if srt.getRecord(jname):
208 self.matrix[iname][jname] = -float(dist)
209 count += 1
210 print "Read:",count
211
212
214 names = self.srt.getNames()
215 pos = []
216 neg = []
217 for i in range(len(names)):
218 for j in range(i+1,len(names)):
219 iname = names[i]
220 jname = names[j]
221 if self.srt.getRecord(iname).subject_id == self.srt.getRecord(jname).subject_id:
222 pos.append(self.matrix[iname][jname])
223 else:
224 neg.append(self.matrix[iname][jname])
225 return pos,neg
226
227
228
229
230 if __name__ == "__main__":
231 srt = CSU_SRT("/Users/bolme/vision/csuFaceIdBenchmark/imagelists/list640.srt")
232 ebgm_dist = CSU_Dist("/Users/bolme/vision/csuFaceIdBenchmark/distances/feret/EBGM",srt)
233 pca_dist = CSU_Dist("/Users/bolme/vision/csuFaceIdBenchmark/distances/feret/PCA_Euclidean",srt)
234 ebgm_pos, ebgm_neg = ebgm_dist.getPosNeg()
235 pca_pos, pca_neg = pca_dist.getPosNeg()
236
237 from pyvis.analysis.roc import *
238 ebgm_roc = pv.ROC(ebgm_pos,ebgm_neg)
239 pca_roc = pv.ROC(pca_pos,pca_neg)
240