viam.media.utils.pil

Submodules

Attributes

RGBA_FORMAT_LABEL

LIBRARY_SUPPORTED_FORMATS

Classes

CameraMimeType

str(object='') -> str

ViamImage

A native implementation of an image.

Functions

viam_to_pil_image(→ PIL.Image.Image)

Convert a ViamImage to a PIL.Image.

pil_to_viam_image(→ viam.media.video.ViamImage)

Convert a PIL.Image to a ViamImage.

Package Contents

class viam.media.utils.pil.CameraMimeType[source]

Bases: str, enum.Enum

str(object=’’) -> str str(bytes_or_buffer[, encoding[, errors]]) -> str

Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.__str__() (if defined) or repr(object). encoding defaults to sys.getdefaultencoding(). errors defaults to ‘strict’.

VIAM_RGBA = 'image/vnd.viam.rgba'
VIAM_RAW_DEPTH = 'image/vnd.viam.dep'
JPEG = 'image/jpeg'
PNG = 'image/png'
PCD = 'pointcloud/pcd'
classmethod from_string(value: str) typing_extensions.Self[source]

Return the mimetype from a string.

Parameters:

value (str) – The mimetype as a string

Returns:

The mimetype

Return type:

Self

classmethod from_proto(format: viam.proto.component.camera.Format.ValueType) CameraMimeType[source]

Returns the mimetype from a proto enum.

Parameters:

format (Format.ValueType) – The mimetype in a proto enum.

Returns:

The mimetype.

Return type:

Self

to_proto() viam.proto.component.camera.Format.ValueType[source]

Returns the mimetype in a proto enum.

Returns:

The mimetype in a proto enum.

Return type:

Format.ValueType

class viam.media.utils.pil.ViamImage(data: bytes, mime_type: CameraMimeType)[source]

A native implementation of an image.

Provides the raw data and the mime type.

property data: bytes

The raw bytes of the image

property mime_type: CameraMimeType

The mime type of the image

property width: int | None

The width of the image

property height: int | None

The height of the image

bytes_to_depth_array() List[List[int]][source]

Decode the data of an image that has the custom depth MIME type image/vnd.viam.dep into a standard representation.

Raises:

NotSupportedError – Raised if the image is not of MIME type image/vnd.viam.dep.

Returns:

The standard representation of the image.

Return type:

List[List[int]]

viam.media.utils.pil.RGBA_FORMAT_LABEL = 'VIAM_RGBA'
viam.media.utils.pil.LIBRARY_SUPPORTED_FORMATS
viam.media.utils.pil.viam_to_pil_image(image: viam.media.video.ViamImage) PIL.Image.Image[source]

Convert a ViamImage to a PIL.Image.

In order to use this function, Pillow must be installed. https://python-pillow.org/

Parameters:

image (ViamImage) – The image to convert.

Returns:

The resulting PIL.Image

Return type:

Image.Image

viam.media.utils.pil.pil_to_viam_image(image: PIL.Image.Image, mime_type: viam.media.video.CameraMimeType) viam.media.video.ViamImage[source]

Convert a PIL.Image to a ViamImage.

In order to use this function, Pillow must be installed. https://python-pillow.org/

Parameters:
  • image (Image.Image) – The image to convert.

  • mime_type (CameraMimeType) – The mime type to convert the image to.

Returns:

The resulting ViamImage

Return type:

ViamImage