From d9bd30f281523fa79df36d4d76d42dffa7bd8f7f Mon Sep 17 00:00:00 2001 From: Bijan Haney Date: Tue, 21 May 2024 14:45:32 -0400 Subject: [PATCH 1/2] removes PIL, adds two new methods --- requirements.txt | 2 +- src/verificationclassifier.py | 52 +++++++++++++++++++++++++++++------ 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/requirements.txt b/requirements.txt index 84fc64b..4937b07 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -viam-sdk >= 0.5.1 +viam-sdk >= 0.21.0 pillow diff --git a/src/verificationclassifier.py b/src/verificationclassifier.py index 4e4fa0c..a221a3c 100755 --- a/src/verificationclassifier.py +++ b/src/verificationclassifier.py @@ -3,18 +3,16 @@ from enum import Enum -from PIL import Image - -from viam.media.video import RawImage +from viam.media.video import ViamImage from viam.module.types import Reconfigurable from viam.proto.app.robot import ComponentConfig -from viam.proto.service.vision import Classification -from viam.proto.common import ResourceName +from viam.proto.service.vision import Classification, Detection +from viam.proto.common import ResourceName, PointCloudObject from viam.resource.base import ResourceBase from viam.resource.types import Model, ModelFamily -from viam.services.vision import Vision +from viam.services.vision import Vision, CaptureAllResult from viam.components.camera import Camera @@ -162,6 +160,44 @@ async def do_command(self): async def get_object_point_clouds(self): return + async def get_properties( + self, + *, + extra: Optional[Mapping[str, Any]] = None, + timeout: Optional[float] = None) -> Vision.Properties: + return Vision.Properties( + classifications_supported=True, + detections_supported=False, + object_point_clouds_supported=False, + ) + + async def capture_all_from_camera( + self, + camera_name: str, + return_image: bool = False, + return_classifications: bool = False, + return_detections: bool = False, + return_object_point_clouds: bool = False, + *, + extra: Optional[Mapping[str, Any]] = None, + timeout: Optional[float] = None, + ) -> CaptureAllResult: + result = CaptureAllResult() + if camera_name != self.camera_name: + raise Exception( + f"camera {camera_name} was not declared in the camera_name dependency") + cam_image = await self.camera.get_image(mime_type="image/jpeg") + if return_image: + result.image = cam_image + if return_classifications: + cls = await self.get_classifications(cam_image, 1) + result.classifications = cls + if return_detections: + result.detections = [] + if return_object_point_clouds: + result.objects = [] + return result + async def get_classifications_from_camera(self, camera_name: str, count: int, @@ -177,7 +213,7 @@ async def get_classifications_from_camera(self, return await self.get_classifications(cam_image, 1) async def get_classifications(self, - image: Union[Image.Image, RawImage], + image: ViamImage, count: int, *, extra: Optional[Dict[str, Any]] = None, @@ -199,7 +235,7 @@ async def get_classifications(self, classifications = [{"class_name": class_name, "confidence": 1.0}] return classifications - async def process_image(self, image: Union[Image.Image, RawImage]): + async def process_image(self, image: ViamImage): if self.alarm_state is AlarmState.TRIGGER_1: if self.trigger_1_detector is None: self.alarm_state = AlarmState.TRIGGER_2 # go straight to trigger 2 From 1f6a2e90b04ba7def85d303226fcc01904643032 Mon Sep 17 00:00:00 2001 From: Bijan Haney Date: Tue, 21 May 2024 16:14:06 -0400 Subject: [PATCH 2/2] remove unneeded imports --- src/verificationclassifier.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/verificationclassifier.py b/src/verificationclassifier.py index a221a3c..982a056 100755 --- a/src/verificationclassifier.py +++ b/src/verificationclassifier.py @@ -7,8 +7,8 @@ from viam.module.types import Reconfigurable from viam.proto.app.robot import ComponentConfig -from viam.proto.service.vision import Classification, Detection -from viam.proto.common import ResourceName, PointCloudObject +from viam.proto.service.vision import Classification +from viam.proto.common import ResourceName from viam.resource.base import ResourceBase from viam.resource.types import Model, ModelFamily