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_config_have.h"
17#include "xrt/xrt_defines.h"
18
20
22
23
24namespace xrt::tracking::constellation::optimizer {
25
26enum class PoseStateIndex : int
27{
28 // Pos
29 PosX = 0,
30 PosY = 1,
31 PosZ = 2,
32
33 // Quat (must match xrt_quat/Eigen ordering)
34 RotX = 3,
35 RotY = 4,
36 RotZ = 5,
37 RotW = 6,
38
39 NumIndices,
40};
41
42constexpr int kPoseStateSize = static_cast<int>(PoseStateIndex::NumIndices);
43
44enum class CovarianceIndex : int
45{
46 PosX = 0,
47 PosY = 1,
48 PosZ = 2,
49
50 RotX = 3,
51 RotY = 4,
52 RotZ = 5,
53
54 NumIndices,
55};
56
57constexpr int kPoseCovarianceSize = static_cast<int>(CovarianceIndex::NumIndices);
58
59// Same format as an Eigen::Matrix<double, 6, 6>.
60typedef double RawPoseCovarianceMatrix[kPoseCovarianceSize * kPoseCovarianceSize];
61
62/*!
63 * Does a pose optimization and RANSAC refinement on the given blobs and LED model, returning the optimized pose and
64 * covariance.
65 *
66 * @param log_level The logging level to use for debug output.
67 * @param params The camera model parameters.
68 * @param init_pose The initial pose estimate to start the optimization from.
69 * @param blobs The array of blobs to use for the optimization, will write to here to unmark outliers.
70 * @param num_blobs The number of blobs in the array.
71 * @param leds_model The LED model to use for the optimization.
72 * @param device_id The device ID to optimize the pose for.
73 * @param[out] out_pose The optimized pose will be written to this variable.
74 * @param[out] out_covariance The covariance of the final pose will be written to this variable, if not nullptr.
75 * @param[out] out_whitening The whitening matrix of the pose, must be non-nullptr if out_covariance is set.
76 *
77 * @return true if the optimization was successful, false otherwise.
78 */
79bool
81 bool deterministic,
82 const t_camera_model_params &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 RawPoseCovarianceMatrix out_whitening);
91
92/*!
93 * Computes the covariance of a pose given the initial pose, blobs, and LED model.
94 *
95 * @param log_level The logging level to use for debug output.
96 * @param params The camera model parameters.
97 * @param init_pose The initial pose estimate to start the optimization from.
98 * @param blobs The array of blobs to use for the optimization.
99 * @param num_blobs The number of blobs in the array.
100 * @param leds_model The LED model to use for the optimization.
101 * @param device_id The device ID to compute the covariance for.
102 * @param[out] out_covariance The covariance of the final pose will be written to this variable.
103 * @param[out] out_whitening The whitening matrix of the pose, must be non-nullptr if out_covariance is set.
104 *
105 * @return void
106 */
107void
109 const t_camera_model_params &params,
110 xrt_pose init_pose,
111 t_blob *blobs,
112 uint32_t num_blobs,
114 t_constellation_device_id_t device_id,
115 RawPoseCovarianceMatrix out_covariance,
116 RawPoseCovarianceMatrix out_whitening);
117
118/*!
119 * Computes the radii and covariance orientation from the 3x3 position part of the pose covariance matrix
120 * (3x eigenvalue, so 99%-ish probability containment).
121 *
122 * @param raw_covariance The raw pose covariance matrix to compute the radii and orientation from.
123 * @param[out] radii The radii of the position covariance will be written to this variable.
124 * @param[out] Q_cam_cov The orientation of the covariance will be written to this variable.
125 */
126void
127covariancePositionRadius(const RawPoseCovarianceMatrix &raw_covariance, xrt_vec3 &radii, xrt_quat &Q_cam_cov);
128
129}; // namespace xrt::tracking::constellation::optimizer
Constellation tracker's camera model storage.
u_logging_level
Logging level enum.
Definition u_logging.h:45
void computePoseCovariance(u_logging_level log_level, const t_camera_model_params &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, RawPoseCovarianceMatrix out_whitening)
Computes the covariance of a pose given the initial pose, blobs, and LED model.
Definition pose_optimize.cpp:652
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:723
bool optimizePose(u_logging_level log_level, bool deterministic, const t_camera_model_params &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, RawPoseCovarianceMatrix out_whitening)
Does a pose optimization and RANSAC refinement on the given blobs and LED model, returning the optimi...
Definition pose_optimize.cpp:496
A blob is a 2d position in a camera sensor's view that is being tracked.
Definition t_constellation.h:45
Floating point calibration data for a single calibrated camera.
Definition t_camera_models.h:62
The LED model is a series of points which define the real-world positions of all LEDs.
Definition t_constellation.h:286
A pose composed of a position and orientation.
Definition xrt_defines.h:513
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.