@@ -74,6 +74,9 @@ def __init__(self,color_conf = None):
74
74
else :
75
75
self .color_conf = color_conf
76
76
77
+ FontData = os .path .join (os .path .dirname (os .path .realpath (__file__ )), "OpenSans-Regular.ttf" )
78
+ self .font = ImageFont .truetype (FontData , self .color_conf .default_font_size )
79
+
77
80
def setBBXs (self , bboxs = None , names = None ):
78
81
self .bbxs = []
79
82
for i , bbox in enumerate (bboxs ):
@@ -117,18 +120,32 @@ def drawOneBox(self, bbx, thr=-1.0, showName=False):
117
120
self .draw .line (line1 , fill = fill_color ,width = self .color_conf .line_width )
118
121
119
122
if bbx .name == None or showName == False :
120
- font = ImageFont .truetype ("OpenSans-Regular.ttf" , self .color_conf .default_font_size )
121
-
122
- self .draw .text ((x + self .color_conf .line_width , y ), str (bbx .score ), fill = fill_color , font = font )
123
+ self .draw .text ((x + self .color_conf .line_width , y ), str (bbx .score ), fill = fill_color , font = self .font )
123
124
else :
124
- font = ImageFont .truetype ("OpenSans-Regular.ttf" , self .color_conf .default_font_size )
125
- self .draw .text ((x + self .color_conf .line_width , y ), bbx .name + ' ' + str (bbx .score ), fill = fill_color , font = font )
125
+ self .draw .text ((x + self .color_conf .line_width , y ), bbx .name + ' ' + str (bbx .score ), fill = fill_color , font = self .font )
126
+
127
+ def drawOneBoxTrue (self , bbx , showName = False ):
128
+ x = bbx .x
129
+ y = bbx .y
130
+ w = bbx .w
131
+ h = bbx .h
132
+ line1 = ((x , y ), (x + w , y ), (x + w , y + h ), (x , y + h ), (x , y ))
133
+ fill_color = self .color_conf .get_color (bbx .name )
134
+ self .draw .line (line1 , fill = fill_color ,width = self .color_conf .line_width )
135
+ if bbx .name == None or showName == False :
136
+ self .draw .text ((x + self .color_conf .line_width , y ), 'True' , fill = fill_color , font = self .font )
137
+ else :
138
+ self .draw .text ((x + self .color_conf .line_width , y ), bbx .name + '_True' , fill = fill_color , font = self .font )
126
139
127
- def drawBox (self , thr = - 1.0 , showName = False ):
140
+ def drawBox (self , thr = - 1.0 , showName = True , show_true = True ):
128
141
self .draw = ImageDraw .Draw (self .img )
129
142
for bbx in self .bbxs :
130
143
self .drawOneBox (bbx , thr , showName )
131
144
145
+ if show_true and hasattr (self ,'bbxs_true' ):
146
+ for bbx in self .bbxs_true :
147
+ self .drawOneBoxTrue (bbx , showName )
148
+
132
149
def read_img (self , fileName ):
133
150
self .img = Image .open (fileName ).convert ('RGB' )
134
151
@@ -149,11 +166,11 @@ def read_ano_true(self, fileName):
149
166
150
167
f = open (fileName , 'r' )
151
168
lines = f .readlines ()
152
- self .bbxs = []
169
+ self .bbxs_true = []
153
170
for line in lines [:]:
154
171
nbbx = BBX ()
155
172
nbbx .str2bbx_true (line )
156
- self .bbxs .append (nbbx )
173
+ self .bbxs_true .append (nbbx )
157
174
158
175
def resizeBBXs (self , r , x_d , y_d ):
159
176
for bbx in self .bbxs :
@@ -187,7 +204,8 @@ def resize(self, width, height, scale=1.0):
187
204
188
205
imgNew .paste (region , (self .x_d , self .y_d ))
189
206
self .img = imgNew
190
- self .resizeBBXs (re_ration , self .x_d , self .y_d )
207
+ if hasattr (self ,'bbxs' ):
208
+ self .resizeBBXs (re_ration , self .x_d , self .y_d )
191
209
# self.drawBox()
192
210
193
211
def cleanAno (self , w0 , h0 ):
@@ -210,7 +228,8 @@ def save_img(self, imgName):
210
228
def pureResize (self , width , height ):
211
229
re_ration = float (width )/ self .img .size [0 ]
212
230
self .img = self .img .resize ((width , height ), Image .ANTIALIAS )
213
- self .resizeBBXs (re_ration , 0 , 0 )
231
+ if hasattr (self ,'bbxs' ):
232
+ self .resizeBBXs (re_ration , 0 , 0 )
214
233
215
234
def flip (self , width ):
216
235
self .img = self .img .transpose (Image .FLIP_LEFT_RIGHT )
0 commit comments