Skip to content

Commit 6206fb8

Browse files
committed
TypeAlias Camera.Properties (#502)
1 parent 9708793 commit 6206fb8

File tree

8 files changed

+21
-31
lines changed

8 files changed

+21
-31
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ clean:
22
find . -type d -name '__pycache__' | xargs rm -rf
33

44
_lint:
5-
flake8 --exclude=**/gen/**,*_grpc.py,*_pb2.py,*_pb2.pyi,.tox
5+
flake8 --exclude=**/gen/**,*_grpc.py,*_pb2.py,*_pb2.pyi,.tox,**/venv/**
66

77
lint:
88
poetry run $(MAKE) _lint

src/viam/components/camera/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from viam.media.video import RawImage
1+
from viam.media.video import RawImage, ViamImage
22
from viam.proto.component.camera import DistortionParameters, IntrinsicParameters
33
from viam.resource.registry import Registry, ResourceRegistration
44

@@ -11,6 +11,7 @@
1111
"IntrinsicParameters",
1212
"DistortionParameters",
1313
"RawImage",
14+
"ViamImage",
1415
]
1516

1617
Registry.register_subtype(

src/viam/components/camera/camera.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
import abc
2-
from typing import Any, Dict, Final, List, NamedTuple, Optional, Tuple, Union
2+
from typing import TYPE_CHECKING, Any, Dict, Final, List, Optional, Tuple, Union
33

44
from PIL.Image import Image
55

66
from viam.media.video import NamedImage
77
from viam.proto.common import ResponseMetadata
8+
from viam.proto.component.camera import GetPropertiesResponse
89
from viam.resource.types import RESOURCE_NAMESPACE_RDK, RESOURCE_TYPE_COMPONENT, Subtype
910

1011
from ..component_base import ComponentBase
11-
from . import DistortionParameters, IntrinsicParameters, RawImage
12+
from . import RawImage
13+
14+
if TYPE_CHECKING:
15+
from typing import TypeAlias
1216

1317

1418
class Camera(ComponentBase):
@@ -22,17 +26,7 @@ class Camera(ComponentBase):
2226

2327
SUBTYPE: Final = Subtype(RESOURCE_NAMESPACE_RDK, RESOURCE_TYPE_COMPONENT, "camera")
2428

25-
class Properties(NamedTuple):
26-
"""The camera's supported features and settings"""
27-
28-
supports_pcd: bool
29-
"""Whether the camera has a valid implementation of ``get_point_cloud``"""
30-
31-
intrinsic_parameters: IntrinsicParameters
32-
"""The properties of the camera"""
33-
34-
distortion_parameters: DistortionParameters
35-
"""The distortion parameters of the camera"""
29+
Properties: "TypeAlias" = GetPropertiesResponse
3630

3731
@abc.abstractmethod
3832
async def get_image(
@@ -41,7 +35,7 @@ async def get_image(
4135
"""Get the next image from the camera as an Image or RawImage.
4236
Be sure to close the image when finished.
4337
44-
NOTE: If the mime type is ``image/vnd.viam.dep`` you can use :func:`viam.media.video.RawImage.bytes_to_depth_array`
38+
NOTE: If the mime type is ``image/vnd.viam.dep`` you can use :func:`viam.media.video.ViamImage.bytes_to_depth_array`
4539
to convert the data to a standard representation.
4640
4741
Args:

src/viam/components/camera/client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
GetPointCloudRequest,
1616
GetPointCloudResponse,
1717
GetPropertiesRequest,
18-
GetPropertiesResponse,
1918
)
2019
from viam.resource.rpc_client_base import ReconfigurableResourceRPCClientBase
2120
from viam.utils import ValueTypes, dict_to_struct, get_geometries, struct_to_dict
@@ -71,8 +70,7 @@ async def get_point_cloud(self, *, extra: Optional[Dict[str, Any]] = None, timeo
7170
return (response.point_cloud, response.mime_type)
7271

7372
async def get_properties(self, *, timeout: Optional[float] = None) -> Camera.Properties:
74-
response: GetPropertiesResponse = await self.client.GetProperties(GetPropertiesRequest(name=self.name), timeout=timeout)
75-
return Camera.Properties(response.supports_pcd, response.intrinsic_parameters, response.distortion_parameters)
73+
return await self.client.GetProperties(GetPropertiesRequest(name=self.name), timeout=timeout)
7674

7775
async def do_command(self, command: Mapping[str, ValueTypes], *, timeout: Optional[float] = None) -> Mapping[str, ValueTypes]:
7876
request = DoCommandRequest(name=self.name, command=dict_to_struct(command))

src/viam/components/types.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/viam/media/video.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818

1919

2020
class RawImage(NamedTuple):
21-
"""A raw bytes representation of an image.
21+
"""**DEPRECATED** Use ``ViamImage`` instead
22+
23+
A raw bytes representation of an image.
2224
2325
A RawImage should be returned instead of a PIL Image instance under one of
2426
the following conditions

tests/mocks/components.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,9 @@ def __init__(self, name: str):
398398
self.point_cloud = b"THIS IS A POINT CLOUD"
399399
self.extra = None
400400
self.props = Camera.Properties(
401-
False,
402-
IntrinsicParameters(width_px=1, height_px=2, focal_x_px=3, focal_y_px=4, center_x_px=5, center_y_px=6),
403-
DistortionParameters(model="no_distortion"),
401+
supports_pcd=False,
402+
intrinsic_parameters=IntrinsicParameters(width_px=1, height_px=2, focal_x_px=3, focal_y_px=4, center_x_px=5, center_y_px=6),
403+
distortion_parameters=DistortionParameters(model="no_distortion"),
404404
)
405405
self.timeout: Optional[float] = None
406406
ts = Timestamp()

tests/test_camera.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ def point_cloud() -> bytes:
6060
@pytest.fixture(scope="function")
6161
def properties() -> Camera.Properties:
6262
return Camera.Properties(
63-
False,
64-
IntrinsicParameters(width_px=1, height_px=2, focal_x_px=3, focal_y_px=4, center_x_px=5, center_y_px=6),
65-
DistortionParameters(model="no_distortion"),
63+
supports_pcd=False,
64+
intrinsic_parameters=IntrinsicParameters(width_px=1, height_px=2, focal_x_px=3, focal_y_px=4, center_x_px=5, center_y_px=6),
65+
distortion_parameters=DistortionParameters(model="no_distortion"),
6666
)
6767

6868

0 commit comments

Comments
 (0)