imcropboxes
-
Description: Crop the input image using multiple provided bounding boxes.
-
Parameters:
- img (
np.ndarray
): Input image to be cropped. - boxes (
Union[Boxes, np.ndarray]
): Cropping boxes. Input can be a Boxes object customized by DocsaidKit, defined as List[Box], or a NumPy array with the same format. - use_pad (
bool
): Whether to use padding to handle areas outside the boundaries. If set to True, the outer regions will be padded with zeros. Default is False.
- img (
-
Returns:
- List[np.ndarray]: List of cropped images.
-
Example:
import docsaidkit as D
# 使用自定義 Box 物件
img = D.imread('lena.png')
box1 = D.Box([50, 50, 200, 200], box_mode='xyxy')
box2 = D.Box([50, 50, 100, 100], box_mode='xyxy')
boxes = D.Boxes([box1, box2])
cropped_imgs = D.imcropboxes(img, boxes, use_pad=True)
# Resize the cropped image to the original size for visualization
cropped_img = D.imresize(cropped_img, [img.shape[0], img.shape[1]])