import numpy as np

from object_detection import CornerNet_Saccade
from util import image_util


def capture_target_area(image, target="book"):
    detector = CornerNet_Saccade()
    bboxes = detector(image)
    target_images = []
    keep_inds = bboxes[target][:, -1] > 0.5
    for bbox in bboxes[target][keep_inds]:
        bbox = bbox[0:4].astype(np.int32)
        bbox = np.clip(bbox, 0, None)
        target_images.append(image_util.capture(image, bbox))
    return target_images
