Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "viam-sdk"
version = "0.4.4"
version = "0.4.5"
description = "Viam Robotics Python SDK"
authors = [ "Naveed <naveed@viam.com>" ]
license = "Apache-2.0"
Expand Down
4 changes: 2 additions & 2 deletions src/viam/components/camera/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
def get_image_from_response(data: bytes, response_mime_type: str, request_mime_type: Optional[str] = None) -> Union[Image.Image, RawImage]:
if request_mime_type is None:
request_mime_type = response_mime_type
_, is_lazy = CameraMimeType.from_lazy(request_mime_type)
if is_lazy or not (CameraMimeType.is_supported(response_mime_type)):
mime_type, is_lazy = CameraMimeType.from_lazy(request_mime_type)
if is_lazy or mime_type._should_be_raw:
image = RawImage(data=data, mime_type=response_mime_type)
return image
return Image.open(BytesIO(data), formats=LIBRARY_SUPPORTED_FORMATS)
Expand Down
13 changes: 11 additions & 2 deletions src/viam/media/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from io import BytesIO
from typing import List, NamedTuple, Optional, Tuple, Union

from PIL import Image
from PIL import Image, UnidentifiedImageError
from typing_extensions import Self

from viam.errors import NotSupportedError
Expand Down Expand Up @@ -94,6 +94,12 @@ def encode_image(self, image: Union[Image.Image, RawImage]) -> bytes:
else:
raise ValueError(f"Cannot encode image to {self}")

@property
def _should_be_raw(self) -> bool:
return self in [CameraMimeType.UNSUPPORTED, CameraMimeType.PCD, CameraMimeType.VIAM_RAW_DEPTH] or not CameraMimeType.is_supported(
self
)

@classmethod
def is_supported(cls, mime_type: str) -> bool:
"""Check if the provided mime_type is supported.
Expand Down Expand Up @@ -185,7 +191,10 @@ def image(self) -> Optional[Image.Image]:
self._image_decoded = True
return self._image

self._image = Image.open(BytesIO(self.data), formats=LIBRARY_SUPPORTED_FORMATS)
try:
self._image = Image.open(BytesIO(self.data), formats=LIBRARY_SUPPORTED_FORMATS)
except UnidentifiedImageError:
self._image = None
self._image_decoded = True
return self._image

Expand Down