Monado OpenXR Runtime
Loading...
Searching...
No Matches
pose_optimize.hpp
Go to the documentation of this file.
1// Copyright 2015, Philipp Zabel
2// Copyright 2020-2023
3// Copyright 2026, Beyley Cardellio
4// SPDX-License-Identifier: BSL-1.0
5/*!
6 * @file
7 * @brief RANSAC PnP pose refinement
8 * @author Philipp Zabel <philipp.zabel@gmail.com>
9 * @author Jan Schmidt <jan@centricular.com>
10 * @author Beyley Cardellio <ep1cm1n10n123@gmail.com>
11 * @ingroup tracking
12 */
13
14#pragma once
15
16#include "xrt/xrt_defines.h"
17
19
21
22
23namespace xrt::tracking::constellation::optimizer {
24
25enum class PoseStateIndex : int
26{
27 // Pos
28 PosX = 0,
29 PosY = 1,
30 PosZ = 2,
31
32 // Quat (must match xrt_quat/Eigen ordering)
33 RotX = 3,
34 RotY = 4,
35 RotZ = 5,
36 RotW = 6,
37
38 NumIndices,
39};
40
41constexpr int kPoseStatePosStart = static_cast<int>(PoseStateIndex::PosX);
42constexpr int kPoseStateRotStart = static_cast<int>(PoseStateIndex::RotX);
43constexpr int kPoseStateSize = static_cast<int>(PoseStateIndex::NumIndices);
44
45enum class CovarianceIndex : int
46{
47 PosX = 0,
48 PosY = 1,
49 PosZ = 2,
50
51 RotX = 3,
52 RotY = 4,
53 RotZ = 5,
54
55 NumIndices,
56};
57
58constexpr int kPoseCovarianceSize = static_cast<int>(CovarianceIndex::NumIndices);
59
60// Same format as an Eigen::Matrix<double, 6, 6>.
61typedef double RawPoseCovarianceMatrix[kPoseCovarianceSize * kPoseCovarianceSize];
62
63/*!
64 * Does a pose optimization and RANSAC refinement on the given blobs and LED model, returning the optimized pose and
65 * covariance.
66 *
67 * @param log_level The logging level to use for debug output.
68 * @param params The camera model parameters.
69 * @param init_pose The initial pose estimate to start the optimization from.
70 * @param blobs The array of blobs to use for the optimization, will write to here to unmark outliers.
71 * @param num_blobs The number of blobs in the array.
72 * @param leds_model The LED model to use for the optimization.
73 * @param device_id The device ID to optimize the pose for.
74 * @param[out] out_pose The optimized pose will be written to this variable.
75 * @param[out] out_covariance The covariance of the final pose will be written to this variable, if not nullptr.
76 *
77 * @return true if the optimization was successful, false otherwise.
78 */
79bool
81 bool deterministic,
82 const camera_model &params,
83 xrt_pose init_pose,
84 t_blob *blobs,
85 uint32_t num_blobs,
87 t_constellation_device_id_t device_id,
88 xrt_pose &out_pose,
89 RawPoseCovarianceMatrix out_covariance);
90
91/*!
92 * Computes the covariance of a pose given the initial pose, blobs, and LED model.
93 *
94 * @param log_level The logging level to use for debug output.
95 * @param params The camera model parameters.
96 * @param init_pose The initial pose estimate to start the optimization from.
97 * @param blobs The array of blobs to use for the optimization.
98 * @param num_blobs The number of blobs in the array.
99 * @param leds_model The LED model to use for the optimization.
100 * @param device_id The device ID to compute the covariance for.
101 * @param[out] out_covariance The covariance of the final pose will be written to this variable.
102 *
103 * @return void
104 */
105void
107 const camera_model &params,
108 xrt_pose init_pose,
109 t_blob *blobs,
110 uint32_t num_blobs,
112 t_constellation_device_id_t device_id,
113 RawPoseCovarianceMatrix out_covariance);
114
115/*!
116 * Computes the radii and covariance orientation from the 3x3 position part of the pose covariance matrix
117 * (3x eigenvalue, so 99%-ish probability containment).
118 *
119 * @param raw_covariance The raw pose covariance matrix to compute the radii and orientation from.
120 * @param[out] radii The radii of the position covariance will be written to this variable.
121 * @param[out] Q_cam_cov The orientation of the covariance will be written to this variable.
122 */
123void
124covariancePositionRadius(const RawPoseCovarianceMatrix &raw_covariance, xrt_vec3 &radii, xrt_quat &Q_cam_cov);
125
126}; // namespace xrt::tracking::constellation::optimizer
Constellation tracker's camera model storage.
u_logging_level
Logging level enum.
Definition u_logging.h:45
bool optimizePose(u_logging_level log_level, bool deterministic, const camera_model &params, xrt_pose init_pose, t_blob *blobs, uint32_t num_blobs, t_constellation_tracker_led_model *leds_model, t_constellation_device_id_t device_id, xrt_pose &out_pose, RawPoseCovarianceMatrix out_covariance)
Does a pose optimization and RANSAC refinement on the given blobs and LED model, returning the optimi...
Definition pose_optimize.cpp:284
void computePoseCovariance(u_logging_level log_level, const camera_model &params, xrt_pose init_pose, t_blob *blobs, uint32_t num_blobs, t_constellation_tracker_led_model *leds_model, t_constellation_device_id_t device_id, RawPoseCovarianceMatrix out_covariance)
Computes the covariance of a pose given the initial pose, blobs, and LED model.
Definition pose_optimize.cpp:433
void covariancePositionRadius(const RawPoseCovarianceMatrix &raw_covariance, xrt_vec3 &radii, xrt_quat &Q_cam_cov)
Computes the radii and covariance orientation from the 3x3 position part of the pose covariance matri...
Definition pose_optimize.cpp:494
Definition camera_model.h:21
A blob is a 2d position in a camera sensor's view that is being tracked.
Definition t_constellation.h:51
The LED model is a series of points which define the real-world positions of all LEDs.
Definition t_constellation.h:311
A pose composed of a position and orientation.
Definition xrt_defines.h:522
A quaternion with single floats.
Definition xrt_defines.h:246
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.