def draw_box( out_img: np.ndarray, box: Box, labels: Iterable[Tuple[str, Point]], color: Color = Color.red(), line_thickness: int = 2, ) -> np.ndarray: cv.rectangle( img=out_img, pt1=box.top_left, pt2=box.bottom_right, color=color.to_bgr(), thickness=line_thickness, ) for text, translation in labels: text_loc: Point = translate_point( Point(box.top_left_x, box.bottom_right_y), translation) cv.putText( img=out_img, text=text, org=text_loc, fontFace=cv.FONT_HERSHEY_SIMPLEX, fontScale=0.5, color=Color.orange().to_bgr(), thickness=2, ) return out_img
def write_boxes( out_path: str, out_img: np.ndarray, boxes: Iterable[Box], labelss: Iterable[Iterable[Tuple[str, Point]]] = tuple(), color: Color = Color.red(), line_thickness: int = 2, ): for box, labels in zip_longest(boxes, labelss): draw_box(out_img, box, labels, color, line_thickness) cv.imwrite(filename=out_path, img=out_img)