MCPcopy Create free account
hub / github.com/mindee/doctr / draw_boxes

Function draw_boxes

doctr/utils/visualization.py:354–375  ·  view source on GitHub ↗

Draw an array of relative straight boxes on an image Args: boxes: array of relative boxes, of shape (*, 4) image: np array, float32 or uint8 color: color to use for bounding box edges **kwargs: keyword arguments from `matplotlib.pyplot.plot`

(boxes: np.ndarray, image: np.ndarray, color: tuple[int, int, int] | None = None, **kwargs)

Source from the content-addressed store, hash-verified

352
353
354def draw_boxes(boxes: np.ndarray, image: np.ndarray, color: tuple[int, int, int] | None = None, **kwargs) -> None:
355 """Draw an array of relative straight boxes on an image
356
357 Args:
358 boxes: array of relative boxes, of shape (*, 4)
359 image: np array, float32 or uint8
360 color: color to use for bounding box edges
361 **kwargs: keyword arguments from `matplotlib.pyplot.plot`
362 """
363 h, w = image.shape[:2]
364 # Convert boxes to absolute coords
365 _boxes = deepcopy(boxes)
366 _boxes[:, [0, 2]] *= w
367 _boxes[:, [1, 3]] *= h
368 _boxes = _boxes.astype(np.int32)
369 for box in _boxes.tolist():
370 xmin, ymin, xmax, ymax = box
371 image = cv2.rectangle(
372 image, (xmin, ymin), (xmax, ymax), color=color if isinstance(color, tuple) else (0, 0, 255), thickness=2
373 )
374 plt.imshow(image)
375 plt.plot(**kwargs)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected