Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RSDK-7565, RSDK-7471: add new methods to vision service get_properties and capture_all_from_camera #615

Conversation

bhaney
Copy link
Member

@bhaney bhaney commented May 14, 2024

This adds two new methods the python SDK vision service

  • GetProperties
  • CaptureAllFromCamera

The mock vision service and tests were updated for these methods as well.

Copy link
Contributor

Warning your change may break code samples. If your change modifies any of the following functions please contact @viamrobotics/fleet-management. Thanks!

component function
base is_moving
board gpio_pin_by_name
camera get_image
encoder get_position
motor is_moving
sensor get_readings
servo get_position
arm get_end_position
gantry get_lengths
gripper is_moving
movement_sensor get_linear_acceleration
input_controller get_controls
audio get_properties
pose_tracker get_poses
power_sensor get_power
motion get_pose
vision get_classifications_from_camera

try:
fmt = result.image.mime_type.to_proto()
img_bytes = result.image.data
img = Image(source_name=request.name, format=fmt, image=img_bytes)
Copy link
Member Author

@bhaney bhaney May 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this Image is the viam.proto.component.camera.Image class, not a PIL image

CaptureAllFromCamera method. This is used most often for visualization purposes, since normally,
returning the image on every call to a classifier/detector/etc would be costly and unnecessary.
"""
def __init__(self, image=None, classifications=None, detections=None, objects=None, extra={}):
Copy link
Member Author

@bhaney bhaney May 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I set the default results to None rather than the empty list to distinguish between "there was no request for classifier to return a result" vs. "the classifier was requested, but there were no results" (I've put this explanation in the doc string as well)

@bhaney bhaney marked this pull request as ready for review May 15, 2024 18:50
@bhaney bhaney requested a review from a team as a code owner May 15, 2024 18:50
@bhaney bhaney changed the title RSDK-7565: add new methods to vision service get_properties and _capture_all_from_camera RSDK-7565, RSDK-7471: add new methods to vision service get_properties and _capture_all_from_camera May 15, 2024
@bhaney bhaney changed the title RSDK-7565, RSDK-7471: add new methods to vision service get_properties and _capture_all_from_camera RSDK-7565, RSDK-7471: add new methods to vision service get_properties and capture_all_from_camera May 15, 2024
Copy link
Member

@stuqdog stuqdog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good to me! I am unconvinced we need the CaptureAllRequest type, but open to being talked into it :)

src/viam/services/vision/client.py Show resolved Hide resolved
Comment on lines +20 to +46
class CaptureAllRequest:
"""
CaptureAllRequest represents the collection of fields you can ask the
CaptureAllFromCamera method to return. If you request something that the service
cannot provide, a warning message will be generated, and the service will return an empty
version of the requested thing.
"""
def __init__(self, return_image=False, return_classifications=False,
return_detections=False, return_object_point_clouds=False):
"""
Args:
return_image (bool): Return the image from the GetImage of the underlying camera.
Default is False.
return_classifications (bool): Return the classifications from GetClassifications.
Default is False.
return_detections (bool): Return the detections from GetDetections.
Default is False.
return_objet_point_clouds (bool): Return the point cloud objects from GetObjectPointClouds.
Default is False.

Returns:
None
"""
self.return_image: bool = return_image
self.return_classifications: bool = return_classifications
self.return_detections: bool = return_detections
self.return_object_point_clouds: bool = return_object_point_clouds
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not convinced this is necessary or particularly helpful. This is only being used for a single call (CaptureAllFromCamera) so we could just put these params and defaults on the capture_all_from_camera method. And that way, a user doesn't have to look in multiple places to understand what their options are or why they matter.

Copy link
Member Author

@bhaney bhaney May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly this is for future changes to the method and to ensure backwards compatability. Given that it is Capture"All", what "All" may mean may change in the future.

Let's say we add 2D segmentation as a vision service method. Then CaptureAll should be able to return it, too. But then it would be a breaking change to the method.

Actually, saying that outloud, python is nice in that you can assign defaults to arguments. So, if a future vision method was added, then the argument list could be extended then without breaking previous versions of the modules, because by default, the extra argument would be assigned a default value

Copy link
Member Author

@bhaney bhaney May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Essentially -- I was attempting to find a way to make it so there would not have to be a breaking change to the CaptureAll method if for some reason a method was added to the vision service in the future. If this is a futile task and creating a Request class doesn't prevent a breaking change from happening, I'm willing to get rid of the class

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, I don't think we need to have this class

Copy link
Member

@njooma njooma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for making you do this, but could you base these changes off the rc-0.21.0 branch? That branch has changes that will affect this PR, and I don't want anyone to have to do this work twice, or go through a nasty rebase

Comment on lines +20 to +46
class CaptureAllRequest:
"""
CaptureAllRequest represents the collection of fields you can ask the
CaptureAllFromCamera method to return. If you request something that the service
cannot provide, a warning message will be generated, and the service will return an empty
version of the requested thing.
"""
def __init__(self, return_image=False, return_classifications=False,
return_detections=False, return_object_point_clouds=False):
"""
Args:
return_image (bool): Return the image from the GetImage of the underlying camera.
Default is False.
return_classifications (bool): Return the classifications from GetClassifications.
Default is False.
return_detections (bool): Return the detections from GetDetections.
Default is False.
return_objet_point_clouds (bool): Return the point cloud objects from GetObjectPointClouds.
Default is False.

Returns:
None
"""
self.return_image: bool = return_image
self.return_classifications: bool = return_classifications
self.return_detections: bool = return_detections
self.return_object_point_clouds: bool = return_object_point_clouds
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, I don't think we need to have this class

@purplenicole730 purplenicole730 removed their request for review May 16, 2024 17:15
@bhaney
Copy link
Member Author

bhaney commented May 16, 2024

Closing this PR and opening the other one, based on rc-0.21.0

@bhaney bhaney closed this May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants