crop_observation#
- rapidtools.processing.reid.crop_observation(image: Image, polygon: Sequence[tuple[float, float]], buffer: float = 0.15) Image[source]#
Cut the axis-aligned crop of a detection polygon out of its source image.
The polygon’s bounding box is expanded by
buffertimes its width and height on each side and clamped to the image. In an equirectangular panorama (width twice the height) a polygon that wraps around the seam is handled by rolling the image half a turn first, so the crop stays contiguous.- Parameters:
image – Source image (thumbnail or full frame).
polygon – Detection outline in normalised image coordinates,
xright andydown in[0, 1].buffer – Context margin as a fraction of the box size.
- Returns:
PIL.Image.Image – The crop; at least one pixel in each direction.
Example
>>> from PIL import Image >>> image = Image.new('RGB', (200, 100)) >>> box = [(0.4, 0.5), (0.5, 0.5), (0.5, 0.7), (0.4, 0.7)] >>> crop_observation(image, box, buffer=0.0).size (20, 20)