imcropboxes
-
Description: Crops the input image using multiple provided bounding boxes.
-
Parameters
- img (
np.ndarray
): The input image to crop. - boxes (
Union[Boxes, np.ndarray]
): The cropping boxes. The input can be a customBoxes
object from Capybara, defined as a list ofBox
objects, or a NumPy array with the same format. - use_pad (
bool
): Whether to use padding for out-of-bounds areas. If set to True, the outer regions will be padded with zeros. Default is False.
- img (
-
Returns
- List[np.ndarray]: A list of cropped images.
-
Example
import capybara as cb
# Using custom Box objects
img = cb.imread('lena.png')
box1 = cb.Box([50, 50, 200, 200], box_mode='xyxy')
box2 = cb.Box([50, 50, 100, 100], box_mode='xyxy')
boxes = cb.Boxes([box1, box2])
cropped_imgs = cb.imcropboxes(img, boxes, use_pad=True)
# Resize the cropped image to the original size for visualization
cropped_img = cb.imresize(cropped_img, [img.shape[0], img.shape[1]])