Viam C++ SDK current
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
viam::sdk::Camera Class Referenceabstract

A Camera represents any physical hardware that can capture frames. More...

#include "components/camera.hpp"

+ Inheritance diagram for viam::sdk::Camera:

Classes

struct  distortion_parameters
 The distortion parameters of the camera. More...
 
struct  image_collection
 a collection of images that were collected from a camera all at the same time. More...
 
struct  intrinsic_parameters
 
struct  point_cloud
 The points and mime type of a point cloud. More...
 
struct  properties
 The camera's supported features and settings. More...
 
struct  raw_image
 the raw bytes, mime type of an image, and name of the source that produced it. More...
 

Public Types

using mime_types = std::vector<std::string>
 The supported mime types of the camera— a type alias.
 
using depth_map = xt::xarray<uint16_t>
 

Public Member Functions

virtual AttributeMap do_command (const AttributeMap &command)=0
 Send/receive arbitrary commands to the resource.
 
raw_image get_image (std::string mime_type)
 Get the next image from the camera as a raw image.
 
virtual raw_image get_image (std::string mime_type, const AttributeMap &extra)=0
 Get the next image from the camera as a raw image.
 
virtual image_collection get_images ()=0
 Get the next images from the camera as a vector of raw images with names and metadata.
 
point_cloud get_point_cloud (std::string mime_type)
 Get the next point_cloud from the camera.
 
virtual point_cloud get_point_cloud (std::string mime_type, const AttributeMap &extra)=0
 Get the next point_cloud from the camera.
 
std::vector< GeometryConfigget_geometries ()
 Returns GeometryConfigs associated with the calling camera.
 
virtual std::vector< GeometryConfigget_geometries (const AttributeMap &extra)=0
 Returns GeometryConfigs associated with the calling camera.
 
virtual properties get_properties ()=0
 Get the camera's properties.
 
API api () const override
 Returns the API associated with a particular resource.
 
- Public Member Functions inherited from viam::sdk::Component
viam::common::v1::ResourceName get_resource_name (std::string name) const override
 Returns a ResourceName for a particular resource name.
 
- Public Member Functions inherited from viam::sdk::Resource
 Resource (std::string name)
 
virtual std::string name () const
 Return the resource's name.
 

Static Public Member Functions

static std::vector< unsigned char > encode_depth_map (const Camera::depth_map &m)
 
static Camera::depth_map decode_depth_map (const std::vector< unsigned char > &data)
 
static std::string normalize_mime_type (const std::string &str)
 remove any extra suffix's from the mime type string.
 
static std::string format_to_MIME_string (viam::component::camera::v1::Format format)
 convert a protobuf format enum with a MIME type string.
 
static viam::component::camera::v1::Format MIME_string_to_format (const std::string &mime_string)
 convert a MIME type string with a protobuf format enum.
 
static raw_image from_proto (const viam::component::camera::v1::GetImageResponse &proto)
 Creates a raw_image struct from its proto representation.
 
static image_collection from_proto (const viam::component::camera::v1::GetImagesResponse &proto)
 Creates a image_collection struct from its proto representation.
 
static point_cloud from_proto (const viam::component::camera::v1::GetPointCloudResponse &proto)
 Creates a point_cloud struct from its proto representation.
 
static intrinsic_parameters from_proto (const viam::component::camera::v1::IntrinsicParameters &proto)
 creates an intrinsic_parameters struct from its proto representation.
 
static distortion_parameters from_proto (const viam::component::camera::v1::DistortionParameters &proto)
 creats a distortion_parameters struct from its proto representation.
 
static properties from_proto (const viam::component::camera::v1::GetPropertiesResponse &proto)
 creates a properties struct from its proto representation.
 
static viam::component::camera::v1::DistortionParameters to_proto (const distortion_parameters &)
 converts a distortion_parameters struct to its proto representation.
 
static viam::component::camera::v1::IntrinsicParameters to_proto (const intrinsic_parameters &)
 converts an intrinsic_parameters struct to its proto representation.
 

Static Public Attributes

static const std::string lazy_suffix
 

Protected Member Functions

 Camera (std::string name)
 
- Protected Member Functions inherited from viam::sdk::Component
 Component (std::string name)
 

Detailed Description

A Camera represents any physical hardware that can capture frames.

This acts as an abstract base class to be inherited from by any drivers representing specific camera implementations. This class cannot be used on its own.

Member Function Documentation

◆ api()

API viam::sdk::Camera::api ( ) const
overridevirtual

Returns the API associated with a particular resource.

Implements viam::sdk::Resource.

◆ decode_depth_map()

static Camera::depth_map viam::sdk::Camera::decode_depth_map ( const std::vector< unsigned char > & data)
static

Decode image data of custom MIME type FORMAT_RAW_DEPTH into a depth_map structure.

This function processes a binary blob representing a depth map in a specific format and extracts the dimensions and depth values contained within.

Parameters
dataA vector of unsigned chars representing the binary data of the depth map.
Returns
A depth_map (type alias for a 2D xtensor array)
Exceptions
Exceptionif the data is misformatted e.g. doesn't contain valid depth information, or if the data size does not match the expected size based on the width and height.

◆ do_command()

virtual AttributeMap viam::sdk::Camera::do_command ( const AttributeMap & command)
pure virtual

Send/receive arbitrary commands to the resource.

Parameters
Commandthe command to execute.
Returns
The result of the executed command.

Implemented in viam::sdk::impl::CameraClient.

◆ encode_depth_map()

static std::vector< unsigned char > viam::sdk::Camera::encode_depth_map ( const Camera::depth_map & m)
static

Encodes the dimensions and depth values of a depth map into a raw binary format (MIME type FORMAT_RAW_DEPTH).

This function takes a depth_map, and encodes this information into a binary blob. The binary format consists of "magic number" header (UTF-8 encoding for 'DEPTHMAP' in big-endian), then the width and height encoded as 64-bit unsigned integers, followed by the depth values encoded as 16-bit unsigned integers (big-endian format). This format is suitable for serialization and transmission of depth map data through gRPC.

Parameters
depth_mapA type alias for a 2D xtensor array
Returns
A std::vector<unsigned char> representing the encoded binary data of the depth map. The vector includes 8 bytes for width, 8 bytes for height, followed by 2 bytes per depth value.
Exceptions
Exceptionif the depth map is not 2D

◆ get_geometries() [1/2]

std::vector< GeometryConfig > viam::sdk::Camera::get_geometries ( )
inline

Returns GeometryConfigs associated with the calling camera.

Returns
The requested GeometryConfigs associated with the component.

◆ get_geometries() [2/2]

virtual std::vector< GeometryConfig > viam::sdk::Camera::get_geometries ( const AttributeMap & extra)
pure virtual

Returns GeometryConfigs associated with the calling camera.

Parameters
extraAny additional arguments to the method.
Returns
The requested GeometryConfigs associated with the component.

Implemented in viam::sdk::impl::CameraClient, and viam::sdk::impl::CameraClient.

◆ get_image() [1/2]

raw_image viam::sdk::Camera::get_image ( std::string mime_type)
inline

Get the next image from the camera as a raw image.

Parameters
mime_typethe desired mime_type of the image (does not guarantee output type).
Returns
The frame as a raw_image.

◆ get_image() [2/2]

virtual raw_image viam::sdk::Camera::get_image ( std::string mime_type,
const AttributeMap & extra )
pure virtual

Get the next image from the camera as a raw image.

Parameters
mime_typethe desired mime_type of the image (does not guarantee output type).
extraany additional arguments to the method.
Returns
The frame as a raw_image.

Implemented in viam::sdk::impl::CameraClient, and viam::sdk::impl::CameraClient.

◆ get_images()

virtual image_collection viam::sdk::Camera::get_images ( )
pure virtual

Get the next images from the camera as a vector of raw images with names and metadata.

Returns
a vector of raw_images and associated response metadata.

Implemented in viam::sdk::impl::CameraClient.

◆ get_point_cloud() [1/2]

point_cloud viam::sdk::Camera::get_point_cloud ( std::string mime_type)
inline

Get the next point_cloud from the camera.

Parameters
mime_typethe desired mime_type of the point_cloud (does not guarantee output type).
Returns
The requested point_cloud.

◆ get_point_cloud() [2/2]

virtual point_cloud viam::sdk::Camera::get_point_cloud ( std::string mime_type,
const AttributeMap & extra )
pure virtual

Get the next point_cloud from the camera.

Parameters
mime_typethe desired mime_type of the point_cloud (does not guarantee output type).
extraany additional arguments to the method.
Returns
The requested point_cloud.

Implemented in viam::sdk::impl::CameraClient, and viam::sdk::impl::CameraClient.

◆ get_properties()

virtual properties viam::sdk::Camera::get_properties ( )
pure virtual

Get the camera's properties.

Returns
The camera properties.

Implemented in viam::sdk::impl::CameraClient.


The documentation for this class was generated from the following file: