Advertisement
Guest User

Untitled

a guest
Mar 31st, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. from handler.handler import Handler
  2. from utils import visualization_utils as vis_util
  3. import numpy as np
  4. import cv2
  5. import PIL.Image as Image
  6.  
  7.  
  8. class DisplayHandler(Handler):
  9.  
  10.     def __init__(self, category_index):
  11.         self.category_index = category_index
  12.  
  13.     def handle(self, frame, boxes, scores, classes, num):
  14.         img = frame.image.copy()
  15.         boxes = np.squeeze(boxes)
  16.         scores = np.squeeze(scores)
  17.         classes = np.squeeze(classes).astype(np.int32)
  18.         for i in range(len(boxes)):
  19.             if scores[i] < 0.6:
  20.                 continue;
  21.             ymin, xmin, ymax, xmax = boxes[i]
  22.             im_width, im_height = Image.fromarray(np.uint8(img)).convert('RGB').size
  23.             (left, right, top, bottom) = (int(xmin * im_width), int(xmax * im_width),
  24.                                           int(ymin * im_height), int(ymax * im_height))
  25.             cv2.rectangle(img, (left, top), (right, bottom), (36,255,12), 2)
  26.             #cv2.putText(img, self.category_index[classes[i]]["name"], (left - 10, top - 10), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 0, 0), 2, cv2.LINE_AA)
  27.        
  28.         #vis_util.visualize_boxes_and_labels_on_image_array(
  29.         #   img,
  30.         #   boxes,
  31.         #   classes,
  32.         #   scores,
  33.         #   self.category_index,
  34.         #   use_normalized_coordinates=True,
  35.         #   line_thickness=8,
  36.         #   min_score_thresh=0.60)
  37.  
  38.         cv2.imshow('Object detector', img)
  39.         super().handle(frame, boxes, scores, classes, num)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement