Camera API | Component APIs
Camera API
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:
- Request single images in 2D color, or display z-depth.
- Request a point cloud. Each 3D point cloud image consists of a set of coordinates (x,y,z) representing depth in mm.
The camera component supports the following methods:
| Method Name | Description |
|---|---|
GetImages |
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. |
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. |
API
GetImages
Usage
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:
- (Tuple[Sequence[ video.NamedImage], common.ResponseMetadata]): : A tuple containing two values; the first [0] a list of images returned from the camera system, and the second [1] the metadata associated with this response.
Example:
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:
- [NamedImage]: The list of images returned from the camera system, with the name of the imager associated with the image.
- (resource.ResponseMetadata): The metadata, which holds the timestamp of when the data was captured.
- (error): An error, if one occurred.
Example:
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:
- (Promise< { images: { image: Uint8Array; mimeType: string; sourceName: string }[]; metadata: ResponseMetadata; }, >)
Example:
For more information, see the TypeScript SDK Docs.
Parameters:
Returns:
Example:
For more information, see the Flutter SDK Docs.
GetPointCloud
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:
- (Tuple[ bytes, str]): : A tuple containing two values; the first [0] the pointcloud data, and the second [1] the mimetype of the pointcloud (for example, PCD).
Example:
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:
- (pointcloud.PointCloud): A general purpose container of points. It does not dictate whether or not the cloud is sparse or dense.
- (error): An error, if one occurred.
Example:
For more information, see the Go SDK Docs.
Parameters:
extra(None) (optional)callOptions(CallOptions) (optional)
Returns:
- (Promise)
Example:
For more information, see the TypeScript SDK Docs.
Parameters:
Returns:
Example:
For more information, see the Flutter SDK Docs.
GetProperties
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:
- ( viam.components.camera.Camera.Properties): : The properties of the camera, including intrinsic parameters, distortion parameters, supported mime types, and optionally extrinsic parameters (position relative to a reference frame).
Example:
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:
- (Properties): Properties of the particular implementation of a camera.
- (error): An error, if one occurred.
For more information, see the Go SDK Docs.
Parameters:
callOptions(CallOptions) (optional)
Returns:
- (Promise< cameraApi. GetPropertiesResponse >)
Example:
For more information, see the TypeScript SDK Docs.
Parameters:
- None.
Returns:
Example:
For more information, see the Flutter SDK Docs.
DoCommand
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:
- (Mapping[ str, viam.utils.ValueTypes]): : Result of the executed command.
Raises:
- (NotImplementedError): Raised if the Resource does not support arbitrary commands.
Example:
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:
- (map[string]interface{}): The command response.
- (error): An error, if one occurred.
Example:
For more information, see the Go SDK Docs.
Parameters:
command( Struct) (required): The command to execute. Accepts either a Struct or a plain object, which will be converted automatically.callOptions(CallOptions) (optional)
Returns:
- (Promise< JsonValue >)
Example:
For more information, see the TypeScript SDK Docs.
Parameters:
Returns:
Example:
For more information, see the Flutter SDK Docs.
GetGeometries
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:
Returns:
- ( Sequence[viam.proto.common.Geometry]): : The geometries associated with the Component.
Example:
For more information, see the Python SDK Docs.
Parameters:
Returns:
- [spatialmath.Geometry]: The geometries associated with this resource, in any order.
- (error): An error, if one occurred.
Example:
For more information, see the Go SDK Docs.
Parameters:
extra(None) (optional)callOptions(CallOptions) (optional)
Returns:
For more information, see the TypeScript SDK Docs.
GetResourceName
Get the ResourceName for this camera.
Parameters:
name( str) (required): The name of the Resource.
Returns:
- ( viam.proto.common.ResourceName): : The ResourceName of this Resource.
Example:
For more information, see the Python SDK Docs.
Parameters:
- None.
Returns:
Example:
For more information, see the Go SDK Docs.
Parameters:
- None.
Returns:
- (string): The name of the resource.
Example:
For more information, see the TypeScript SDK Docs.
Parameters:
nameString (required)
Returns:
Example:
For more information, see the Flutter SDK Docs.
Close
Safely shut down the resource and prevent further use.
Parameters:
- None.
Returns:
- None.
Example:
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:
- (error): An error, if one occurred.
Example:
For more information, see the Go SDK Docs.