Draw a rectangle on an image. Args: image: numpy array of shape (H, W, 3), the image to draw on bbox: tuple of (x_min, y_min, x_max, y_max) or list [x_min, y_min, x_max, y_max] color: tuple of (B, G, R), the color of the rectangle thickness: int, thickne
(image, bbox, color=(0, 255, 0), thickness=2)
| 4 | # draw rectangle in an image |
| 5 | |
| 6 | def draw_rectangle(image, bbox, color=(0, 255, 0), thickness=2): |
| 7 | """ |
| 8 | Draw a rectangle on an image. |
| 9 | |
| 10 | Args: |
| 11 | image: numpy array of shape (H, W, 3), the image to draw on |
| 12 | bbox: tuple of (x_min, y_min, x_max, y_max) or list [x_min, y_min, x_max, y_max] |
| 13 | color: tuple of (B, G, R), the color of the rectangle |
| 14 | thickness: int, thickness of the rectangle lines |
| 15 | |
| 16 | Returns: |
| 17 | numpy array: the image with rectangle drawn |
| 18 | """ |
| 19 | x_min, y_min, x_max, y_max = [int(coord) for coord in bbox] |
| 20 | cv2.rectangle(image, (x_min, y_min), (x_max, y_max), color, thickness) |
| 21 | return image |
| 22 | |
| 23 | def draw_rectangles(image, bboxes, colors=None, thickness=2): |
| 24 | """ |
no outgoing calls
no test coverage detected