Auterion App SDK
Auterion SDK is a library that can be used by AuterionOS apps to communicate with the system.
Loading...
Searching...
No Matches
auterion::Camera Class Reference

Camera client to subscribe to a camera image stream. More...

#include <auterion_sdk/camera/camera.hpp>

Classes

struct  ImageReplacementOptions
 

Public Types

using ImageCallback = std::function< void(const Image &image)>
 
using ImageFDCallback = std::function< void(const std::shared_ptr< ImageFD > &image_fd)>
 
using CameraInfoAfterSwitchCallback = std::function< void(const sensor_msgs::msg::CameraInfo::SharedPtr &camera_info)>
 
using TrackingStatusCallback = std::function< void(const TrackingStatus &status)>
 
using ServiceStatusCallback = std::function< void(const CameraServiceStatus &status)>
 

Public Member Functions

 Camera (SDK &sdk, const CameraDescriptor &camera_descriptor)
 
 Camera (std::shared_ptr< CameraImpl > impl)
 
void subscribeImage (const ImageCallback &callback)
 
void subscribeImageFD (const ImageFDCallback &callback, float max_rate_hz=0.0F)
 
void setImagesPaused (bool paused)
 Stop or resume image delivery without giving up the subscription.
 
void activateImageReplacement (const ImageReplacementOptions &options=ImageReplacementOptions())
 Activate image replacement.
 
void deactivateImageReplacement ()
 
std::optional< ImageFD > getReplacementImage (const ImageFD &image)
 Get a replacement image buffer.
 
std::optional< ImageFD > getReplacementImage (uint32_t original_frame_id)
 Get a replacement image buffer by the original frame's id.
 
std::chrono::steady_clock::time_point lastReplacementImageOffer () const
 When the camera service last offered a replacement image buffer.
 
void subscribeCameraInfo (std::function< void(const sensor_msgs::msg::CameraInfo::SharedPtr)> callback)
 
void subscribeCameraInfoAfterSwitch (const CameraInfoAfterSwitchCallback &callback)
 Subscribe to camera info updates emitted once after each successful stream switch.
 
void subscribeTrackingStatus (TrackingStatusCallback callback)
 Subscribe to the status of the tracking on this camera.
 
void subscribeServiceStatus (ServiceStatusCallback callback)
 Subscribe to the status of the service providing this camera.
 
bool cameraInfoValid () const
 Determine whether a camera info message contains valid data.
 
std::optional< cv::Size > getLastImageSize () const
 Returns the size of the last received image, if available.
 
Eigen::Vector3d unprojectImagePoint (const cv::Point &image_point) const
 Determine the (relative) camera-frame 3D position of a point in an image.
 
bool getPoseBodyCamera (Eigen::Quaterniond &q_body_camera, Eigen::Vector3d &t_body_camera) const
 Get the pose of the camera with respect to the body frame.
 
bool getPoseWorldCamera (Eigen::Quaterniond &q_enu_camera, Eigen::Vector3d &t_enu_camera, const tf2::TimePoint &time=tf2::TimePointZero) const
 Get the pose of the camera with respect to the ENU world frame.
 
bool getDeltaRotationWorldCamera (Eigen::Quaterniond &q_delta_world_camera, tf2::TimePoint &time_start, tf2::TimePoint &time_end)
 Calculates how much the camera has rotated between two points in time based only on gyro data.
 
bool getCameraInfo (sensor_msgs::msg::CameraInfo &camera_info) const
 Get the camera information data for the camera.
 
bool getCameraInfoDirect (sensor_msgs::msg::CameraInfo &camera_info) const
 get the camera info directly from the camera
 
bool switchTo (const std::function< bool(const CameraDescriptor &)> &find_callback)
 Switch active UnixFD input to a discovered camera selected by callback.
 
const CameraDescriptor & descriptor () const
 Get the descriptor of the active camera source.
 
CameraControl & control ()
 
bool usesImageSession () const
 

Static Public Member Functions

static Camera waitForCamera (SDK &sdk, const std::function< bool(const CameraDescriptor &)> &find_callback)
 
static Camera waitForCamera (SDK &sdk, std::optional< auterion::CameraDescriptor > camera_descriptor=std::nullopt)
 
static std::optional< Camera > open (SDK &sdk, const std::string &unique_name, const std::chrono::seconds &timeout=30s)
 
static std::optional< Camera > open (SDK &sdk, const std::function< bool(const CameraDescriptor &)> &find_callback, const std::chrono::seconds &timeout=30s)
 
static std::optional< Camera > openFirst (SDK &sdk, const std::chrono::seconds &timeout=30s)
 

Detailed Description

Camera client to subscribe to a camera image stream.

Member Function Documentation

◆ activateImageReplacement()

void auterion::Camera::activateImageReplacement ( const ImageReplacementOptions &  options = ImageReplacementOptions())

Activate image replacement.

This allows to customize the image that is sent to the GCS (and displayed to the user). It can be dynamically enabled or disabled, but there can be at most one replacement image active at a time for a given camera.

◆ cameraInfoValid()

bool auterion::Camera::cameraInfoValid ( ) const

Determine whether a camera info message contains valid data.

The first query of the camera info (this or getCameraInfo()) subscribes to it and waits up to 1 s for valid camera info, if the data can arrive meanwhile (SDK::canWaitForData()).

Returns
True if valid distortion and intrinsic matrices are present and image size is non-zero.

◆ getCameraInfo()

bool auterion::Camera::getCameraInfo ( sensor_msgs::msg::CameraInfo &  camera_info) const

Get the camera information data for the camera.

The first query of the camera info (this or cameraInfoValid()) subscribes to it and waits up to 1 s for valid camera info, if the data can arrive meanwhile (SDK::canWaitForData()).

Parameters
camera_infoCamera information data.
Returns
true if the camera info is successfully retrieved, false otherwise.

◆ getCameraInfoDirect()

bool auterion::Camera::getCameraInfoDirect ( sensor_msgs::msg::CameraInfo &  camera_info) const

get the camera info directly from the camera

This can be used to access the calibration (intrinsics) directly provided by the camera, if supported. Applications should generally use getCameraInfo() instead.

Parameters
camera_infoCamera information data.
Returns
true if the camera info is successfully retrieved, false otherwise.

◆ getDeltaRotationWorldCamera()

bool auterion::Camera::getDeltaRotationWorldCamera ( Eigen::Quaterniond &  q_delta_world_camera,
tf2::TimePoint &  time_start,
tf2::TimePoint &  time_end 
)

Calculates how much the camera has rotated between two points in time based only on gyro data.

Deprecated:
The backing 'world_only_gyro' tf frame is no longer published, so this method currently always returns false.

This function computes the change in orientation of the camera's optical frame between time_start and time_end, using transforms from the TF2 buffer.

The result is a quaternion (q_delta_world_camera) that represents the rotation from the camera's orientation at time_start to its orientation at time_end, relative to the world (inertial) frame.

If a transform at the requested time is not available or is invalid (e.g., a zero quaternion), the function will fall back to the latest available valid transform. If a fallback is used, the time_start and time_end values will be updated to match the actual times of the data used.

Parameters
[out]q_delta_world_cameraThe computed relative rotation from start to end time, represented as a quaternion in the world frame.
[in,out]time_startThe start time of the rotation interval. May be updated if fallback is used.
[in,out]time_endThe end time of the rotation interval. May be updated if fallback is used.
Returns
true if the rotation was successfully calculated, false if transform data was unavailable.
Note
If time_start and time_end are the same, no rotation is assumed and the identity quaternion is returned.

◆ getLastImageSize()

std::optional< cv::Size > auterion::Camera::getLastImageSize ( ) const

Returns the size of the last received image, if available.

This is updated with every new image and can be used to determine the current image resolution.

Returns
image size if available, std::nullopt otherwise

◆ getPoseBodyCamera()

bool auterion::Camera::getPoseBodyCamera ( Eigen::Quaterniond &  q_body_camera,
Eigen::Vector3d &  t_body_camera 
) const

Get the pose of the camera with respect to the body frame.

This function retrieves the pose of the camera relative to the body frame / FMU of the vehicle. The pose is represented by a rotation quaternion and a translation vector. ROS2 coordinate frame conventions are followed. Specifically:

  • The body frame is defined FLU (front=x, left=y,up=z).
  • The quaternion represents the orientation of the camera frame w.r.t. the body frame.
  • The translation represents the position of the camera frame w.r.t. the body frame.
Parameters
q_body_cameraRotation quaternion of the camera with respect to the body frame.
t_body_cameraTranslation of the camera with respect to the body frame.
Returns
true if the pose is successfully retrieved, false otherwise.

◆ getPoseWorldCamera()

bool auterion::Camera::getPoseWorldCamera ( Eigen::Quaterniond &  q_enu_camera,
Eigen::Vector3d &  t_enu_camera,
const tf2::TimePoint &  time = tf2::TimePointZero 
) const

Get the pose of the camera with respect to the ENU world frame.

This function retrieves the pose of the camera relative to the world frame (ENU convention). The pose is represented by a rotation quaternion and a translation vector. ROS2 coordinate frame conventions are followed. Specifically:

  • The world frame is defined ENU.
  • The rotation represents the orientation of the camera frame with respect to the ENU world frame.
  • The translation represents the position of the camera frame with respect to the ENU world frame.
Parameters
q_enu_cameraRotation quaternion of the camera with respect to the ENU world frame.
t_enu_cameraTranslation of the camera with respect to the ENU world frame.
timeOptional parameter specifying the time point for which the pose is requested. Defaults to the earliest possible time.
Returns
true if the pose is successfully retrieved, false otherwise.

◆ getReplacementImage() [1/2]

std::optional< ImageFD > auterion::Camera::getReplacementImage ( const ImageFD &  image)

Get a replacement image buffer.

Only call this after activateImageReplacement() is called. It should be called whenever a new image is available (from the subscription callback). It will have the same buffer size and format as the subscription image.

The returned image can be written to, and no assumption should be made about the contents.

Note
this might return nullopt for the first few images (up to 3) after replacement got activated.
Parameters
imagethe image that was received from the subscription callback (used to keep track of the original frame for timestamping)

◆ getReplacementImage() [2/2]

std::optional< ImageFD > auterion::Camera::getReplacementImage ( uint32_t  original_frame_id)

Get a replacement image buffer by the original frame's id.

Same as getReplacementImage(const ImageFD&), but takes only the original frame id — the acquire is client-local and needs nothing else from the original image. This allows a consumer to acquire the replacement on a different thread (e.g. a render worker) after the original ImageFD has already been released: frames that are never composed simply never acquire a buffer, and the camera service handles them as unreplaced.

Parameters
original_frame_idframe id of the original image the replacement is for

◆ lastReplacementImageOffer()

std::chrono::steady_clock::time_point auterion::Camera::lastReplacementImageOffer ( ) const

When the camera service last offered a replacement image buffer.

The camera service offers replacement buffers only while it uses the replacements, e.g. while its video output streams this camera. It hands out every free buffer in advance and offers a returned one again, so buffers obtained with getReplacementImage() can remain after it stopped: a consumer that renders, but sees no new offer afterwards, learns that the replacements are no longer used.

Returns
the time of the last offer, or a default-constructed time point if there was none

◆ setImagesPaused()

void auterion::Camera::setImagesPaused ( bool  paused)

Stop or resume image delivery without giving up the subscription.

Paused, the camera service is told to close the image session: it sends nothing at all, and the buffers it shared are unmapped. That is the difference from ignoring frames in the callback, which still pays the socket round trip for every one of them - what a frame costs once nothing reads it. The subscription itself survives, callback, rate and all, so resuming costs a session rather than a resubscribe; the first frame after it is delivered as soon as one arrives.

Never throws, is idempotent, and is safe to call before any subscription exists - it is meant to be driven by whatever knows the consumer has nothing to do, which is usually a callback with nothing to catch for it. Use it for a consumer that will want nothing for a while - a vehicle that has taken off, an operating mode that owns the camera - rather than for skipping individual frames, which is what the rate is for. Session-based cameras only; a no-op on the legacy socket path, which has no session to close.

◆ subscribeCameraInfoAfterSwitch()

void auterion::Camera::subscribeCameraInfoAfterSwitch ( const CameraInfoAfterSwitchCallback &  callback)

Subscribe to camera info updates emitted once after each successful stream switch.

Multiple callbacks are supported and all will be invoked.

◆ subscribeImage()

void auterion::Camera::subscribeImage ( const ImageCallback &  callback)

Subscribe to image updates. Note that the image is only valid for the duration of the callback.

Parameters
callback

◆ subscribeServiceStatus()

void auterion::Camera::subscribeServiceStatus ( ServiceStatusCallback  callback)

Subscribe to the status of the service providing this camera.

Reported about once a second while the service provides the camera; a camera of the old protocol (see usesImageSession()) has none. callback runs on the SDK executor.

◆ subscribeTrackingStatus()

void auterion::Camera::subscribeTrackingStatus ( TrackingStatusCallback  callback)

Subscribe to the status of the tracking on this camera.

The app registered to track on the camera reports it about 5 times per second, with active false and mode None while nothing is tracked; without such an app there are no reports. callback runs on the SDK executor.

◆ switchTo()

bool auterion::Camera::switchTo ( const std::function< bool(const CameraDescriptor &)> &  find_callback)

Switch active UnixFD input to a discovered camera selected by callback.

This keeps callbacks/subscriptions unchanged and only reconnects the underlying UnixFD receiver to the selected camera socket path.

Returns
true if the switch was successful, false otherwise (e.g. if no matching camera found).

◆ unprojectImagePoint()

Eigen::Vector3d auterion::Camera::unprojectImagePoint ( const cv::Point &  image_point) const

Determine the (relative) camera-frame 3D position of a point in an image.

Parameters
image_pointA 2D point in an image.
Returns
A 3D point describing the input pixel coordinates in the camera frame (normalize such that z=1.0).

◆ usesImageSession()

bool auterion::Camera::usesImageSession ( ) const

True for a session camera (new camera protocol, e.g. video-service); false for the legacy UnixFD socket path. Lets a consumer select behaviour by transport without knowing the producer.

◆ waitForCamera()

static Camera auterion::Camera::waitForCamera ( SDK &  sdk,
const std::function< bool(const CameraDescriptor &)> &  find_callback 
)
static

Setup camera to enable registering image callbacks


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