Skip to main content

draw_box

draw_box(img: np.ndarray, box: Union[Box, np.ndarray], color: _Color = (0, 255, 0), thickness: _Thickness = 2) -> np.ndarray

  • Description: Draws a bounding box on an image.

  • Parameters:

    • img (np.ndarray): The image to draw on, as a NumPy array.
    • box (Union[Box, np.ndarray]): The bounding box to draw, either as a Box object or a NumPy array in the format [x1, y1, x2, y2].
    • color (_Color): The color of the bounding box. Defaults to (0, 255, 0) (green).
    • thickness (_Thickness): The thickness of the box border. Defaults to 2.
  • Return Value:

    • np.ndarray: The image with the bounding box drawn.
  • Example:

    import capybara as cb

    img = cb.imread('lena.png')
    box = cb.Box([20, 20, 100, 100])
    box_img = cb.draw_box(img, box, color=(0, 255, 0), thickness=2)

    draw_box