Path: blob/master/video-editor/utils.py
641 views
import cv21import numpy as np234def draw_bounding_box_on_image(5image, ymin, xmin, ymax, xmax, display_str, color=(255, 234, 32), thickness=46):7(left, right, top, bottom) = (xmin, xmax, ymin, ymax)8pts = np.array(9[[left, top], [left, bottom], [right, bottom], [right, top]], np.int3210)11pts = pts.reshape((-1, 1, 2))12cv2.polylines(image, [pts], True, color, thickness)13font = cv2.FONT_HERSHEY_SIMPLEX14font_scale = 0.715thickness_text = 216text_size, baseline = cv2.getTextSize(display_str, font, font_scale, thickness_text)17text_width, text_height = text_size18margin = np.ceil(0.2 * text_height)19thickness_fill = -120start_point = (int(left - margin), int(top - text_height - 2 * margin))21end_point = (int(left + text_width + 2 * margin), int(top))2223cv2.rectangle(image, start_point, end_point, color, thickness_fill)2425org = (int(left + margin), int(top - text_height + 3 * margin))26cv2.putText(27image,28display_str,29org,30font,31font_scale,32(255, 255, 255),33thickness_text,34cv2.LINE_AA,35)363738