Ocean
QRCodeTracker3D.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #pragma once
9 
11 
12 #include "ocean/cv/FramePyramid.h"
13 
15 
17 
18 namespace Ocean
19 {
20 
21 namespace Tracking
22 {
23 
24 namespace QRCodes
25 {
26 
27 /**
28  * This class implements a 6-DOF tracker for QR codes.
29  * @ingroup trackingqrcodes
30  */
31 class OCEAN_TRACKING_QRCODES_EXPORT QRCodeTracker3D : public CV::Detector::QRCodes::QRCodeDetector3D
32 {
33  protected:
34 
35  /// Forward-declaration
36  class ObservationHistory;
37 
38  /// Vector of observation histories
39  typedef std::vector<ObservationHistory> ObservationHistories;
40 
41  public:
42 
43  /**
44  * Definition of tracking states.
45  */
47  {
48  /// Unknown/invalid tracking statue
49  TS_UNKNOWN_STATE = 0u,
50  /// State for currently tracked codes
52  /// State when tracking has been lost
53  TS_LOST
54  };
55 
56  /// The unique ID of each tracked code.
57  typedef uint32_t ObjectId;
58 
59  /// Definition of a pointer to the function that provides new 6DOF detections of QR codes, QRCodeDetector3D::detectQRCodes()
61 
62  /// Definition of a function pointer that is called in the event a new QR code is detected for the first time.
63  typedef std::function<void(const CV::Detector::QRCodes::QRCode&, const HomogenousMatrix4&, const Scalar, const ObjectId)> CallbackNewQRCode;
64 
65  /**
66  * Definition of parameters that control the tracker
67  */
68  struct Parameters
69  {
70  /// The number of frames after which the detection will be run, range: [1, infinity)
71  unsigned int detectionCadence_ = 15u;
72 
73  /// The number of layers of the image pyramid that are used for the frame-to-frame tracking of points, range: [1, infinity)
74  unsigned int trackingNumberFramePyramidLayers_ = 3u;
75 
76  /// The time for which a code that is no longer tracked is removed from the database, in seconds, range: (0, infinity)
77  double trackingLostGraceTimeout_ = NumericT<double>::maxValue();
78 
79  /// The maximum projection error that different observations may have to be counted as identical, in pixels, range: (0, infinity)
80  Scalar observationHistoryMaxProjectionError = Scalar(0.5);
81 
82  /// The maximum amount of outliers (points) that different observations may have to be counted as identical, in percent, range: [0, 1]
83  Scalar observationHistoryMaxOutliersPercent = Scalar(0.1);
84  };
85 
86  /**
87  * A tracked code.
88  */
90  {
91  friend class QRCodeTracker3D;
92 
93  public:
94 
95  /**
96  * Constructs an invalid tracked code.
97  */
98  TrackedQRCode() = default;
99 
100  /**
101  * Constructs a tracked code.
102  * @param code The code that is tracked, must be valid.
103  * @param world_T_code The 6DOF pose of the code mapping from object space to world space, must be valid.
104  * @param codeSize The size of the code in the physical world, in meters, range: (0, infinity)
105  * @param trackingObjectPoints The set of object points of this code that should be used for tracking, must have >= 3 elements
106  * @param trackingState The tracking state that this tracked code will be initialized with, must not be `TS_UNKNOWN_STATE`.
107  * @param trackingTimestamp The time at which the code was tracked, must be valid.
108  */
109  TrackedQRCode(CV::Detector::QRCodes::QRCode&& code, HomogenousMatrix4&& world_T_code, const Scalar codeSize, Geometry::ObjectPoints&& trackingObjectPoints, const TrackingState trackingState, const Timestamp trackingTimestamp);
110 
111  /**
112  * Constructs a tracked code.
113  * @param code The code that is tracked, must be valid.
114  * @param world_T_code The 6DOF pose of the code mapping from object space to world space, must be valid.
115  * @param codeSize The size of the code in the physical world, in meters, range: (0, infinity)
116  * @param trackingObjectPoints The set of object points of this code that should be used for tracking, must have >= 3 elements
117  * @param trackingState The tracking state that this tracked code will be initialized with, must not be `TS_UNKNOWN_STATE`.
118  * @param trackingTimestamp The time at which the code was tracked, must be valid.
119  */
120  TrackedQRCode(const CV::Detector::QRCodes::QRCode& code, const HomogenousMatrix4& world_T_code, const Scalar codeSize, const Geometry::ObjectPoints& trackingObjectPoints, const TrackingState trackingState, const Timestamp trackingTimestamp);
121 
122  /**
123  * Returns the tracked code.
124  * @return The code.
125  */
126  inline const CV::Detector::QRCodes::QRCode& code() const;
127 
128  /**
129  * Returns the 6DOF pose of the tracked code.
130  * @return The 6DOF pose.
131  */
132  inline const HomogenousMatrix4& world_T_code() const;
133 
134  /**
135  * Return the size of the code in the physical world.
136  * @return The size.
137  */
138  inline Scalar codeSize() const;
139 
140  /**
141  * Returns the tracking state of the tracked code.
142  * @return The tracking state.
143  */
144  inline TrackingState trackingState() const;
145 
146  /**
147  * Returns the time stamp of the moment when this code was tracked.
148  * @return The time stamp.
149  */
150  inline const Timestamp& trackingTimestamp() const;
151 
152  /**
153  * Returns if this tracked code is valid.
154  * @return True, if so.
155  */
156  inline bool isValid() const;
157 
158  /**
159  * Returns the object points that are used to track this code
160  * @return The object points
161  */
162  inline const Geometry::ObjectPoints& trackingObjectPoints() const;
163 
164  protected:
165 
166  /**
167  * Updates the 6DOF pose of the tracked code.
168  * @param world_T_code The new 6DOF pose of the tracked code, must be valid.
169  * @param codeSize The new size estimate of the code, range: (0, infinity)
170  * @param trackingTimestamp The time stamp that the pose corresponds to, must be valid.
171  */
172  inline void updateTrackingPose(HomogenousMatrix4&& world_T_code, const Scalar codeSize, const Timestamp trackingTimestamp);
173 
174  /**
175  * Sets the tracking state to lost.
176  */
177  inline void setTrackingLost();
178 
179  /**
180  * Returns the list of observation histories of this code.
181  * @return The list of observation histories.
182  */
183  inline ObservationHistories& observationHistories();
184 
185  protected:
186 
187  /// The tracked QR code.
189 
190  /// The 6DOF pose of the tracked QR code.
191  HomogenousMatrix4 world_T_code_ = HomogenousMatrix4(false);
192 
193  /// The size of the code in the physical world .
194  Scalar codeSize_ = Scalar(0);
195 
196  /// The tracking state of the tracked QR code.
197  TrackingState trackingState_ = TS_UNKNOWN_STATE;
198 
199  /// The time when this code was tracked.
200  Timestamp trackingTimestamp_ = Timestamp(false);
201 
202  /// The observation histories of the tracked QR code. One observation history per camera.
204 
205  /// The object points that this code can be tracked with.
207  };
208 
209  /// The definition of map of tracked QR codes.
210  typedef std::unordered_map<ObjectId, TrackedQRCode> TrackedQRCodesMap;
211 
212  protected:
213 
214  /**
215  * The definition of an observation history.
216  */
218  {
219  public:
220 
221  /**
222  * Creates an empty observation history.
223  */
224  ObservationHistory() = default;
225 
226  /**
227  * Adds a new observation to the observation history.
228  * @param sharedAnyCamera The camera what was used to compute this observation, must be valid.
229  * @param world_T_camera The 6DOF pose of the camera in the world, must be valid.
230  * @param objectPoints The object points of the tracked QR code, must have at least 3 elements and the same size as `imagePoints`.
231  * @param imagePoints The image points of the tracked QR code, must have at least 3 elements and the size as `objectPoints`.
232  */
233  void addObservation(const SharedAnyCamera& sharedAnyCamera, const HomogenousMatrix4& world_T_camera, Geometry::ObjectPoints&& objectPoints, Geometry::ImagePoints&& imagePoints);
234 
235  /**
236  * Removes all previous observations that are taken from a different pose than the specified one.
237  * @param sharedAnyCamera The camera what was used to compute this observation, must be valid.
238  * @param world_T_code The transformation between code and world, must be valid.
239  * @param maxProjectionError The maximum projection error that different observations may have to be counted as identical, in pixels, range: (0, infinity)
240  * @param maxOutliersPercent The maximum amount of outliers (points) that different observations may have to be counted as identical, in percent, range: [0, 1]
241  */
242  size_t removeObservations(const SharedAnyCamera& sharedAnyCamera, const HomogenousMatrix4& world_T_code, const Scalar maxProjectionError, const Scalar maxOutliersPercent);
243 
244  /**
245  * Returns the latest group of object points.
246  * @note Do not call this function if no observation history exists.
247  * @return The latest object points.
248  */
250 
251  /**
252  * Returns the latest group of image points
253  * @note Do not call this function if no observation history exists.
254  * @return The latest image points.
255  */
257 
258  /**
259  * Return the number of observations stored in this history.
260  * @return The number of observations
261  */
262  size_t size();
263 
264  /**
265  * Removes all stored observations from this history.
266  */
267  void clear();
268 
269  protected:
270 
271  /// The cameras what were used to compute these observations.
273 
274  /// The camera-to-world transformations, one element per observation.
276 
277  /// The object points of a code observation, one element per observation.
279 
280  /// The image points of a code observation, one element per observation.
282  };
283 
284  public:
285 
286  /**
287  * Constructs a tracker instance
288  */
289  QRCodeTracker3D() = default;
290 
291  /**
292  * Constructs a tracker instance with a specific detection function
293  * @note When `forceDetectionOnlyAndAllow2DCodes` is enabled, 2D detections of codes will be reported in addition to 3D detections. (Frame-to-frame 6DOF code tracking is also disabled.) A 2D code will have will have a negative code size and an invalid pose. The caller will have to add corresponding checks for that.
294  * @param parameters The parameters that will be used for tracking, must be valid
295  * @param callbackQRCodeDetection3D An optional pointer to the function that will be used for the detection of QR codes, if `nullptr` the default will be used
296  * @param callbackNewQRCode An optional callback function that is called whenever a QR code has been detected for the very first time, will be ignored if it is set to `nullptr`
297  * @param forceDetectionOnlyAndAllow2DCodes An optional parameter that disables tracking and only runs detection instead; this will also report 2D codes (which will have a negative size and an invalid pose; the user must check for that); use this if you only care about the payload of codes not their locations.
298  */
299  QRCodeTracker3D(const Parameters& parameters, CallbackQRCodeDetection3D callbackQRCodeDetection3D = nullptr, CallbackNewQRCode callbackNewQRCode = nullptr, const bool forceDetectionOnlyAndAllow2DCodes = false);
300 
301  /**
302  * Tracks QR codes and their 6-DOF pose in two or more 8-bit grayscale images
303  * @note When `forceDetectionOnlyAndAllow2DCodes` is enabled, 2D detections of codes will be reported as well. A 2D code will have will have a negative code size and an invalid pose. The caller will have to add corresponding checks for that.
304  * @param sharedAnyCameras The cameras that produced the input images, must have the same number of elements as `yFrames`, all elements must be valid, number of cameras must remain identical on subsequent calls.
305  * @param yFrames The frames in which QR codes will be detected, must be valid, a minimum 2 frames must be provided, origin must be in the upper left corner, and have a pixel format that is compatible with Y8, minimum size is 29 x 29 pixels
306  * @param world_T_device The transformation that maps points in the device coordinate system points to world points, must be valid
307  * @param device_T_cameras The transformation that converts points in the camera coordinate systems to device coordinates, `devicePoint = device_T_cameras[i] * cameraPoint`, must have the same number of elements as `yFrames`, all elements must be valid
308  * @param worker Optional worker instance for parallelization
309  * @return The map containing all currently tracked QR code
310  */
311  const TrackedQRCodesMap& trackQRCodes(const SharedAnyCameras& sharedAnyCameras, const Frames& yFrames, const HomogenousMatrix4& world_T_device, const HomogenousMatrices4& device_T_cameras, Worker* worker = nullptr);
312 
313  /**
314  * Returns if the tracker is in detection-only mode and will report 2D codes as well
315  * @note If this function returns true, 2D detections of codes will be reported as well. A 2D code will have will have a negative code size and an invalid pose. The caller will have to add corresponding checks for that.
316  * @return True if so, otherwise false
317  */
318  inline bool isForceDetectionOnlyAndAllow2DCodesEnabled() const;
319 
320  /**
321  * Returns an invalid object ID.
322  * @return An invalid object ID.
323  */
324  static constexpr ObjectId invalidObjectId();
325 
326  protected:
327 
328  /**
329  * Tracks a single QR code from one frame to the next
330  * @param previousSharedAnyCameraA The first camera that produced the observation in the previous frame, must be valid
331  * @param previousSharedAnyCameraB The second camera that produced the observation in the previous frame, must be valid
332  * @param previousWorld_T_device The transformation from the previous frame that maps points in the device coordinate system points to world points, must be valid
333  * @param previousDevice_T_cameraA The transformation from the previous frame that converts points in the coordinate systems of the first camera to device coordinates, must be valid
334  * @param previousDevice_T_cameraB The transformation from the previous frame converts points in the coordinate systems of the first camera to device coordinates, must be valid
335  * @param sharedAnyCameraA The first camera that produced the observation in the current frame, must be valid
336  * @param sharedAnyCameraB The second camera that produced the observation in the current frame, must be valid
337  * @param world_T_device The transformation from the current frame that maps points in the device coordinate system points to world points, must be valid
338  * @param device_T_cameraA The transformation from the current frame that converts points in the coordinate systems of the first camera to device coordinates, must be valid
339  * @param device_T_cameraB The transformation from the current frame that converts points in the coordinate systems of the first camera to device coordinates, must be valid
340  * @param previousFramePyramidA The first image pyramid from the previous frame, must be valid
341  * @param previousFramePyramidB The second image pyramid from the previous frame, must be valid
342  * @param framePyramidA The first image pyramid from the current frame, must be valid
343  * @param framePyramidB The second image pyramid from the current frame, must be valid
344  * @param trackingTimestamp The time stamp that will be attributed to the current tracking attempt, must be valid
345  * @param trackedCode The code that will be tracked. This instance will be updated by this function, must be valid
346  * @return True if the code was successfully tracked from the previous to the current frame, otherwise false
347  */
348  static bool trackQRCode(const SharedAnyCamera& previousSharedAnyCameraA, const SharedAnyCamera& previousSharedAnyCameraB, const HomogenousMatrix4& previousWorld_T_device, const HomogenousMatrix4& previousDevice_T_cameraA, const HomogenousMatrix4& previousDevice_T_cameraB, const SharedAnyCamera& sharedAnyCameraA, const SharedAnyCamera& sharedAnyCameraB, const HomogenousMatrix4& world_T_device, const HomogenousMatrix4& device_T_cameraA, const HomogenousMatrix4& device_T_cameraB, const CV::FramePyramid& previousFramePyramidA, const CV::FramePyramid& previousFramePyramidB, const CV::FramePyramid& framePyramidA, const CV::FramePyramid& framePyramidB, const Timestamp& trackingTimestamp, TrackedQRCode& trackedCode);
349 
350  /**
351  * Checks if a specified code is already stored in the database of tracked QR codes.
352  * @param trackedQRCodesMap The map containing all currently tracked QR codes.
353  * @param code The code for which will be searched for in the database, must be valid.
354  * @param world_T_code The 6DOF pose of the code that will be searched for, must be valid.
355  * @param codeSize The size of the code in the physical world, range: (0, infinity)
356  * @param objectId The returning object ID of the code that is identical to the specified one and which already tracked, will `QRCodeTracker3D::invalidObjectId()` if this function return `false`.
357  * @return True the specified code is already tracked, otherwise false.
358  */
359  static bool isAlreadyTracked(const TrackedQRCodesMap& trackedQRCodesMap, const CV::Detector::QRCodes::QRCode& code, const HomogenousMatrix4& world_T_code, const Scalar codeSize, ObjectId& objectId);
360 
361  /**
362  * Creates objects points for a code that can be used for tracking
363  * @param code The code for which the tracking object points will be generated, must be valid
364  * @param codeSize The (display) size of the code in the real world (in meters), range: (0, infinity)
365  * @return The object points, will be empty on failure
366  */
368 
369  /**
370  * Creates the object-image point pairs that can be used for tracking
371  * @param sharedAnyCamera The camera that produced the observation in the frame, must be valid
372  * @param yFrame The frame which contains the image of the code, must be valid
373  * @param world_T_camera The 6DOF pose of the camera in world coordinates, must be valid
374  * @param world_T_code The 6DOF pose of the code that will be used to project the code, must be valid
375  * @param refineCorners True, a subpixel refinement will be applied to the image points, otherwise the points will be used as-is
376  * @param potentialObjectPoints The object points that will considered, must be valid
377  * @param objectPoints The resulting object points (a true subset of `potentialObjectPoints`), size is identical to that of `imagePoints`
378  * @param imagePoints The resulting image points that correspond to the object points, size is identical to that of `objectPoints`
379  * @return True if the point pairs have been created, otherwise false
380  * @sa createTrackingObjectPoints()
381  */
382  static bool createTrackingImagePoints(const SharedAnyCamera& sharedAnyCamera, const Frame& yFrame, const HomogenousMatrix4& world_T_camera, const HomogenousMatrix4& world_T_code, const bool refineCorners, const Geometry::ObjectPoints& potentialObjectPoints, Geometry::ObjectPoints& objectPoints, Geometry::ImagePoints& imagePoints);
383 
384  /**
385  * Returns an invalid map for tracked code
386  * @return The invalid map
387  */
389 
390  /**
391  * Disabled copy constructor.
392  */
394 
395  /**
396  * Disabled assign operator.
397  * @return The reference to this object
398  */
400 
401  protected:
402 
403  /// The function pointer to the function that provides new 6DOF detections of QR codes.
405 
406  /// The function pointer that is called in the event a new QR code is detected for the first time.
407  CallbackNewQRCode callbackNewQRCode_ = nullptr;
408 
409  /// The tracking parameters.
411 
412  /// The database of all tracked QR codes.
414 
415  /// The counter that is used for the assignment of ID to new codes.
416  ObjectId objectIdCounter_ = 0u;
417 
418  /// The counter for frames that have been processed.
419  unsigned int frameCounter_ = 0u;
420 
421  /// The cameras from the previous frame/time step.
423 
424  /// The frames (frame pyramids) from the previous time step.
425  std::vector<CV::FramePyramid> previousFramePyramids_;
426 
427  /// The device poses from the previous time step.
428  HomogenousMatrix4 previousWorld_T_device_ = HomogenousMatrix4(false);
429 
430  /// The camera poses from the previous time step.
432 
433  /// Will disable tracking and run detection only; will also report back 2D codes if a 6-DOF pose is not available.
434  bool forceDetectionOnlyAndAllow2DCodes_ = false;
435 };
436 
438 {
439  return code_;
440 }
441 
443 {
444  return world_T_code_;
445 }
446 
448 {
449  return codeSize_;
450 }
451 
453 {
454  return trackingState_;
455 }
456 
458 {
459  return trackingTimestamp_;
460 }
461 
463 {
464  return code_.isValid() && world_T_code_.isValid() && codeSize_ > Scalar(0) && trackingState_ != TS_UNKNOWN_STATE && trackingTimestamp_.isValid() && trackingObjectPoints_.size() >= 3;
465 }
466 
468 {
469  return trackingObjectPoints_;
470 }
471 
472 void QRCodeTracker3D::TrackedQRCode::updateTrackingPose(HomogenousMatrix4&& world_T_code, const Scalar codeSize, const Timestamp trackingTimestamp)
473 {
474  if (world_T_code.isValid() && codeSize > Scalar(0) && trackingTimestamp.isValid() && (!trackingTimestamp_.isValid() || trackingTimestamp >= trackingTimestamp_))
475  {
476  world_T_code_ = std::move(world_T_code);
477  codeSize_ = codeSize;
478  trackingTimestamp_ = trackingTimestamp;
479 
480  trackingState_ = TS_TRACKING;
481  }
482  else
483  {
484  Log::error() << "Failed to updated the tracking pose!";
485  ocean_assert(false && "Failed to updated the tracking pose!");
486  }
487 }
488 
490 {
491  // world_T_code_, codeSize_ - not invalidating since they could still be useful
492  trackingState_ = TS_LOST;
493 }
494 
496 {
497  return observationHistories_;
498 }
499 
501 {
503 }
504 
505 } // namespace QRCodes
506 
507 } // namespace Tracking
508 
509 } // namespace Ocean
This class implements a 6-DOF detector for QR codes.
Definition: QRCodeDetector3D.h:41
static bool detectQRCodesWithPyramids(const SharedAnyCameras &sharedAnyCameras, const Frames &yFrames, const HomogenousMatrix4 &world_T_device, const HomogenousMatrices4 &device_T_cameras, QRCodes &codes, HomogenousMatrices4 &world_T_codes, Scalars &codeSizes, Worker *worker=nullptr, const bool allow2DCodes=false)
Detects QR codes their 6-DOF poses in two synchronized 8-bit grayscale images.
Definition of a QR code.
Definition: QRCode.h:35
This class implements a frame pyramid.
Definition: FramePyramid.h:37
This class implements Ocean's image class.
Definition: Frame.h:1792
static MessageObject error()
Returns the message for error messages.
Definition: Messenger.h:1074
static constexpr T maxValue()
Returns the max scalar value.
Definition: Numeric.h:3244
This class implements a timestamp.
Definition: Timestamp.h:36
bool isValid() const
Returns whether the timestamp holds a valid time.
Definition: Timestamp.h:303
The definition of an observation history.
Definition: QRCodeTracker3D.h:218
SharedAnyCameras sharedAnyCameras_
The cameras what were used to compute these observations.
Definition: QRCodeTracker3D.h:272
void addObservation(const SharedAnyCamera &sharedAnyCamera, const HomogenousMatrix4 &world_T_camera, Geometry::ObjectPoints &&objectPoints, Geometry::ImagePoints &&imagePoints)
Adds a new observation to the observation history.
Geometry::ObjectPointGroups objectPointsGroups_
The object points of a code observation, one element per observation.
Definition: QRCodeTracker3D.h:278
HomogenousMatrices4 world_T_cameras_
The camera-to-world transformations, one element per observation.
Definition: QRCodeTracker3D.h:275
Geometry::ImagePointGroups imagePointsGroups_
The image points of a code observation, one element per observation.
Definition: QRCodeTracker3D.h:281
size_t removeObservations(const SharedAnyCamera &sharedAnyCamera, const HomogenousMatrix4 &world_T_code, const Scalar maxProjectionError, const Scalar maxOutliersPercent)
Removes all previous observations that are taken from a different pose than the specified one.
size_t size()
Return the number of observations stored in this history.
const Geometry::ObjectPoints & latestObjectPoints() const
Returns the latest group of object points.
const Geometry::ImagePoints & latestImagePoints() const
Returns the latest group of image points.
ObservationHistory()=default
Creates an empty observation history.
void clear()
Removes all stored observations from this history.
A tracked code.
Definition: QRCodeTracker3D.h:90
bool isValid() const
Returns if this tracked code is valid.
Definition: QRCodeTracker3D.h:462
TrackingState trackingState() const
Returns the tracking state of the tracked code.
Definition: QRCodeTracker3D.h:452
ObservationHistories & observationHistories()
Returns the list of observation histories of this code.
Definition: QRCodeTracker3D.h:495
const Timestamp & trackingTimestamp() const
Returns the time stamp of the moment when this code was tracked.
Definition: QRCodeTracker3D.h:457
Geometry::ObjectPoints trackingObjectPoints_
The object points that this code can be tracked with.
Definition: QRCodeTracker3D.h:206
TrackedQRCode(const CV::Detector::QRCodes::QRCode &code, const HomogenousMatrix4 &world_T_code, const Scalar codeSize, const Geometry::ObjectPoints &trackingObjectPoints, const TrackingState trackingState, const Timestamp trackingTimestamp)
Constructs a tracked code.
const Geometry::ObjectPoints & trackingObjectPoints() const
Returns the object points that are used to track this code.
Definition: QRCodeTracker3D.h:467
CV::Detector::QRCodes::QRCode code_
The tracked QR code.
Definition: QRCodeTracker3D.h:188
TrackedQRCode()=default
Constructs an invalid tracked code.
TrackedQRCode(CV::Detector::QRCodes::QRCode &&code, HomogenousMatrix4 &&world_T_code, const Scalar codeSize, Geometry::ObjectPoints &&trackingObjectPoints, const TrackingState trackingState, const Timestamp trackingTimestamp)
Constructs a tracked code.
const HomogenousMatrix4 & world_T_code() const
Returns the 6DOF pose of the tracked code.
Definition: QRCodeTracker3D.h:442
ObservationHistories observationHistories_
The observation histories of the tracked QR code. One observation history per camera.
Definition: QRCodeTracker3D.h:203
Scalar codeSize() const
Return the size of the code in the physical world.
Definition: QRCodeTracker3D.h:447
void updateTrackingPose(HomogenousMatrix4 &&world_T_code, const Scalar codeSize, const Timestamp trackingTimestamp)
Updates the 6DOF pose of the tracked code.
Definition: QRCodeTracker3D.h:472
const CV::Detector::QRCodes::QRCode & code() const
Returns the tracked code.
Definition: QRCodeTracker3D.h:437
void setTrackingLost()
Sets the tracking state to lost.
Definition: QRCodeTracker3D.h:489
This class implements a 6-DOF tracker for QR codes.
Definition: QRCodeTracker3D.h:32
QRCodeTracker3D(const QRCodeTracker3D &)=delete
Disabled copy constructor.
std::function< bool(const SharedAnyCameras &, const Frames &, const HomogenousMatrix4 &, const HomogenousMatrices4 &, CV::Detector::QRCodes::QRCodes &, HomogenousMatrices4 &, Scalars &, Worker *, const bool)> CallbackQRCodeDetection3D
Definition of a pointer to the function that provides new 6DOF detections of QR codes,...
Definition: QRCodeTracker3D.h:60
static bool isAlreadyTracked(const TrackedQRCodesMap &trackedQRCodesMap, const CV::Detector::QRCodes::QRCode &code, const HomogenousMatrix4 &world_T_code, const Scalar codeSize, ObjectId &objectId)
Checks if a specified code is already stored in the database of tracked QR codes.
static bool trackQRCode(const SharedAnyCamera &previousSharedAnyCameraA, const SharedAnyCamera &previousSharedAnyCameraB, const HomogenousMatrix4 &previousWorld_T_device, const HomogenousMatrix4 &previousDevice_T_cameraA, const HomogenousMatrix4 &previousDevice_T_cameraB, const SharedAnyCamera &sharedAnyCameraA, const SharedAnyCamera &sharedAnyCameraB, const HomogenousMatrix4 &world_T_device, const HomogenousMatrix4 &device_T_cameraA, const HomogenousMatrix4 &device_T_cameraB, const CV::FramePyramid &previousFramePyramidA, const CV::FramePyramid &previousFramePyramidB, const CV::FramePyramid &framePyramidA, const CV::FramePyramid &framePyramidB, const Timestamp &trackingTimestamp, TrackedQRCode &trackedCode)
Tracks a single QR code from one frame to the next.
static Geometry::ObjectPoints createTrackingObjectPoints(const CV::Detector::QRCodes::QRCode &code, const Scalar codeSize)
Creates objects points for a code that can be used for tracking.
HomogenousMatrices4 previousDevice_T_cameras_
The camera poses from the previous time step.
Definition: QRCodeTracker3D.h:431
bool forceDetectionOnlyAndAllow2DCodes_
Will disable tracking and run detection only; will also report back 2D codes if a 6-DOF pose is not a...
Definition: QRCodeTracker3D.h:434
static const TrackedQRCodesMap & invalidTrackedQRCodesMap()
Returns an invalid map for tracked code.
std::vector< ObservationHistory > ObservationHistories
Vector of observation histories.
Definition: QRCodeTracker3D.h:36
bool isForceDetectionOnlyAndAllow2DCodesEnabled() const
Returns if the tracker is in detection-only mode and will report 2D codes as well.
Definition: QRCodeTracker3D.h:500
TrackedQRCodesMap trackedQRCodesMap_
The database of all tracked QR codes.
Definition: QRCodeTracker3D.h:413
static constexpr ObjectId invalidObjectId()
Returns an invalid object ID.
uint32_t ObjectId
The unique ID of each tracked code.
Definition: QRCodeTracker3D.h:57
std::unordered_map< ObjectId, TrackedQRCode > TrackedQRCodesMap
The definition of map of tracked QR codes.
Definition: QRCodeTracker3D.h:210
TrackingState
Definition of tracking states.
Definition: QRCodeTracker3D.h:47
@ TS_UNKNOWN_STATE
Unknown/invalid tracking statue.
Definition: QRCodeTracker3D.h:49
@ TS_TRACKING
State for currently tracked codes.
Definition: QRCodeTracker3D.h:51
@ TS_LOST
State when tracking has been lost.
Definition: QRCodeTracker3D.h:53
const TrackedQRCodesMap & trackQRCodes(const SharedAnyCameras &sharedAnyCameras, const Frames &yFrames, const HomogenousMatrix4 &world_T_device, const HomogenousMatrices4 &device_T_cameras, Worker *worker=nullptr)
Tracks QR codes and their 6-DOF pose in two or more 8-bit grayscale images.
Parameters parameters_
The tracking parameters.
Definition: QRCodeTracker3D.h:410
QRCodeTracker3D()=default
Constructs a tracker instance.
QRCodeTracker3D(const Parameters &parameters, CallbackQRCodeDetection3D callbackQRCodeDetection3D=nullptr, CallbackNewQRCode callbackNewQRCode=nullptr, const bool forceDetectionOnlyAndAllow2DCodes=false)
Constructs a tracker instance with a specific detection function.
std::function< void(const CV::Detector::QRCodes::QRCode &, const HomogenousMatrix4 &, const Scalar, const ObjectId)> CallbackNewQRCode
Definition of a function pointer that is called in the event a new QR code is detected for the first ...
Definition: QRCodeTracker3D.h:63
static bool createTrackingImagePoints(const SharedAnyCamera &sharedAnyCamera, const Frame &yFrame, const HomogenousMatrix4 &world_T_camera, const HomogenousMatrix4 &world_T_code, const bool refineCorners, const Geometry::ObjectPoints &potentialObjectPoints, Geometry::ObjectPoints &objectPoints, Geometry::ImagePoints &imagePoints)
Creates the object-image point pairs that can be used for tracking.
std::vector< CV::FramePyramid > previousFramePyramids_
The frames (frame pyramids) from the previous time step.
Definition: QRCodeTracker3D.h:425
SharedAnyCameras previousSharedAnyCameras_
The cameras from the previous frame/time step.
Definition: QRCodeTracker3D.h:422
QRCodeTracker3D operator=(const QRCodeTracker3D &)=delete
Disabled assign operator.
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
std::vector< Frame > Frames
Definition of a vector holding padding frames.
Definition: Frame.h:1755
std::vector< ObjectPoint > ObjectPoints
Definition of a vector holding 3D object points.
Definition: geometry/Geometry.h:129
std::vector< ObjectPoints > ObjectPointGroups
Definition of a vector holding object points, so we have groups of object points.
Definition: geometry/Geometry.h:135
std::vector< ImagePoint > ImagePoints
Definition of a vector holding 2D image points.
Definition: geometry/Geometry.h:123
std::vector< ImagePoints > ImagePointGroups
Definition of a vector holding image points, so we have groups of image points.
Definition: geometry/Geometry.h:141
float Scalar
Definition of a scalar type.
Definition: Math.h:128
std::vector< HomogenousMatrix4 > HomogenousMatrices4
Definition of a vector holding HomogenousMatrix4 objects.
Definition: HomogenousMatrix4.h:73
std::shared_ptr< AnyCamera > SharedAnyCamera
Definition of a shared pointer holding an AnyCamera object with Scalar precision.
Definition: AnyCamera.h:60
std::vector< Scalar > Scalars
Definition of a vector holding Scalar objects.
Definition: Math.h:144
HomogenousMatrixT4< Scalar > HomogenousMatrix4
Definition of the HomogenousMatrix4 object, depending on the OCEAN_MATH_USE_SINGLE_PRECISION flag eit...
Definition: HomogenousMatrix4.h:37
SharedAnyCamerasT< Scalar > SharedAnyCameras
Definition of a vector holding AnyCamera objects.
Definition: AnyCamera.h:90
std::vector< QRCode > QRCodes
Definition of a vector of QR codes.
Definition: QRCode.h:25
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15
Definition of parameters that control the tracker.
Definition: QRCodeTracker3D.h:69