viam.services.vision
Submodules
Package Contents
Classes
the general form of the output from a classifier |
|
Abstract base class for protocol messages. |
|
Connect to the Vision service, which allows you to access various computer vision algorithms |
|
Vision represents a Vision service. |
- class viam.services.vision.Classification(*, class_name: str = ..., confidence: float = ...)
Bases:
google.protobuf.message.Message
the general form of the output from a classifier
- class_name: str
the class name
- confidence: float
the confidence score of the classification
- class viam.services.vision.Detection(*, x_min: int | None = ..., y_min: int | None = ..., x_max: int | None = ..., y_max: int | None = ..., confidence: float = ..., class_name: str = ...)
Bases:
google.protobuf.message.Message
Abstract base class for protocol messages.
Protocol message classes are almost always generated by the protocol compiler. These generated types subclass Message and implement the methods shown below.
- x_min: int
the four corners of the box
- y_min: int
- x_max: int
- y_max: int
- confidence: float
the confidence of the detection
- class_name: str
label associated with the detected object
- HasField(field_name: Literal[_x_max, b'_x_max', _x_min, b'_x_min', _y_max, b'_y_max', _y_min, b'_y_min', x_max, b'x_max', x_min, b'x_min', y_max, b'y_max', y_min, b'y_min']) bool
Checks if a certain field is set for the message.
For a oneof group, checks if any field inside is set. Note that if the field_name is not defined in the message descriptor,
ValueError
will be raised.- Parameters:
field_name (str) – The name of the field to check for presence.
- Returns:
Whether a value has been set for the named field.
- Return type:
bool
- Raises:
ValueError – if the field_name is not a member of this message.
- WhichOneof(oneof_group: Literal[_x_max, b'_x_max']) Literal[x_max] | None
- WhichOneof(oneof_group: Literal[_x_min, b'_x_min']) Literal[x_min] | None
- WhichOneof(oneof_group: Literal[_y_max, b'_y_max']) Literal[y_max] | None
- WhichOneof(oneof_group: Literal[_y_min, b'_y_min']) Literal[y_min] | None
Returns the name of the field that is set inside a oneof group.
If no field is set, returns None.
- Parameters:
oneof_group (str) – the name of the oneof group to check.
- Returns:
The name of the group that is set, or None.
- Return type:
str or None
- Raises:
ValueError – no group with the given name exists
- class viam.services.vision.VisionClient(name: str, channel: grpclib.client.Channel)[source]
Bases:
viam.services.vision.vision.Vision
,viam.resource.rpc_client_base.ReconfigurableResourceRPCClientBase
Connect to the Vision service, which allows you to access various computer vision algorithms (like detection, segmentation, tracking, etc) that usually only require a camera or image input.
- async get_detections_from_camera(camera_name: str, *, extra: Optional[Mapping[str, Any]] = None, timeout: Optional[float] = None) List[viam.proto.service.vision.Detection] [source]
Get a list of detections in the next image given a camera and a detector
- Parameters:
camera_name (str) – The name of the camera to use for detection
- Returns:
A list of 2D bounding boxes, their labels, and the confidence score of the labels, around the found objects in the next 2D image from the given camera, with the given detector applied to it.
- Return type:
- async get_detections(image: Union[viam.media.viam_rgba_plugin.Image.Image, viam.media.video.RawImage], *, extra: Optional[Mapping[str, Any]] = None, timeout: Optional[float] = None) List[viam.proto.service.vision.Detection] [source]
Get a list of detections in the given image using the specified detector
- Parameters:
image (Image) – The image to get detections from
- Returns:
A list of 2D bounding boxes, their labels, and the confidence score of the labels, around the found objects in the next 2D image from the given camera, with the given detector applied to it.
- Return type:
- async get_classifications_from_camera(camera_name: str, count: int, *, extra: Optional[Mapping[str, Any]] = None, timeout: Optional[float] = None) List[viam.proto.service.vision.Classification] [source]
Get a list of classifications in the next image given a camera and a classifier
- Parameters:
camera_name (str) – The name of the camera to use for detection
count (int) – The number of classifications desired
- Returns:
The list of Classifications
- Return type:
- async get_classifications(image: Union[viam.media.viam_rgba_plugin.Image.Image, viam.media.video.RawImage], count: int, *, extra: Optional[Mapping[str, Any]] = None, timeout: Optional[float] = None) List[viam.proto.service.vision.Classification] [source]
Get a list of classifications in the given image using the specified classifier
- Parameters:
image (Image) – The image to get detections from
count (int) – The number of classifications desired
- Returns:
The list of Classifications
- Return type:
- async get_object_point_clouds(camera_name: str, *, extra: Optional[Mapping[str, Any]] = None, timeout: Optional[float] = None) List[viam.proto.common.PointCloudObject] [source]
Returns a list of the 3D point cloud objects and associated metadata in the latest picture obtained from the specified 3D camera (using the specified segmenter).
To deserialize the returned information into a numpy array, use the Open3D library.
import numpy as np import open3d as o3d object_point_clouds = await vision.get_object_point_clouds(camera_name, segmenter_name) # write the first object point cloud into a temporary file with open("/tmp/pointcloud_data.pcd", "wb") as f: f.write(object_point_clouds[0].point_cloud) pcd = o3d.io.read_point_cloud("/tmp/pointcloud_data.pcd") points = np.asarray(pcd.points)
- Parameters:
camera_name (str) – The name of the camera
- Returns:
The pointcloud objects with metadata
- Return type:
- async do_command(command: Mapping[str, viam.utils.ValueTypes], *, timeout: Optional[float] = None) Mapping[str, viam.utils.ValueTypes] [source]
Send/receive arbitrary commands
- Parameters:
command (Dict[str, ValueTypes]) – The command to execute
- Returns:
Result of the executed command
- Return type:
Dict[str, ValueTypes]
- classmethod from_robot(robot: viam.robot.client.RobotClient, name: str) typing_extensions.Self
Get the service named
name
from the provided robot.- Parameters:
robot (RobotClient) – The robot
name (str) – The name of the service
- Returns:
The service, if it exists on the robot
- Return type:
Self
- classmethod get_resource_name(name: str) viam.proto.common.ResourceName
Get the ResourceName for this Resource with the given name
- Parameters:
name (str) – The name of the Resource
- get_operation(kwargs: Mapping[str, Any]) viam.operations.Operation
Get the
Operation
associated with the currently running function.When writing custom resources, you should get the
Operation
by calling this function and check to see if it’s cancelled. If theOperation
is cancelled, then you can perform any necessary (terminating long running tasks, cleaning up connections, etc. ).- Parameters:
kwargs (Mapping[str, Any]) – The kwargs object containing the operation
- Returns:
The operation associated with this function
- Return type:
- async close()
Safely shut down the resource and prevent further use.
Close must be idempotent. Later configuration may allow a resource to be “open” again. If a resource does not want or need a close function, it is assumed that the resource does not need to retun errors when future non-Close methods are called.
- class viam.services.vision.Vision(name: str)[source]
Bases:
viam.services.service_base.ServiceBase
,abc.ABC
Vision represents a Vision service.
This acts as an abstract base class for any drivers representing specific arm implementations. This cannot be used on its own. If the
__init__()
function is overridden, it must call thesuper().__init__()
function.- SUBTYPE: Final
- abstract async get_detections_from_camera(camera_name: str, *, extra: Optional[Mapping[str, Any]] = None, timeout: Optional[float] = None) List[viam.proto.service.vision.Detection] [source]
Get a list of detections in the next image given a camera and a detector
- Parameters:
camera_name (str) – The name of the camera to use for detection
- Returns:
A list of 2D bounding boxes, their labels, and the confidence score of the labels, around the found objects in the next 2D image from the given camera, with the given detector applied to it.
- Return type:
- abstract async get_detections(image: Union[PIL.Image.Image, viam.media.video.RawImage], *, extra: Optional[Mapping[str, Any]] = None, timeout: Optional[float] = None) List[viam.proto.service.vision.Detection] [source]
Get a list of detections in the given image using the specified detector
- Parameters:
image (Image) – The image to get detections from
- Returns:
A list of 2D bounding boxes, their labels, and the confidence score of the labels, around the found objects in the next 2D image from the given camera, with the given detector applied to it.
- Return type:
- abstract async get_classifications_from_camera(camera_name: str, count: int, *, extra: Optional[Mapping[str, Any]] = None, timeout: Optional[float] = None) List[viam.proto.service.vision.Classification] [source]
Get a list of classifications in the next image given a camera and a classifier
- Parameters:
camera_name (str) – The name of the camera to use for detection
count (int) – The number of classifications desired
- Returns:
The list of Classifications
- Return type:
- abstract async get_classifications(image: Union[PIL.Image.Image, viam.media.video.RawImage], count: int, *, extra: Optional[Mapping[str, Any]] = None, timeout: Optional[float] = None) List[viam.proto.service.vision.Classification] [source]
Get a list of classifications in the given image using the specified classifier
- Parameters:
image (Image) – The image to get detections from
count (int) – The number of classifications desired
- Returns:
The list of Classifications
- Return type:
- abstract async get_object_point_clouds(camera_name: str, *, extra: Optional[Mapping[str, Any]] = None, timeout: Optional[float] = None) List[viam.proto.common.PointCloudObject] [source]
Returns a list of the 3D point cloud objects and associated metadata in the latest picture obtained from the specified 3D camera (using the specified segmenter).
To deserialize the returned information into a numpy array, use the Open3D library.
import numpy as np import open3d as o3d object_point_clouds = await vision.get_object_point_clouds(camera_name, segmenter_name) # write the first object point cloud into a temporary file with open("/tmp/pointcloud_data.pcd", "wb") as f: f.write(object_point_clouds[0].point_cloud) pcd = o3d.io.read_point_cloud("/tmp/pointcloud_data.pcd") points = np.asarray(pcd.points)
- Parameters:
camera_name (str) – The name of the camera
- Returns:
The pointcloud objects with metadata
- Return type:
- abstract async do_command(command: Mapping[str, viam.utils.ValueTypes], *, timeout: Optional[float] = None) Mapping[str, viam.utils.ValueTypes] [source]
Send/receive arbitrary commands
- Parameters:
command (Dict[str, ValueTypes]) – The command to execute
- Returns:
Result of the executed command
- Return type:
Dict[str, ValueTypes]
- classmethod from_robot(robot: viam.robot.client.RobotClient, name: str) typing_extensions.Self
Get the service named
name
from the provided robot.- Parameters:
robot (RobotClient) – The robot
name (str) – The name of the service
- Returns:
The service, if it exists on the robot
- Return type:
Self
- classmethod get_resource_name(name: str) viam.proto.common.ResourceName
Get the ResourceName for this Resource with the given name
- Parameters:
name (str) – The name of the Resource
- get_operation(kwargs: Mapping[str, Any]) viam.operations.Operation
Get the
Operation
associated with the currently running function.When writing custom resources, you should get the
Operation
by calling this function and check to see if it’s cancelled. If theOperation
is cancelled, then you can perform any necessary (terminating long running tasks, cleaning up connections, etc. ).- Parameters:
kwargs (Mapping[str, Any]) – The kwargs object containing the operation
- Returns:
The operation associated with this function
- Return type:
- async close()
Safely shut down the resource and prevent further use.
Close must be idempotent. Later configuration may allow a resource to be “open” again. If a resource does not want or need a close function, it is assumed that the resource does not need to retun errors when future non-Close methods are called.