47#include <opencv2/opencv.hpp>
48#include <onnxruntime_c_api.h>
54namespace xrt::tracking::hand::mercury {
56using namespace xrt::auxiliary::util;
58using namespace xrt::auxiliary::onnx;
60#define HG_TRACE(hgt, ...) U_LOG_IFL_T(hgt->log_level, __VA_ARGS__)
61#define HG_DEBUG(hgt, ...) U_LOG_IFL_D(hgt->log_level, __VA_ARGS__)
62#define HG_INFO(hgt, ...) U_LOG_IFL_I(hgt->log_level, __VA_ARGS__)
63#define HG_WARN(hgt, ...) U_LOG_IFL_W(hgt->log_level, __VA_ARGS__)
64#define HG_ERROR(hgt, ...) U_LOG_IFL_E(hgt->log_level, __VA_ARGS__)
66static constexpr uint16_t kDetectionInputSize = 160;
67static constexpr uint16_t kKeypointInputSize = 128;
69static constexpr uint16_t kKeypointOutputHeatmapSize = 22;
70static constexpr uint16_t kVisSpacerSize = 8;
72static const cv::Scalar RED(255, 30, 30);
73static const cv::Scalar YELLOW(255, 255, 0);
74static const cv::Scalar PINK(255, 0, 255);
75static const cv::Scalar GREEN(0, 255, 0);
77static const cv::Scalar colors[2] = {YELLOW, RED};
82 XRT_HAND_JOINT_THUMB_METACARPAL,
83 XRT_HAND_JOINT_THUMB_PROXIMAL,
84 XRT_HAND_JOINT_THUMB_DISTAL,
85 XRT_HAND_JOINT_THUMB_TIP,
88 XRT_HAND_JOINT_INDEX_METACARPAL,
89 XRT_HAND_JOINT_INDEX_PROXIMAL,
90 XRT_HAND_JOINT_INDEX_INTERMEDIATE,
91 XRT_HAND_JOINT_INDEX_DISTAL,
92 XRT_HAND_JOINT_INDEX_TIP,
95 XRT_HAND_JOINT_MIDDLE_METACARPAL,
96 XRT_HAND_JOINT_MIDDLE_PROXIMAL,
97 XRT_HAND_JOINT_MIDDLE_INTERMEDIATE,
98 XRT_HAND_JOINT_MIDDLE_DISTAL,
99 XRT_HAND_JOINT_MIDDLE_TIP,
102 XRT_HAND_JOINT_RING_METACARPAL,
103 XRT_HAND_JOINT_RING_PROXIMAL,
104 XRT_HAND_JOINT_RING_INTERMEDIATE,
105 XRT_HAND_JOINT_RING_DISTAL,
106 XRT_HAND_JOINT_RING_TIP,
109 XRT_HAND_JOINT_LITTLE_METACARPAL,
110 XRT_HAND_JOINT_LITTLE_PROXIMAL,
111 XRT_HAND_JOINT_LITTLE_INTERMEDIATE,
112 XRT_HAND_JOINT_LITTLE_DISTAL,
113 XRT_HAND_JOINT_LITTLE_TIP,
117namespace ROIProvenance {
136using hand21_2d = std::array<vec2_5, 21>;
140 Eigen::Quaternionf rot_quat = Eigen::Quaternionf::Identity();
141 float stereographic_radius = 0;
150 float *data =
nullptr;
151 int64_t dimensions[4];
152 size_t num_dimensions = 0;
154 OrtValue *tensor =
nullptr;
160 std::unique_ptr<OnnxWrapper> wrap = {};
162 std::vector<model_input_wrap> wraps = {};
171 ROIProvenance::ROIProvenance provenance;
178 bool hand_detection_confidence;
213 cv::Mat run_model_on_this;
214 cv::Mat debug_out_to_this;
226 float out_hand_confidence;
227 float hand_size_refinement_schedule_x = 0;
228 float hand_size_refinement_schedule_y = 0;
229 bool optimizing =
true;
258 float multiply_px_coord_for_undistort;
263 struct xrt_size calibration_one_view_size_px = {};
266 struct xrt_size last_frame_one_view_size_px = {};
278 xrt_pose hand_pose_camera_offset = {};
280 uint64_t current_frame_timestamp = {};
282 bool debug_scribble =
false;
284 char models_folder[1024];
296 bool hand_seen_before[2] = {
false,
false};
302 bool last_frame_hand_detected[2] = {
false,
false};
305 bool this_frame_hand_detected[2] = {
false,
false};
315 uint64_t hand_tracked_for_num_frames[2] = {0, 0};
319 Eigen::Array<float, 3, 21> pose_predicted_keypoints[2];
321 int detection_counter = 0;
324 float target_hand_size = STANDARD_HAND_SIZE;
331 void (*keypoint_estimation_run_func)(
void *);
357 int64_t *out_timestamp_ns);
382release_onnx_state(onnx_state *wrap);
390 Eigen::Array<float, 3, 21> &joints,
391 projection_instructions &out_instructions,
392 hand21_2d &out_hand);
396make_projection_instructions_angular(
xrt_vec3 direction_3d,
398 float angular_radius,
401 projection_instructions &out_instructions);
405 const projection_instructions &instructions,
406 cv::Mat &input_image,
407 cv::Mat *debug_image,
408 const cv::Scalar &boundary_color,
Stores some number of values in a ring buffer, overwriting the earliest-pushed-remaining element if o...
Definition u_template_historybuf.hpp:38
u_logging_level
Logging level enum.
Definition u_logging.h:45
@ U_LOGGING_INFO
Info messages: not very verbose, not indicating a problem.
Definition u_logging.h:48
xrt_hand_joint
Number of joints in a hand.
Definition xrt_defines.h:1442
Debug instrumentation for mercury_train or others to control hand tracking.
Public interface of Mercury hand tracking.
void run_keypoint_estimation(void *ptr)
Runs keypoint estimation, excpets ptr to be a keypoint_estimation_run_info *
Definition hg_model.cpp:950
void run_hand_detection(void *ptr)
Runs hand detection, expects ptr to be a hand_detection_run_info *
Definition hg_model.cpp:410
Random common stuff for Mercury kinematic optimizers.
Interface for Levenberg-Marquardt kinematic optimizer.
C interface to math library.
Interoperability helpers connecting internal math types and Eigen.
Wrapper header for <math.h> to ensure pi-related math constants are defined.
C++-only functionality in the Math helper library.
Definition m_documentation.hpp:15
onnxruntime wrapper objects and functions.
Definition hg_debug_instrumentation.hpp:23
Floating point calibration data for a single calibrated camera.
Definition t_camera_models.h:59
Synchronously processes frames and returns two hands.
Definition t_hand_tracking.h:120
Stereo camera calibration data to be given to trackers.
Definition t_tracking.h:261
Allows more safely to debug sink inputs and outputs.
Definition u_sink.h:214
A worker group where you submit tasks to.
Definition u_worker.h:102
A worker pool, can shared between multiple groups worker pool.
Definition u_worker.h:33
Definition hg_sync.hpp:132
Main class of Mercury hand tracking.
Definition hg_sync.hpp:249
Definition hg_sync.hpp:184
Definition hg_sync.hpp:170
Definition hg_sync.hpp:223
Definition hg_sync.hpp:200
Definition hg_sync.hpp:194
Definition lm_defines.hpp:528
Definition hg_sync.hpp:233
Definition hg_sync.hpp:159
Definition hg_sync.hpp:139
Basic frame data structure - holds a pointer to buffer.
Definition xrt_frame.h:25
Joint set type used for hand tracking.
Definition xrt_defines.h:1521
An object to push xrt_hand_masks_sample to.
Definition xrt_tracking.h:196
A pose composed of a position and orientation.
Definition xrt_defines.h:492
Image size.
Definition xrt_defines.h:436
A 2 element vector with single floats.
Definition xrt_defines.h:268
A 3 element vector with single floats.
Definition xrt_defines.h:289
Simple, untemplated, C, float-only, camera (un)projection functions for various camera models.
Hand tracking interfaces.
Basic logging functionality.
xrt_frame_sink converters and other helpers.
Ringbuffer implementation for keeping track of the past state of things.
Tracing support code, see Tracing support.
Worker and threading pool.
Common defines and enums for XRT.
Header defining the tracking system integration in Monado.