This API is deprecated: Instead try the PyCoral APIs.

Utilities to process your images before performing an inference.

edgetpu.utils.image_processing.resampling_with_original_ratio(img, required_size, sample)

Resizes the image to maintain the original aspect ratio by adding pixel padding where needed.

For example, if your model’s input tensor requires a square image but your image is landscape (and you don’t want to reshape the image to fit), pass this function your image and the required square dimensions, and it returns a square version by adding the necessary amount of black pixels on the bottom-side only. If the original image is portrait, it adds black pixels on the right-side only.

  • img (PIL.Image) – The image to resize.
  • required_size (list) – The pixel width and height [x, y] that your model requires for input.
  • sample (int) – A resampling filter for image resizing. This can be one of PIL.Image.NEAREST (recommended), PIL.Image.BOX, PIL.Image.BILINEAR, PIL.Image.HAMMING, PIL.Image.BICUBIC, or PIL.Image.LANCZOS. See Pillow filters.

A 2-tuple with a PIL.Image object for the resized image, and a tuple of floats representing the aspect ratio difference between the original image and the returned image (x delta-ratio, y delta-ratio).