def render_bounding_box(comma_delimited_rect: str, plot: plt): """ Helper method to render bounding box around the detected word """ box_coordinates = comma_delimited_rect.strip().split(',') x = int(box_coordinates[0].strip()) y = int(box_coordinates[1].strip()) width = int(box_coordinates[2].strip()) height = int(box_coordinates[3].strip()) bottom_left = [x, y] bottom_right = [x + width, y] top_left = [x, y + height] top_right = [x + width, y + height] points = [bottom_left, top_left, top_right, bottom_right, bottom_left] polygon = plt.Polygon(points, fill=None, edgecolor='xkcd:rusty red', closed=False) plot.gca().add_line(polygon)
def render_word(comma_delimited_rect: str, word: str, plot: plt): """ Helper method to render the word above the bounding box """ coordinates_array = comma_delimited_rect.strip().split(',') x = int(coordinates_array[0].strip()) y = int(coordinates_array[1].strip()) plot.gca().text(x, y - 10, word, fontsize=8, color='xkcd:rusty red')