Auterion App SDK
Auterion SDK is a library that can be used by AuterionOS apps to communicate with the system.
tracking_interface.hpp
1 /****************************************************************************
2  *
3  * Copyright 2024 Auterion AG. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this
9  * list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software without
17  * specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  *
31  ****************************************************************************/
32 
33 #pragma once
34 
35 #include <Eigen/Eigen>
36 #include <auterion_sdk/auterion.hpp>
37 #include <auterion_sdk/camera/camera.hpp>
38 #include <opencv2/core/mat.hpp>
39 #include <opencv2/core/types.hpp>
40 #include <optional>
41 
42 namespace auterion {
52  public:
53  enum class Frame {
54  Camera,
55  Body, // equal to FMU
56  FMU, // equal to Body
57  World, // equal to ENU
58  ENU // equal to World
59  };
60 
61  TrackingResult(const cv::Point& object_center, const cv::Size& object_size,
62  const float confidence = 1.f);
63  ~TrackingResult();
64 
65  TrackingResult& withConfidence(const float confidence);
66 
67  TrackingResult& withObjectDirection(const Eigen::Vector3f& direction, Frame frame);
68 
69  inline cv::Point getObjectCenter() const { return _object_center; }
70  inline cv::Size getObjectSize() const { return _object_size; }
71  inline float getConfidence() const { return _confidence; }
72  Eigen::Vector3f getObjectDirection(Frame frame = Frame::Camera) const;
73 
74  private:
75  cv::Size _object_size;
76  cv::Point _object_center;
77  Eigen::Vector3f _object_direction_camera_frame;
79  Eigen::Vector3f _object_direction_body_frame;
81  Eigen::Vector3f _object_direction_world_frame;
83  float _confidence;
84 };
85 
97  cv::Point2d normalized_point;
101  std::optional<rclcpp::Time>
103 
112  timestamp(std::nullopt) {}
113 
125  timestamp(std::nullopt) {}
126 };
127 
128 class TrackingInterfaceImpl;
129 
136  public:
144  NONE = 0,
146  ADJUST_UP = 2,
148  ADJUST_RIGHT = 4
149  };
150 
151  using ImageCallback = std::function<void(const auterion::Image& image)>;
152  using CameraInfoCallback =
153  std::function<void(const sensor_msgs::msg::CameraInfo::SharedPtr& camera_info)>;
154  using TrackSelectionCallback = std::function<void(const TrackingSelection& selection)>;
155  using TrackStopCallback = std::function<void(void)>;
156  using TrackZoomChangeCallback = std::function<void(const int change)>;
157  using TrackKeyControlCallback = std::function<void(const TrackingKeyControl key)>;
158 
168  TrackingInterface(auterion::SDK& sdk, std::shared_ptr<auterion::Camera> camera = nullptr);
169 
181  [[deprecated(
182  "'camera_descriptor' not used anymore. This will be removed in some later "
183  "release.")]] TrackingInterface(auterion::SDK& sdk,
184  std::optional<auterion::CameraDescriptor>
185  camera_descriptor);
186 
188 
193  [[deprecated(
194  "Replace by equal function in camera interface. This will be removed in some later "
195  "release.")]] void
196  subscribeImage(const ImageCallback& callback);
197 
202  [[deprecated(
203  "Replace by equal function in camera interface. This will be removed in some later "
204  "release.")]] void
205  subscribeCameraInfo(const CameraInfoCallback& callback);
206 
211  void subscribeTrackingSelection(const TrackSelectionCallback& callback);
212 
217  void subscribeTrackingOff(const TrackStopCallback& callback);
218 
223  void subscribeTrackingZoomChange(const TrackZoomChangeCallback& callback);
224 
230  void subscribeKeyControl(const TrackKeyControlCallback& callback);
231 
241  void updateImage(const cv::Mat& image, const auterion::ImageHeader::Encoding& encoding,
242  const std::optional<cv::Rect>& displayed_region = std::nullopt,
243  const std::optional<TrackingResult>& tracking_result = std::nullopt);
244 
255  void updateImage(const cv::Mat& image, const auterion::ImageHeader::Encoding& encoding,
256  const TrackingResult& tracking_result);
257 
262  // TODO create an overload with plain/simple types?
263  void updateResult(TrackingResult& tracking_result) const;
264 
279  [[deprecated(
280  "Replace by equal function in camera interface. This will be removed in some later "
281  "release.")]] bool
282  getPoseBodyCamera(Eigen::Vector3d& t_body_camera, Eigen::Quaterniond& q_body_camera) const;
283 
284  private:
285  std::shared_ptr<TrackingInterfaceImpl> _impl;
286 };
287 
289 } // namespace auterion
Camera client to subscribe to a camera image stream.
Definition: camera.hpp:307
Contains image data with a specific encoding.
Definition: camera.hpp:202
SDK execution class. All callbacks are called on the same thread.
Definition: auterion.hpp:45
Provides an API to react to tracking related events, and update the current tracking status.
Definition: tracking_interface.hpp:135
void subscribeKeyControl(const TrackKeyControlCallback &callback)
Subscribes to the tracking key control events.
bool getPoseBodyCamera(Eigen::Vector3d &t_body_camera, Eigen::Quaterniond &q_body_camera) const
Get the pose of the camera with respect to the body frame.
void subscribeImage(const ImageCallback &callback)
Subscribes to incoming images.
void subscribeCameraInfo(const CameraInfoCallback &callback)
Subscribes to camera information data.
void subscribeTrackingZoomChange(const TrackZoomChangeCallback &callback)
Subscribes to the tracking zoom change events.
void updateImage(const cv::Mat &image, const auterion::ImageHeader::Encoding &encoding, const std::optional< cv::Rect > &displayed_region=std::nullopt, const std::optional< TrackingResult > &tracking_result=std::nullopt)
Updates image for connected systems to display and publishes the tracking result over MAVLink to be r...
void subscribeTrackingOff(const TrackStopCallback &callback)
Subscribes to the tracking off events.
TrackingInterface(auterion::SDK &sdk, std::optional< auterion::CameraDescriptor > camera_descriptor)
[Deprecated] Constructor that selects a camera based on a provided descriptor.
TrackingInterface(auterion::SDK &sdk, std::shared_ptr< auterion::Camera > camera=nullptr)
Constructor that accepts a camera object.
TrackingKeyControl
Enum representing the control commands for tracking adjustments.
Definition: tracking_interface.hpp:143
@ NONE
Not set.
Definition: tracking_interface.hpp:144
@ ADJUST_RIGHT
Move right.
Definition: tracking_interface.hpp:148
@ ADJUST_UP
Move up.
Definition: tracking_interface.hpp:146
@ ADJUST_DOWN
Move down.
Definition: tracking_interface.hpp:145
@ ADJUST_LEFT
Move left.
Definition: tracking_interface.hpp:147
void subscribeTrackingSelection(const TrackSelectionCallback &callback)
Subscribes to tracking selection requests.
void updateResult(TrackingResult &tracking_result) const
Updates the tracking result for connected systems.
void updateImage(const cv::Mat &image, const auterion::ImageHeader::Encoding &encoding, const TrackingResult &tracking_result)
Updates image for connected systems to display and publishes the tracking result over MAVLink to be r...
Represents the result of an image tracking operation.
Definition: tracking_interface.hpp:51
Encoding
Image encoding, following FourCC.
Definition: camera.hpp:67
Represents the tracking selection as received by AMC.
Definition: tracking_interface.hpp:96
std::optional< rclcpp::Time > timestamp
Optional timestamp for the tracking selection (not currently used).
Definition: tracking_interface.hpp:102
cv::Size2d normalized_window_size
Definition: tracking_interface.hpp:99
TrackingSelection(cv::Point2d normalized_point)
Constructor for creating a tracking selection with a point only.
Definition: tracking_interface.hpp:109
cv::Point2d normalized_point
Definition: tracking_interface.hpp:97
TrackingSelection(cv::Point2d normalized_point, cv::Size2d normalized_window_size)
Constructor for creating a tracking selection with a point and a window size. This should be used whe...
Definition: tracking_interface.hpp:122