Draws the rectangle around the object borrowed from: https://bbox-visualizer.readthedocs.io/en/latest/_modules/bbox_visualizer/bbox_visualizer.html Parameters ---------- img : ndarray the actual image bbox : list a list containing x_min, y_min, x_max and y_max of
(img,
bbox,
bbox_color=(255, 255, 255),
thickness=3,
is_opaque=False,
alpha=0.5)
| 608 | |
| 609 | # ---------------------------------- visualization |
| 610 | def draw_rectangle(img, |
| 611 | bbox, |
| 612 | bbox_color=(255, 255, 255), |
| 613 | thickness=3, |
| 614 | is_opaque=False, |
| 615 | alpha=0.5): |
| 616 | """Draws the rectangle around the object |
| 617 | borrowed from: https://bbox-visualizer.readthedocs.io/en/latest/_modules/bbox_visualizer/bbox_visualizer.html |
| 618 | Parameters |
| 619 | ---------- |
| 620 | img : ndarray |
| 621 | the actual image |
| 622 | bbox : list |
| 623 | a list containing x_min, y_min, x_max and y_max of the rectangle positions |
| 624 | bbox_color : tuple, optional |
| 625 | the color of the box, by default (255,255,255) |
| 626 | thickness : int, optional |
| 627 | thickness of the outline of the box, by default 3 |
| 628 | is_opaque : bool, optional |
| 629 | if False, draws a solid rectangular outline. Else, a filled rectangle which is semi transparent, by default False |
| 630 | alpha : float, optional |
| 631 | strength of the opacity, by default 0.5 |
| 632 | |
| 633 | Returns |
| 634 | ------- |
| 635 | ndarray |
| 636 | the image with the bounding box drawn |
| 637 | """ |
| 638 | |
| 639 | output = img.copy() |
| 640 | if not is_opaque: |
| 641 | cv2.rectangle(output, (bbox[0], bbox[1]), (bbox[2], bbox[3]), |
| 642 | bbox_color, thickness) |
| 643 | else: |
| 644 | overlay = img.copy() |
| 645 | |
| 646 | cv2.rectangle(overlay, (bbox[0], bbox[1]), (bbox[2], bbox[3]), |
| 647 | bbox_color, -1) |
| 648 | # cv2.addWeighted(overlay, alpha, output, 1 - alpha, 0, output) |
| 649 | |
| 650 | return output |
| 651 | |
| 652 | def plot_bbox(image, bbox): |
| 653 | ''' Draw bbox |
nothing calls this directly
no outgoing calls
no test coverage detected