Ocean
Loading...
Searching...
No Matches
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
13
15
17
18namespace Ocean
19{
20
21namespace Tracking
22{
23
24namespace QRCodes
25{
26
27/**
28 * This class implements a 6-DOF tracker for QR codes.
29 * @ingroup trackingqrcodes
30 */
31class OCEAN_TRACKING_QRCODES_EXPORT QRCodeTracker3D : public CV::Detector::QRCodes::QRCodeDetector3D
32{
33 protected:
34
35 /// Forward-declaration
37
38 /// Vector of observation histories
39 using ObservationHistories = std::vector<ObservationHistory>;
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 using ObjectId = uint32_t;
58
59 /// Definition of a pointer to the function that provides new 6DOF detections of QR codes, QRCodeDetector3D::detectQRCodes()
60 using CallbackQRCodeDetection3D = std::function<bool(const SharedAnyCameras&, const Frames&, const HomogenousMatrix4&, const HomogenousMatrices4&, CV::Detector::QRCodes::QRCodes&, HomogenousMatrices4&, Scalars&, Worker*, const bool, const bool)>;
61
62 /// Definition of a function pointer that is called in the event a new QR code is detected for the first time.
63 using CallbackNewQRCode = std::function<void(const CV::Detector::QRCodes::QRCode&, const HomogenousMatrix4&, const Scalar, const ObjectId)>;
64
65 /**
66 * Definition of parameters that control the tracker
67 */
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 /// True to additionally detect bright QR codes on a dark background.
86 bool detectInvertedReflectance_ = false;
87 };
88
89 /**
90 * A tracked code.
91 */
93 {
94 friend class QRCodeTracker3D;
95
96 public:
97
98 /**
99 * Constructs an invalid tracked code.
100 */
101 TrackedQRCode() = default;
102
103 /**
104 * Constructs a tracked code.
105 * @param code The code that is tracked, must be valid.
106 * @param world_T_code The 6DOF pose of the code mapping from object space to world space, must be valid.
107 * @param codeSize The size of the code in the physical world, in meters, range: (0, infinity)
108 * @param trackingObjectPoints The set of object points of this code that should be used for tracking, must have >= 3 elements
109 * @param trackingState The tracking state that this tracked code will be initialized with, must not be `TS_UNKNOWN_STATE`.
110 * @param trackingTimestamp The time at which the code was tracked, must be valid.
111 */
112 TrackedQRCode(CV::Detector::QRCodes::QRCode&& code, HomogenousMatrix4&& world_T_code, const Scalar codeSize, Vectors3&& trackingObjectPoints, const TrackingState trackingState, const Timestamp trackingTimestamp);
113
114 /**
115 * Constructs a tracked code.
116 * @param code The code that is tracked, must be valid.
117 * @param world_T_code The 6DOF pose of the code mapping from object space to world space, must be valid.
118 * @param codeSize The size of the code in the physical world, in meters, range: (0, infinity)
119 * @param trackingObjectPoints The set of object points of this code that should be used for tracking, must have >= 3 elements
120 * @param trackingState The tracking state that this tracked code will be initialized with, must not be `TS_UNKNOWN_STATE`.
121 * @param trackingTimestamp The time at which the code was tracked, must be valid.
122 */
123 TrackedQRCode(const CV::Detector::QRCodes::QRCode& code, const HomogenousMatrix4& world_T_code, const Scalar codeSize, const Vectors3& trackingObjectPoints, const TrackingState trackingState, const Timestamp trackingTimestamp);
124
125 /**
126 * Returns the tracked code.
127 * @return The code.
128 */
129 inline const CV::Detector::QRCodes::QRCode& code() const;
130
131 /**
132 * Returns the 6DOF pose of the tracked code.
133 * @return The 6DOF pose.
134 */
135 inline const HomogenousMatrix4& world_T_code() const;
136
137 /**
138 * Return the size of the code in the physical world.
139 * @return The size.
140 */
141 inline Scalar codeSize() const;
142
143 /**
144 * Returns the tracking state of the tracked code.
145 * @return The tracking state.
146 */
147 inline TrackingState trackingState() const;
148
149 /**
150 * Returns the time stamp of the moment when this code was tracked.
151 * @return The time stamp.
152 */
153 inline const Timestamp& trackingTimestamp() const;
154
155 /**
156 * Returns if this tracked code is valid.
157 * @return True, if so.
158 */
159 inline bool isValid() const;
160
161 /**
162 * Returns the object points that are used to track this code
163 * @return The object points
164 */
165 inline const Vectors3& trackingObjectPoints() const;
166
167 protected:
168
169 /**
170 * Updates the 6DOF pose of the tracked code.
171 * @param world_T_code The new 6DOF pose of the tracked code, must be valid.
172 * @param codeSize The new size estimate of the code, range: (0, infinity)
173 * @param trackingTimestamp The time stamp that the pose corresponds to, must be valid.
174 */
175 inline void updateTrackingPose(HomogenousMatrix4&& world_T_code, const Scalar codeSize, const Timestamp trackingTimestamp);
176
177 /**
178 * Sets the tracking state to lost.
179 */
180 inline void setTrackingLost();
181
182 /**
183 * Returns the list of observation histories of this code.
184 * @return The list of observation histories.
185 */
186 inline ObservationHistories& observationHistories();
187
188 protected:
189
190 /// The tracked QR code.
192
193 /// The 6DOF pose of the tracked QR code.
194 HomogenousMatrix4 world_T_code_ = HomogenousMatrix4(false);
195
196 /// The size of the code in the physical world .
197 Scalar codeSize_ = Scalar(0);
198
199 /// The tracking state of the tracked QR code.
200 TrackingState trackingState_ = TS_UNKNOWN_STATE;
201
202 /// The time when this code was tracked.
203 Timestamp trackingTimestamp_ = Timestamp(false);
204
205 /// The observation histories of the tracked QR code. One observation history per camera.
207
208 /// The object points that this code can be tracked with.
210 };
211
212 /// The definition of map of tracked QR codes.
213 using TrackedQRCodesMap = std::unordered_map<ObjectId, TrackedQRCode>;
214
215 protected:
216
217 /**
218 * The definition of an observation history.
219 */
221 {
222 public:
223
224 /**
225 * Creates an empty observation history.
226 */
228
229 /**
230 * Adds a new observation to the observation history.
231 * @param sharedAnyCamera The camera what was used to compute this observation, must be valid.
232 * @param world_T_camera The 6DOF pose of the camera in the world, must be valid.
233 * @param objectPoints The object points of the tracked QR code, must have at least 3 elements and the same size as `imagePoints`.
234 * @param imagePoints The image points of the tracked QR code, must have at least 3 elements and the size as `objectPoints`.
235 */
236 void addObservation(const SharedAnyCamera& sharedAnyCamera, const HomogenousMatrix4& world_T_camera, Vectors3&& objectPoints, Vectors2&& imagePoints);
237
238 /**
239 * Removes all previous observations that are taken from a different pose than the specified one.
240 * @param sharedAnyCamera The camera what was used to compute this observation, must be valid.
241 * @param world_T_code The transformation between code and world, must be valid.
242 * @param maxProjectionError The maximum projection error that different observations may have to be counted as identical, in pixels, range: (0, infinity)
243 * @param maxOutliersPercent The maximum amount of outliers (points) that different observations may have to be counted as identical, in percent, range: [0, 1]
244 */
245 size_t removeObservations(const SharedAnyCamera& sharedAnyCamera, const HomogenousMatrix4& world_T_code, const Scalar maxProjectionError, const Scalar maxOutliersPercent);
246
247 /**
248 * Returns the latest group of object points.
249 * @note Do not call this function if no observation history exists.
250 * @return The latest object points.
251 */
253
254 /**
255 * Returns the latest group of image points
256 * @note Do not call this function if no observation history exists.
257 * @return The latest image points.
258 */
260
261 /**
262 * Return the number of observations stored in this history.
263 * @return The number of observations
264 */
265 size_t size();
266
267 /**
268 * Removes all stored observations from this history.
269 */
270 void clear();
271
272 protected:
273
274 /// The cameras what were used to compute these observations.
276
277 /// The camera-to-world transformations, one element per observation.
279
280 /// The object points of a code observation, one element per observation.
282
283 /// The image points of a code observation, one element per observation.
285 };
286
287 public:
288
289 /**
290 * Constructs a tracker instance
291 */
292 QRCodeTracker3D() = default;
293
294 /**
295 * Constructs a tracker instance with a specific detection function
296 * @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.
297 * @param parameters The parameters that will be used for tracking, must be valid
298 * @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
299 * @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`
300 * @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.
301 */
302 QRCodeTracker3D(const Parameters& parameters, CallbackQRCodeDetection3D callbackQRCodeDetection3D = nullptr, CallbackNewQRCode callbackNewQRCode = nullptr, const bool forceDetectionOnlyAndAllow2DCodes = false);
303
304 /**
305 * Tracks QR codes and their 6-DOF pose in two or more 8-bit grayscale images
306 * @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.
307 * @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.
308 * @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
309 * @param world_T_device The transformation that maps points in the device coordinate system points to world points, must be valid
310 * @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
311 * @param worker Optional worker instance for parallelization
312 * @return The map containing all currently tracked QR code
313 */
314 const TrackedQRCodesMap& trackQRCodes(const SharedAnyCameras& sharedAnyCameras, const Frames& yFrames, const HomogenousMatrix4& world_T_device, const HomogenousMatrices4& device_T_cameras, Worker* worker = nullptr);
315
316 /**
317 * Returns if the tracker is in detection-only mode and will report 2D codes as well
318 * @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.
319 * @return True if so, otherwise false
320 */
321 inline bool isForceDetectionOnlyAndAllow2DCodesEnabled() const;
322
323 /**
324 * Returns an invalid object ID.
325 * @return An invalid object ID.
326 */
327 static constexpr ObjectId invalidObjectId();
328
329 protected:
330
331 /**
332 * Tracks a single QR code from one frame to the next
333 * @param previousSharedAnyCameraA The first camera that produced the observation in the previous frame, must be valid
334 * @param previousSharedAnyCameraB The second camera that produced the observation in the previous frame, must be valid
335 * @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
336 * @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
337 * @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
338 * @param sharedAnyCameraA The first camera that produced the observation in the current frame, must be valid
339 * @param sharedAnyCameraB The second camera that produced the observation in the current frame, must be valid
340 * @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
341 * @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
342 * @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
343 * @param previousFramePyramidA The first image pyramid from the previous frame, must be valid
344 * @param previousFramePyramidB The second image pyramid from the previous frame, must be valid
345 * @param framePyramidA The first image pyramid from the current frame, must be valid
346 * @param framePyramidB The second image pyramid from the current frame, must be valid
347 * @param trackingTimestamp The time stamp that will be attributed to the current tracking attempt, must be valid
348 * @param trackedCode The code that will be tracked. This instance will be updated by this function, must be valid
349 * @return True if the code was successfully tracked from the previous to the current frame, otherwise false
350 */
351 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);
352
353 /**
354 * Checks if a specified code is already stored in the database of tracked QR codes.
355 * @param trackedQRCodesMap The map containing all currently tracked QR codes.
356 * @param code The code for which will be searched for in the database, must be valid.
357 * @param world_T_code The 6DOF pose of the code that will be searched for, must be valid.
358 * @param codeSize The size of the code in the physical world, range: (0, infinity)
359 * @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`.
360 * @return True the specified code is already tracked, otherwise false.
361 */
362 static bool isAlreadyTracked(const TrackedQRCodesMap& trackedQRCodesMap, const CV::Detector::QRCodes::QRCode& code, const HomogenousMatrix4& world_T_code, const Scalar codeSize, ObjectId& objectId);
363
364 /**
365 * Creates objects points for a code that can be used for tracking
366 * @param code The code for which the tracking object points will be generated, must be valid
367 * @param codeSize The (display) size of the code in the real world (in meters), range: (0, infinity)
368 * @return The object points, will be empty on failure
369 */
371
372 /**
373 * Creates the object-image point pairs that can be used for tracking
374 * @param sharedAnyCamera The camera that produced the observation in the frame, must be valid
375 * @param yFrame The frame which contains the image of the code, must be valid
376 * @param world_T_camera The 6DOF pose of the camera in world coordinates, must be valid
377 * @param world_T_code The 6DOF pose of the code that will be used to project the code, must be valid
378 * @param refineCorners True, a subpixel refinement will be applied to the image points, otherwise the points will be used as-is
379 * @param potentialObjectPoints The object points that will considered, must be valid
380 * @param objectPoints The resulting object points (a true subset of `potentialObjectPoints`), size is identical to that of `imagePoints`
381 * @param imagePoints The resulting image points that correspond to the object points, size is identical to that of `objectPoints`
382 * @return True if the point pairs have been created, otherwise false
383 * @sa createTrackingObjectPoints()
384 */
385 static bool createTrackingImagePoints(const SharedAnyCamera& sharedAnyCamera, const Frame& yFrame, const HomogenousMatrix4& world_T_camera, const HomogenousMatrix4& world_T_code, const bool refineCorners, const Vectors3& potentialObjectPoints, Vectors3& objectPoints, Vectors2& imagePoints);
386
387 /**
388 * Returns an invalid map for tracked code
389 * @return The invalid map
390 */
392
393 /**
394 * Disabled copy constructor.
395 */
397
398 /**
399 * Disabled assign operator.
400 * @return The reference to this object
401 */
403
404 protected:
405
406 /// The function pointer to the function that provides new 6DOF detections of QR codes.
407 CallbackQRCodeDetection3D callbackQRCodeDetection3D_ = CV::Detector::QRCodes::QRCodeDetector3D::detectQRCodesWithPyramids;
408
409 /// The function pointer that is called in the event a new QR code is detected for the first time.
410 CallbackNewQRCode callbackNewQRCode_ = nullptr;
411
412 /// The tracking parameters.
414
415 /// The database of all tracked QR codes.
417
418 /// The counter that is used for the assignment of ID to new codes.
419 ObjectId objectIdCounter_ = 0u;
420
421 /// The counter for frames that have been processed.
422 unsigned int frameCounter_ = 0u;
423
424 /// The cameras from the previous frame/time step.
426
427 /// The frames (frame pyramids) from the previous time step.
428 std::vector<CV::FramePyramid> previousFramePyramids_;
429
430 /// The device poses from the previous time step.
431 HomogenousMatrix4 previousWorld_T_device_ = HomogenousMatrix4(false);
432
433 /// The camera poses from the previous time step.
435
436 /// Will disable tracking and run detection only; will also report back 2D codes if a 6-DOF pose is not available.
437 bool forceDetectionOnlyAndAllow2DCodes_ = false;
438};
439
444
446{
447 return world_T_code_;
448}
449
451{
452 return codeSize_;
453}
454
456{
457 return trackingState_;
458}
459
461{
462 return trackingTimestamp_;
463}
464
466{
467 return code_.isValid() && world_T_code_.isValid() && codeSize_ > Scalar(0) && trackingState_ != TS_UNKNOWN_STATE && trackingTimestamp_.isValid() && trackingObjectPoints_.size() >= 3;
468}
469
471{
472 return trackingObjectPoints_;
473}
474
475void QRCodeTracker3D::TrackedQRCode::updateTrackingPose(HomogenousMatrix4&& world_T_code, const Scalar codeSize, const Timestamp trackingTimestamp)
476{
477 if (world_T_code.isValid() && codeSize > Scalar(0) && trackingTimestamp.isValid() && (!trackingTimestamp_.isValid() || trackingTimestamp >= trackingTimestamp_))
478 {
479 world_T_code_ = std::move(world_T_code);
480 codeSize_ = codeSize;
481 trackingTimestamp_ = trackingTimestamp;
482
483 trackingState_ = TS_TRACKING;
484 }
485 else
486 {
487 Log::error() << "Failed to updated the tracking pose!";
488 ocean_assert(false && "Failed to updated the tracking pose!");
489 }
490}
491
493{
494 // world_T_code_, codeSize_ - not invalidating since they could still be useful
495 trackingState_ = TS_LOST;
496}
497
502
507
508} // namespace QRCodes
509
510} // namespace Tracking
511
512} // namespace Ocean
This class implements a 6-DOF detector for QR codes.
Definition QRCodeDetector3D.h:41
Definition of a QR code.
Definition QRCode.h:35
This class implements a frame pyramid.
Definition FramePyramid.h:46
This class implements Ocean's image class.
Definition Frame.h:1969
static MessageObject error()
Returns the message for error messages.
Definition Messenger.h:1095
This class provides basic numeric functionalities.
Definition Numeric.h:57
This class implements a timestamp.
Definition Timestamp.h:64
bool isValid() const
Returns whether the timestamp holds a valid time.
Definition Timestamp.h:646
The definition of an observation history.
Definition QRCodeTracker3D.h:221
SharedAnyCameras sharedAnyCameras_
The cameras what were used to compute these observations.
Definition QRCodeTracker3D.h:275
void addObservation(const SharedAnyCamera &sharedAnyCamera, const HomogenousMatrix4 &world_T_camera, Vectors3 &&objectPoints, Vectors2 &&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:281
HomogenousMatrices4 world_T_cameras_
The camera-to-world transformations, one element per observation.
Definition QRCodeTracker3D.h:278
Geometry::ImagePointGroups imagePointsGroups_
The image points of a code observation, one element per observation.
Definition QRCodeTracker3D.h:284
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.
ObservationHistory()=default
Creates an empty observation history.
void clear()
Removes all stored observations from this history.
const Vectors2 & latestImagePoints() const
Returns the latest group of image points.
const Vectors3 & latestObjectPoints() const
Returns the latest group of object points.
A tracked code.
Definition QRCodeTracker3D.h:93
TrackedQRCode(const CV::Detector::QRCodes::QRCode &code, const HomogenousMatrix4 &world_T_code, const Scalar codeSize, const Vectors3 &trackingObjectPoints, const TrackingState trackingState, const Timestamp trackingTimestamp)
Constructs a tracked code.
bool isValid() const
Returns if this tracked code is valid.
Definition QRCodeTracker3D.h:465
TrackingState trackingState() const
Returns the tracking state of the tracked code.
Definition QRCodeTracker3D.h:455
ObservationHistories & observationHistories()
Returns the list of observation histories of this code.
Definition QRCodeTracker3D.h:498
const Timestamp & trackingTimestamp() const
Returns the time stamp of the moment when this code was tracked.
Definition QRCodeTracker3D.h:460
TrackedQRCode(CV::Detector::QRCodes::QRCode &&code, HomogenousMatrix4 &&world_T_code, const Scalar codeSize, Vectors3 &&trackingObjectPoints, const TrackingState trackingState, const Timestamp trackingTimestamp)
Constructs a tracked code.
CV::Detector::QRCodes::QRCode code_
The tracked QR code.
Definition QRCodeTracker3D.h:191
TrackedQRCode()=default
Constructs an invalid tracked code.
const HomogenousMatrix4 & world_T_code() const
Returns the 6DOF pose of the tracked code.
Definition QRCodeTracker3D.h:445
ObservationHistories observationHistories_
The observation histories of the tracked QR code. One observation history per camera.
Definition QRCodeTracker3D.h:206
Scalar codeSize() const
Return the size of the code in the physical world.
Definition QRCodeTracker3D.h:450
void updateTrackingPose(HomogenousMatrix4 &&world_T_code, const Scalar codeSize, const Timestamp trackingTimestamp)
Updates the 6DOF pose of the tracked code.
Definition QRCodeTracker3D.h:475
const CV::Detector::QRCodes::QRCode & code() const
Returns the tracked code.
Definition QRCodeTracker3D.h:440
void setTrackingLost()
Sets the tracking state to lost.
Definition QRCodeTracker3D.h:492
const Vectors3 & trackingObjectPoints() const
Returns the object points that are used to track this code.
Definition QRCodeTracker3D.h:470
Vectors3 trackingObjectPoints_
The object points that this code can be tracked with.
Definition QRCodeTracker3D.h:209
This class implements a 6-DOF tracker for QR codes.
Definition QRCodeTracker3D.h:32
QRCodeTracker3D(const QRCodeTracker3D &)=delete
Disabled copy constructor.
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.
HomogenousMatrices4 previousDevice_T_cameras_
The camera poses from the previous time step.
Definition QRCodeTracker3D.h:434
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:437
std::function< bool(const SharedAnyCameras &, const Frames &, const HomogenousMatrix4 &, const HomogenousMatrices4 &, CV::Detector::QRCodes::QRCodes &, HomogenousMatrices4 &, Scalars &, Worker *, const bool, const bool)> CallbackQRCodeDetection3D
Definition of a pointer to the function that provides new 6DOF detections of QR codes,...
Definition QRCodeTracker3D.h:60
bool isForceDetectionOnlyAndAllow2DCodesEnabled() const
Returns if the tracker is in detection-only mode and will report 2D codes as well.
Definition QRCodeTracker3D.h:503
std::unordered_map< ObjectId, TrackedQRCode > TrackedQRCodesMap
The definition of map of tracked QR codes.
Definition QRCodeTracker3D.h:213
TrackedQRCodesMap trackedQRCodesMap_
The database of all tracked QR codes.
Definition QRCodeTracker3D.h:416
static constexpr ObjectId invalidObjectId()
Returns an invalid object ID.
static Vectors3 createTrackingObjectPoints(const CV::Detector::QRCodes::QRCode &code, const Scalar codeSize)
Creates objects points for a code that can be used for tracking.
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
static const TrackedQRCodesMap & invalidTrackedQRCodesMap()
Returns an invalid map for tracked code.
std::vector< ObservationHistory > ObservationHistories
Vector of observation histories.
Definition QRCodeTracker3D.h:39
Parameters parameters_
The tracking parameters.
Definition QRCodeTracker3D.h:413
QRCodeTracker3D()=default
Constructs a tracker instance.
uint32_t ObjectId
The unique ID of each tracked code.
Definition QRCodeTracker3D.h:57
QRCodeTracker3D(const Parameters &parameters, CallbackQRCodeDetection3D callbackQRCodeDetection3D=nullptr, CallbackNewQRCode callbackNewQRCode=nullptr, const bool forceDetectionOnlyAndAllow2DCodes=false)
Constructs a tracker instance with a specific detection function.
std::vector< CV::FramePyramid > previousFramePyramids_
The frames (frame pyramids) from the previous time step.
Definition QRCodeTracker3D.h:428
SharedAnyCameras previousSharedAnyCameras_
The cameras from the previous frame/time step.
Definition QRCodeTracker3D.h:425
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.
QRCodeTracker3D operator=(const QRCodeTracker3D &)=delete
Disabled assign operator.
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 Vectors3 &potentialObjectPoints, Vectors3 &objectPoints, Vectors2 &imagePoints)
Creates the object-image point pairs that can be used for tracking.
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:1932
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< ImagePoints > ImagePointGroups
Definition of a vector holding image points, so we have groups of image points.
Definition geometry/Geometry.h:141
std::vector< Vector2 > Vectors2
Definition of a vector holding Vector2 objects.
Definition Vector2.h:64
float Scalar
Definition of a scalar type.
Definition Math.h:129
std::shared_ptr< AnyCamera > SharedAnyCamera
Definition of a shared pointer holding an AnyCamera object with Scalar precision.
Definition AnyCamera.h:61
std::vector< HomogenousMatrix4 > HomogenousMatrices4
Definition of a vector holding HomogenousMatrix4 objects.
Definition HomogenousMatrix4.h:73
std::vector< Vector3 > Vectors3
Definition of a vector holding Vector3 objects.
Definition Vector3.h:65
std::vector< Scalar > Scalars
Definition of a vector holding Scalar objects.
Definition Math.h:145
SharedAnyCamerasT< Scalar > SharedAnyCameras
Definition of a vector holding AnyCamera objects.
Definition AnyCamera.h:91
std::vector< QRCode > QRCodes
Definition of a vector of QR codes.
Definition QRCode.h:28
The namespace covering the entire Ocean framework.
Definition Accessor.h:15
Definition of parameters that control the tracker.
Definition QRCodeTracker3D.h:69