| import cv2 | |
| import numpy as np | |
| def draw_bbox(image,box,color=(255,0,0),thickness=1): | |
| if thickness==0: | |
| return | |
| left = int(box[0]) | |
| top = int(box[1]) | |
| right = int(box[0]+box[2]) | |
| bottom = int(box[1]+box[3]) | |
| box_points =[(left,top),(right,top),(right,bottom),(left,bottom)] | |
| cv2.polylines(image, [np.array(box_points)], isClosed=True, color=color, thickness=thickness) | |
| def to_int_points(points): | |
| int_points=[] | |
| for point in points: | |
| int_points.append([int(point[0]),int(point[1])]) | |
| return int_points | |
| def draw_text(img, text, point, font_scale=0.5, color=(200, 200, 200), thickness=1): | |
| font = cv2.FONT_HERSHEY_SIMPLEX | |
| cv2.putText(img, str(text), point, font, font_scale, color, thickness, cv2.LINE_AA) | |
| plot_text_color = (200, 200, 200) | |
| plot_text_font_scale = 0.5 | |
| plot_index = 1 | |
| plot_text = True | |
| def set_plot_text(is_plot,text_font_scale,text_color): | |
| global plot_index,plot_text,plot_text_font_scale,plot_text_color | |
| plot_text = is_plot | |
| plot_index = 1 | |
| plot_text_font_scale = text_font_scale | |
| plot_text_color = text_color | |
| def plot_points(image,points,isClosed=False,circle_size=3,circle_color=(255,0,0),line_size=1,line_color=(0,0,255)): | |
| global plot_index,plot_text | |
| int_points = to_int_points(points) | |
| if circle_size>0: | |
| for point in int_points: | |
| cv2.circle(image,point,circle_size,circle_color,-1) | |
| if plot_text: | |
| draw_text(image,plot_index,point,plot_text_font_scale,plot_text_color) | |
| plot_index+=1 | |
| if line_size>0: | |
| cv2.polylines(image, [np.array(int_points)], isClosed=isClosed, color=line_color, thickness=line_size) |