@@ -144,29 +144,25 @@ def encode_image(image):
144
144
145
145
146
146
def detect_objects (image_path ):
147
- image = Image .open (image_path )
147
+ image = Image .open (image_path ). convert ( 'RGB' )
148
148
boxes , scores , classes , num_detections = client .detect (image )
149
+ image .thumbnail ((480 , 480 ), Image .ANTIALIAS )
149
150
150
151
new_images = {}
151
152
for i in range (num_detections ):
152
153
if scores [i ] < 0.7 : continue
153
154
cls = classes [i ]
154
155
if cls not in new_images .keys ():
155
- image = Image .open (image_path )
156
- image .thumbnail ((480 , 480 ), Image .ANTIALIAS )
157
- new_images [cls ] = image
158
-
156
+ new_images [cls ] = image .copy ()
159
157
draw_bounding_box_on_image (new_images [cls ], boxes [i ],
160
158
thickness = int (scores [i ]* 10 )- 4 )
161
159
162
160
result = {}
163
- image = Image .open (image_path )
164
- image .thumbnail ((480 , 480 ), Image .ANTIALIAS )
165
- result ['original' ] = encode_image (image )
161
+ result ['original' ] = encode_image (image .copy ())
166
162
167
- for cls , image in new_images .iteritems ():
163
+ for cls , new_image in new_images .iteritems ():
168
164
category = client .category_index [cls ]['name' ]
169
- result [category ] = encode_image (image )
165
+ result [category ] = encode_image (new_image )
170
166
171
167
return result
172
168
0 commit comments