Monado OpenXR Runtime
Loading...
Searching...
No Matches
pose_metrics.h
Go to the documentation of this file.
1// Copyright 2020-2023 Jan Schmidt
2// Copyright 2025-2026 Beyley Cardellio
3// SPDX-License-Identifier: BSL-1.0
4/*!
5 * @file
6 * @brief Metrics for constellation tracking poses
7 * @author Jan Schmidt <jan@centricular.com>
8 * @author Beyley Cardellio <ep1cm1n10n123@gmail.com>
9 * @ingroup tracking
10 */
11
12#pragma once
13
14#include "xrt/xrt_defines.h"
15
17
18#include "camera_model.h"
19
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25#define MAX_OBJECT_LEDS 64
26
27#define WORST_REPROJECTION_ERROR 10.0
28//! Device origin poses closer than this are probably invalid solves.
29#define CLOSEST_ACCEPTABLE_POSE_M 0.05
30//! Poses farther away than this are definitely invalid solves.
31#define FARTHEST_ACCEPTABLE_POSE_M 15.0
32
34{
35 double left;
36 double top;
37 double right;
38 double bottom;
39};
40
41XRT_MAYBE_UNUSED static bool
42pose_rect_has_area(struct pose_rect *rect)
43{
44 return rect->left != rect->right && rect->top != rect->bottom;
45}
46
48{
49 //! A reasonable pose match - most LEDs matched to within a few pixels error
51 //! A strong pose match is a match with very low error
53 //! The position of the pose matched the prior well
55 //! The orientation of the pose matched the prior well
57 //! If a pose prior was supplied when calculating the score, then rot/trans_error are set
59 //! The LED IDs on the blobs all matched the LEDs we thought (or were unassigned)
61 /*!
62 * Set when the pose cannot explain the device entirely on it's own. One case is when too few blobs matched for
63 * the reprojection error to say anything about the fit, a P3P solve or fewer. Such a solve reproduces its own
64 * points by construction, so its error is near zero whether or not the pose is right.
65 *
66 * Another case this may be triggered is when the amount of blobs is too low for the LED model in question to be
67 * confident about a slow solve. See @ref t_constellation_tracker_led_model_match_parameters.
68 */
70};
71
72#define POSE_SET_FLAGS(score, f) ((score)->match_flags |= (f))
73#define POSE_CLEAR_FLAGS(score, f) ((score)->match_flags &= ~(f))
74#define POSE_HAS_FLAGS(score, f) (((score)->match_flags & (f)) == (f))
75
76#define POSE_CLEAR_VALID(score) POSE_CLEAR_FLAGS(score, POSE_MATCH_GOOD | POSE_MATCH_STRONG)
77
79{
80 enum pose_match_flags match_flags;
81
82 uint32_t matched_blobs;
83 uint32_t unmatched_blobs;
84 uint32_t visible_leds;
85
86 double reprojection_error;
87
88 //! Rotation error (compared to a prior)
90 //! Translation error (compared to a prior)
92};
93
95{
97 double led_radius_px; //< Expected max size of the LED in pixels at that distance
98 struct xrt_vec2 pos_px; //< Projected position of the LED (pixels)
99 struct xrt_vec3 pos_m; //< Projected physical position of the LED (metres)
100 double facing_dot; //< Dot product between LED and camera
101 struct t_blob *matched_blob;
102};
103
105{
106 struct pose_metrics_visible_led_info visible_leds[MAX_OBJECT_LEDS];
107 int num_visible_leds;
108
109 bool all_led_ids_matched;
110 uint32_t matched_blobs;
111 uint32_t unmatched_blobs;
112
113 double reprojection_error;
114 struct pose_rect bounds;
115
116 bool degenerate_solution;
117};
118
119void
120pose_metrics_match_pose_to_blobs(const struct xrt_pose *pose,
121 struct t_blob *blobs,
122 int num_blobs,
123 struct t_constellation_tracker_led_model *led_model,
124 t_constellation_device_id_t device_id,
125 struct camera_model *calib,
126 struct pose_metrics_blob_match_info *match_info);
127
128void
129pose_metrics_evaluate_pose(struct pose_metrics *score,
130 const struct xrt_pose *pose,
131 struct t_blob *blobs,
132 int num_blobs,
133 struct t_constellation_tracker_led_model *leds_model,
134 t_constellation_device_id_t device_id,
135 struct camera_model *calib,
136 struct pose_rect *out_bounds);
137
138void
139pose_metrics_evaluate_pose_with_prior(struct pose_metrics *score,
140 const struct xrt_pose *pose,
141 bool prior_must_match,
142 const struct xrt_pose *pose_prior,
143 const struct xrt_vec3 *pos_error_thresh,
144 const struct xrt_vec3 *rot_error_thresh,
145 struct t_blob *blobs,
146 int num_blobs,
147 struct t_constellation_tracker_led_model *led_model,
148 t_constellation_device_id_t device_id,
149 struct camera_model *calib,
150 struct pose_rect *out_bounds);
151
152/*!
153 * Compares whether new_score is a better pose than old_score.
154 *
155 * @param old_score The old score to compare against.
156 * @param new_score The new score to compare against the old score.
157 * @return true if the new score is a better pose than the old score, false otherwise.
158 */
159bool
160pose_metrics_score_is_better_pose(struct pose_metrics *old_score, struct pose_metrics *new_score);
161
162#ifdef __cplusplus
163}
164#endif
Constellation tracker's camera model storage.
pose_match_flags
Definition pose_metrics.h:48
@ POSE_MATCH_LED_IDS
The LED IDs on the blobs all matched the LEDs we thought (or were unassigned)
Definition pose_metrics.h:60
@ POSE_MATCH_DEGENERATE
Set when the pose cannot explain the device entirely on it's own.
Definition pose_metrics.h:69
@ POSE_MATCH_ORIENT
The orientation of the pose matched the prior well.
Definition pose_metrics.h:56
@ POSE_HAD_PRIOR
If a pose prior was supplied when calculating the score, then rot/trans_error are set.
Definition pose_metrics.h:58
@ POSE_MATCH_POSITION
The position of the pose matched the prior well.
Definition pose_metrics.h:54
@ POSE_MATCH_GOOD
A reasonable pose match - most LEDs matched to within a few pixels error.
Definition pose_metrics.h:50
@ POSE_MATCH_STRONG
A strong pose match is a match with very low error.
Definition pose_metrics.h:52
bool pose_metrics_score_is_better_pose(struct pose_metrics *old_score, struct pose_metrics *new_score)
Compares whether new_score is a better pose than old_score.
Definition pose_metrics.c:502
Definition camera_model.h:19
Definition pose_metrics.h:105
Definition pose_metrics.h:95
Definition pose_metrics.h:79
struct xrt_vec3 pos_error
Translation error (compared to a prior)
Definition pose_metrics.h:91
struct xrt_vec3 orient_error
Rotation error (compared to a prior)
Definition pose_metrics.h:89
Definition pose_metrics.h:34
A blob is a 2d position in a camera sensor's view that is being tracked.
Definition t_constellation.h:45
The LED model is a series of points which define the real-world positions of all LEDs.
Definition t_constellation.h:286
Definition t_constellation.h:253
A pose composed of a position and orientation.
Definition xrt_defines.h:513
A 2 element vector with single floats.
Definition xrt_defines.h:279
A 3 element vector with single floats.
Definition xrt_defines.h:310
Header defining the tracking system integration in Monado.
Common defines and enums for XRT.