def detect_image(self, image):
    start = timer()
    new_image_size = self.model_image_size
    boxed_image = letterbox_image(image, new_image_size)
    image_data = np.array(boxed_image, dtype='float32')
    image_data /= 255.0
    image_data = np.expand_dims(image_data, 0)
    (out_boxes, out_scores, out_classes) = self.sess.run([self.boxes, self.scores, self.classes], feed_dict={self.yolo_model.input: image_data, self.input_image_shape: [image.size[1], image.size[0]], K.learning_phase(): 0})
    print('Found {} boxes for {}'.format(len(out_boxes), 'img'))
    font = ImageFont.truetype(font='font/simhei.ttf', size=np.floor(((0.03 * image.size[1]) + 0.5)).astype('int32'))
    thickness = ((image.size[0] + image.size[1]) // 300)
    small_pic = []
    for (i, c) in list(enumerate(out_classes)):
        predicted_class = self.class_names[c]
        box = out_boxes[i]
        score = out_scores[i]
        (top, left, bottom, right) = box
        top = (top - 5)
        left = (left - 5)
        bottom = (bottom + 5)
        right = (right + 5)
        top = max(0, np.floor((top + 0.5)).astype('int32'))
        left = max(0, np.floor((left + 0.5)).astype('int32'))
        bottom = min(image.size[1], np.floor((bottom + 0.5)).astype('int32'))
        right = min(image.size[0], np.floor((right + 0.5)).astype('int32'))
        label = '{} {:.2f}'.format(predicted_class, score)
        draw = ImageDraw.Draw(image)
        label_size = draw.textsize(label, font)
        label = label.encode('utf-8')
        print(label)
        if ((top - label_size[1]) >= 0):
            text_origin = np.array([left, (top - label_size[1])])
        else:
            text_origin = np.array([left, (top + 1)])
        for i in range(thickness):
            draw.rectangle([(left + i), (top + i), (right - i), (bottom - i)], outline=self.colors[c])
        draw.rectangle([tuple(text_origin), tuple((text_origin + label_size))], fill=self.colors[c])
        draw.text(text_origin, str(label, 'UTF-8'), fill=(0, 0, 0), font=font)
        del draw
    end = timer()
    print((end - start))
    return image
def detect_image(self, image):
    start = timer()
    new_image_size = self.model_image_size
    boxed_image = letterbox_image(image, new_image_size)
    image_data = np.array(boxed_image, dtype='float32')
    image_data /= 255.0
    image_data = np.expand_dims(image_data, 0)
    (out_boxes, out_scores, out_classes) = self.sess.run([self.boxes, self.scores, self.classes], feed_dict={self.yolo_model.input: image_data, self.input_image_shape: [image.size[1], image.size[0]], K.learning_phase(): 0})
    print('Found {} boxes for {}'.format(len(out_boxes), 'img'))
    font = ImageFont.truetype(font='font/simhei.ttf', size=np.floor(((0.03 * image.size[1]) + 0.5)).astype('int32'))
    thickness = ((image.size[0] + image.size[1]) // 300)
    small_pic = []
    for (i, c) in list(enumerate(out_classes)):
        predicted_class = self.class_names[c]
        box = out_boxes[i]
        score = out_scores[i]
        (top, left, bottom, right) = box
        top = (top - 5)
        left = (left - 5)
        bottom = (bottom + 5)
        right = (right + 5)
        top = max(0, np.floor((top + 0.5)).astype('int32'))
        left = max(0, np.floor((left + 0.5)).astype('int32'))
        bottom = min(image.size[1], np.floor((bottom + 0.5)).astype('int32'))
        right = min(image.size[0], np.floor((right + 0.5)).astype('int32'))
        label = '{} {:.2f}'.format(predicted_class, score)
        draw = ImageDraw.Draw(image)
        label_size = draw.textsize(label, font)
        label = label.encode('utf-8')
        print(label)
        if ((top - label_size[1]) >= 0):
            text_origin = np.array([left, (top - label_size[1])])
        else:
            text_origin = np.array([left, (top + 1)])
        for i in range(thickness):
            draw.rectangle([(left + i), (top + i), (right - i), (bottom - i)], outline=self.colors[c])
        draw.rectangle([tuple(text_origin), tuple((text_origin + label_size))], fill=self.colors[c])
        draw.text(text_origin, str(label, 'UTF-8'), fill=(0, 0, 0), font=font)
        del draw
    end = timer()
    print((end - start))
    return image