Implement an efficient algorithm to crop, scale, and align visual bounding boxes or video frame sequences for dataset preprocessing.
Implement crop_scale_boxes(frame_boxes, crop, target_size). frame_boxes is a list of frames, where each frame contains boxes [x1, y1, x2, y2] in source-image coordinates. crop is [left, top, right, bottom], and target_size is [width, height]. Intersect every box with the crop, translate it to crop-relative coordinates, scale it to the target size, and discard boxes with zero visible area. Preserve frame order and box order.
Return a list of frames containing transformed boxes. Coordinates may be floating-point values.
def crop_scale_boxes(frame_boxes, crop, target_size):