Skip to content

Commit e980e58

Browse files
committed
Fix: handling png images.
1 parent 8441ca1 commit e980e58

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

object_detection_app/app.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,29 +144,25 @@ def encode_image(image):
144144

145145

146146
def detect_objects(image_path):
147-
image = Image.open(image_path)
147+
image = Image.open(image_path).convert('RGB')
148148
boxes, scores, classes, num_detections = client.detect(image)
149+
image.thumbnail((480, 480), Image.ANTIALIAS)
149150

150151
new_images = {}
151152
for i in range(num_detections):
152153
if scores[i] < 0.7: continue
153154
cls = classes[i]
154155
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()
159157
draw_bounding_box_on_image(new_images[cls], boxes[i],
160158
thickness=int(scores[i]*10)-4)
161159

162160
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())
166162

167-
for cls, image in new_images.iteritems():
163+
for cls, new_image in new_images.iteritems():
168164
category = client.category_index[cls]['name']
169-
result[category] = encode_image(image)
165+
result[category] = encode_image(new_image)
170166

171167
return result
172168

0 commit comments

Comments
 (0)