Previous
Button
The camera API allows you to give commands to your camera components for getting images or point clouds.
The API for camera components allows you to:
The camera component supports the following methods:
| Method Name | Description |
|---|---|
GetImages | Get simultaneous images from different imagers, along with associated metadata. |
GetPointCloud | Get a point cloud from the camera as bytes with a MIME type describing the structure of the data. |
GetProperties | Get the camera intrinsic parameters and camera distortion, as well as whether the camera supports returning point clouds. |
DoCommand | Execute model-specific commands that are not otherwise defined by the component API. |
GetGeometries | Get all the geometries associated with the camera in its current configuration, in the frame of the camera. |
GetResourceName | Get the ResourceName for this camera. |
Close | Safely shut down the resource and prevent further use. |
You can use the rgb-d-overlay module to view and compare the camera streams returned by this method.
See the module readme for further instructions.
GetImages is used for getting simultaneous images from different imagers from 3D cameras along with associated metadata, and single images from non-3D cameras, for example webcams, RTSP cameras, etc. in the image list in the response.
Multiple images returned from GetImages() do not represent a time series of images.
Parameters:
filter_source_names (Sequence[str]) (optional): The filter_source_names parameter can be used to filter only the images from the specified source names. When unspecified, all images are returned.extra (Mapping[str, Any]) (optional): Extra options to pass to the underlying RPC call.timeout (float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.Returns:
Example:
my_camera = Camera.from_robot(robot=machine, name="my_camera")
images, metadata = await my_camera.get_images()
first_image = images[0]
timestamp = metadata.captured_at
For more information, see the Python SDK Docs.
Parameters:
ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.filterSourceNames ([]string)extra (map[string]interface{}): Extra options to pass to the underlying RPC call.Returns:
Example:
myCamera, err := camera.FromProvider(machine, "my_camera")
images, metadata, err := myCamera.Images(context.Background(), nil, nil)
For more information, see the Go SDK Docs.
Parameters:
filterSourceNames (string) (optional): A list of source names to filter the images by.
If empty or undefined, all images will be returned.extra (None) (optional): Extra parameters to pass to the camera.callOptions (CallOptions) (optional)Returns:
Example:
const camera = new VIAM.CameraClient(machine, 'my_camera');
const images = await camera.getImages();
For more information, see the TypeScript SDK Docs.
Parameters:
Returns:
Example:
const camera = new VIAM.CameraClient(machine, 'my_camera');
const images = await camera.getImages();
For more information, see the Flutter SDK Docs.
Get a point cloud from the camera as bytes with a MIME type describing the structure of the data. The consumer of this call should decode the bytes into the format suggested by the MIME type.
Parameters:
extra (Mapping[str, Any]) (optional): Extra options to pass to the underlying RPC call.timeout (float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.Returns:
Example:
import numpy as np
import open3d as o3d
my_camera = Camera.from_robot(robot=machine, name="my_camera")
data, _ = await my_camera.get_point_cloud()
# write the point cloud into a temporary file
with open("/tmp/pointcloud_data.pcd", "wb") as f:
f.write(data)
pcd = o3d.io.read_point_cloud("/tmp/pointcloud_data.pcd")
points = np.asarray(pcd.points)
For more information, see the Python SDK Docs.
Parameters:
ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.extra (map[string]interface{}): Extra options to pass to the underlying RPC call.Returns:
Example:
myCamera, err := camera.FromProvider(machine, "my_camera")
// gets the next point cloud from a camera
pointCloud, err := myCamera.NextPointCloud(context.Background(), nil)
For more information, see the Go SDK Docs.
Parameters:
extra (None) (optional)callOptions (CallOptions) (optional)Returns:
Example:
const camera = new VIAM.CameraClient(machine, 'my_camera');
const pointCloud = await camera.getPointCloud();
For more information, see the TypeScript SDK Docs.
Parameters:
Returns:
Example:
var nextPointCloud = await myCamera.pointCloud();
For more information, see the Flutter SDK Docs.
Get the camera intrinsic parameters and camera distortion, as well as whether the camera supports returning point clouds.
Parameters:
timeout (float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.Returns:
Example:
my_camera = Camera.from_robot(robot=machine, name="my_camera")
properties = await my_camera.get_properties()
For more information, see the Python SDK Docs.
Parameters:
ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.Returns:
For more information, see the Go SDK Docs.
Parameters:
callOptions (CallOptions) (optional)Returns:
Example:
const camera = new VIAM.CameraClient(machine, 'my_camera');
const properties = await camera.getProperties();
For more information, see the TypeScript SDK Docs.
Parameters:
Returns:
Example:
var cameraProperties = await myCamera.properties();
For more information, see the Flutter SDK Docs.
Execute model-specific commands that are not otherwise defined by the component API.
Most models do not implement DoCommand.
Any available model-specific commands should be covered in the model’s documentation.
If you are implementing your own camera and want to add features that have no corresponding built-in API method, you can implement them with DoCommand.
Parameters:
command (Mapping[str, ValueTypes]) (required): The command to execute.timeout (float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.Returns:
Raises:
Example:
my_camera = Camera.from_robot(robot=machine, name="my_camera")
command = {"cmd": "test", "data1": 500}
result = await my_camera.do_command(command)
For more information, see the Python SDK Docs.
Parameters:
ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.cmd (map[string]interface{}): The command to execute.Returns:
Example:
myCamera, err := camera.FromProvider(machine, "my_camera")
command := map[string]interface{}{"cmd": "test", "data1": 500}
result, err := myCamera.DoCommand(context.Background(), command)
For more information, see the Go SDK Docs.
Parameters:
command (Struct) (required): The command to execute.callOptions (CallOptions) (optional)Returns:
Example:
import { Struct } from '@viamrobotics/sdk';
const result = await resource.doCommand(
Struct.fromJson({
myCommand: { key: 'value' },
})
);
For more information, see the TypeScript SDK Docs.
Get all the geometries associated with the camera in its current configuration, in the frame of the camera. The motion and navigation services use the relative position of inherent geometries to configured geometries representing obstacles for collision detection and obstacle avoidance while motion planning.
Parameters:
extra (Mapping[str, Any]) (optional): Extra options to pass to the underlying RPC call.timeout (float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.Returns:
Example:
my_camera = Camera.from_robot(robot=machine, name="my_camera")
geometries = await my_camera.get_geometries()
if geometries:
# Get the center of the first geometry
print(f"Pose of the first geometry's centerpoint: {geometries[0].center}")
For more information, see the Python SDK Docs.
Parameters:
ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.extra (map[string]interface{}): Extra options to pass to the underlying RPC call.Returns:
Example:
// This example shows using Geometries with an camera component.
myCamera, err := camera.FromProvider(machine, "my_camera")
geometries, err := myCamera.Geometries(context.Background(), nil)
if len(geometries) > 0 {
// Get the center of the first geometry
elem := geometries[0]
fmt.Println("Pose of the first geometry's center point:", elem.Pose())
}
For more information, see the Go SDK Docs.
Parameters:
extra (None) (optional)callOptions (CallOptions) (optional)Returns:
For more information, see the TypeScript SDK Docs.
Get the ResourceName for this camera.
Parameters:
name (str) (required): The name of the Resource.Returns:
Example:
my_camera_name = Camera.get_resource_name("my_camera")
For more information, see the Python SDK Docs.
Parameters:
Returns:
Example:
myCamera, err := camera.FromProvider(machine, "my_camera")
err = myCamera.Name()
For more information, see the Go SDK Docs.
Parameters:
Returns:
Example:
camera.name
For more information, see the TypeScript SDK Docs.
Parameters:
name String (required)Returns:
Example:
final myCameraResourceName = myCamera.getResourceName("my_camera");
For more information, see the Flutter SDK Docs.
Safely shut down the resource and prevent further use.
Parameters:
Returns:
Example:
my_camera = Camera.from_robot(robot=machine, name="my_camera")
await my_camera.close()
For more information, see the Python SDK Docs.
Parameters:
ctx (Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.Returns:
Example:
myCamera, err := camera.FromProvider(machine, "my_camera")
err = myCamera.Close(context.Background())
For more information, see the Go SDK Docs.
Was this page helpful?
Glad to hear it! If you have any other feedback please let us know:
We're sorry about that. To help us improve, please tell us what we can do better:
Thank you!