:py:mod:`viam.media.video` ========================== .. py:module:: viam.media.video Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: viam.media.video.RawImage viam.media.video.CameraMimeType viam.media.video.ViamImage viam.media.video.NamedImage Attributes ~~~~~~~~~~ .. autoapisummary:: viam.media.video.LAZY_SUFFIX viam.media.video.LIBRARY_SUPPORTED_FORMATS .. py:data:: LAZY_SUFFIX :value: '+lazy' .. py:data:: LIBRARY_SUPPORTED_FORMATS .. py:class:: RawImage Bases: :py:obj:`NamedTuple` **DEPRECATED** Use ``ViamImage`` instead A raw bytes representation of an image. A RawImage should be returned instead of a PIL Image instance under one of the following conditions 1) The requested mime type has the LAZY_SUFFIX string appended to it 2) The requested mime type is not supported for decoding/encoding by Viam's Python SDK .. py:attribute:: data :type: bytes The raw data of the image .. py:attribute:: mime_type :type: str The mimetype of the image .. py:method:: close() Close the image and release resources. For RawImage, this is a noop. .. py:method:: bytes_to_depth_array() -> List[List[int]] 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 given an image that is not of MIME type `image/vnd.viam.dep`. :returns: The standard representation of the image. :rtype: List[List[int]] .. py:class:: CameraMimeType Bases: :py:obj:`str`, :py:obj:`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'. .. py:property:: with_lazy_suffix :type: str .. py:attribute:: VIAM_RGBA :value: 'image/vnd.viam.rgba' .. py:attribute:: VIAM_RAW_DEPTH :value: 'image/vnd.viam.dep' .. py:attribute:: JPEG :value: 'image/jpeg' .. py:attribute:: PNG :value: 'image/png' .. py:attribute:: PCD :value: 'pointcloud/pcd' .. py:attribute:: UNSUPPORTED :value: 'unsupported' .. py:method:: from_lazy(value: str) -> Tuple[typing_extensions.Self, bool] :classmethod: .. py:method:: encode_image(image: Union[PIL.Image.Image, RawImage]) -> bytes .. py:method:: is_supported(mime_type: str) -> bool :classmethod: Check if the provided mime_type is supported. :param mime_type: The mime_type to check :type mime_type: str :returns: Whether the mime_type is supported :rtype: bool .. py:method:: from_proto(format: viam.proto.component.camera.Format.ValueType) -> CameraMimeType :classmethod: Returns the mimetype from a proto enum. :param format: The mimetype in a proto enum. :type format: Format.ValueType :returns: The mimetype. :rtype: Self .. py:method:: to_proto() -> viam.proto.component.camera.Format.ValueType Returns the mimetype in a proto enum. :returns: The mimetype in a proto enum. :rtype: Format.ValueType .. py:class:: ViamImage(data: bytes, mime_type: CameraMimeType) A native implementation of an image. Provides the raw data and the mime type, as well as lazily loading and caching the PIL.Image representation. .. py:property:: data :type: bytes The raw bytes of the image .. py:property:: mime_type :type: CameraMimeType The mime type of the image .. py:property:: image :type: Optional[PIL.Image.Image] The PIL.Image representation of the image. If the mime type is not supported, this will be None. .. py:method:: close() Close the image and release resources. .. py:method:: bytes_to_depth_array() -> List[List[int]] 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 given an image that is not of MIME type `image/vnd.viam.dep`. :returns: The standard representation of the image. :rtype: List[List[int]] .. py:class:: NamedImage(name: str, data: bytes, mime_type: CameraMimeType) Bases: :py:obj:`ViamImage` An implementation of ViamImage that contains a name attribute. .. py:attribute:: name :type: str The name of the image .. py:method:: close() Close the image and release resources.