45#include <opencv2/opencv.hpp>
46#include <onnxruntime_c_api.h>
52namespace xrt::tracking::hand::mercury {
54using namespace xrt::auxiliary::util;
57#define HG_TRACE(hgt, ...) U_LOG_IFL_T(hgt->log_level, __VA_ARGS__)
58#define HG_DEBUG(hgt, ...) U_LOG_IFL_D(hgt->log_level, __VA_ARGS__)
59#define HG_INFO(hgt, ...) U_LOG_IFL_I(hgt->log_level, __VA_ARGS__)
60#define HG_WARN(hgt, ...) U_LOG_IFL_W(hgt->log_level, __VA_ARGS__)
61#define HG_ERROR(hgt, ...) U_LOG_IFL_E(hgt->log_level, __VA_ARGS__)
63static constexpr uint16_t kDetectionInputSize = 160;
64static constexpr uint16_t kKeypointInputSize = 128;
66static constexpr uint16_t kKeypointOutputHeatmapSize = 22;
67static constexpr uint16_t kVisSpacerSize = 8;
69static const cv::Scalar RED(255, 30, 30);
70static const cv::Scalar YELLOW(255, 255, 0);
71static const cv::Scalar PINK(255, 0, 255);
72static const cv::Scalar GREEN(0, 255, 0);
74static const cv::Scalar colors[2] = {YELLOW, RED};
79 XRT_HAND_JOINT_THUMB_METACARPAL,
80 XRT_HAND_JOINT_THUMB_PROXIMAL,
81 XRT_HAND_JOINT_THUMB_DISTAL,
82 XRT_HAND_JOINT_THUMB_TIP,
85 XRT_HAND_JOINT_INDEX_METACARPAL,
86 XRT_HAND_JOINT_INDEX_PROXIMAL,
87 XRT_HAND_JOINT_INDEX_INTERMEDIATE,
88 XRT_HAND_JOINT_INDEX_DISTAL,
89 XRT_HAND_JOINT_INDEX_TIP,
92 XRT_HAND_JOINT_MIDDLE_METACARPAL,
93 XRT_HAND_JOINT_MIDDLE_PROXIMAL,
94 XRT_HAND_JOINT_MIDDLE_INTERMEDIATE,
95 XRT_HAND_JOINT_MIDDLE_DISTAL,
96 XRT_HAND_JOINT_MIDDLE_TIP,
99 XRT_HAND_JOINT_RING_METACARPAL,
100 XRT_HAND_JOINT_RING_PROXIMAL,
101 XRT_HAND_JOINT_RING_INTERMEDIATE,
102 XRT_HAND_JOINT_RING_DISTAL,
103 XRT_HAND_JOINT_RING_TIP,
106 XRT_HAND_JOINT_LITTLE_METACARPAL,
107 XRT_HAND_JOINT_LITTLE_PROXIMAL,
108 XRT_HAND_JOINT_LITTLE_INTERMEDIATE,
109 XRT_HAND_JOINT_LITTLE_DISTAL,
110 XRT_HAND_JOINT_LITTLE_TIP,
114namespace ROIProvenance {
133using hand21_2d = std::array<vec2_5, 21>;
137 Eigen::Quaternionf rot_quat = Eigen::Quaternionf::Identity();
138 float stereographic_radius = 0;
147 float *data =
nullptr;
148 int64_t dimensions[4];
149 size_t num_dimensions = 0;
151 OrtValue *tensor =
nullptr;
157 const OrtApi *api =
nullptr;
158 OrtEnv *env =
nullptr;
160 OrtMemoryInfo *meminfo =
nullptr;
161 OrtSession *session =
nullptr;
163 std::vector<model_input_wrap> wraps = {};
172 ROIProvenance::ROIProvenance provenance;
179 bool hand_detection_confidence;
214 cv::Mat run_model_on_this;
215 cv::Mat debug_out_to_this;
227 float out_hand_confidence;
228 float hand_size_refinement_schedule_x = 0;
229 float hand_size_refinement_schedule_y = 0;
230 bool optimizing =
true;
259 float multiply_px_coord_for_undistort;
264 struct xrt_size calibration_one_view_size_px = {};
267 struct xrt_size last_frame_one_view_size_px = {};
279 xrt_pose hand_pose_camera_offset = {};
281 uint64_t current_frame_timestamp = {};
283 bool debug_scribble =
false;
285 char models_folder[1024];
297 bool hand_seen_before[2] = {
false,
false};
303 bool last_frame_hand_detected[2] = {
false,
false};
306 bool this_frame_hand_detected[2] = {
false,
false};
316 uint64_t hand_tracked_for_num_frames[2] = {0, 0};
320 Eigen::Array<float, 3, 21> pose_predicted_keypoints[2];
322 int detection_counter = 0;
325 float target_hand_size = STANDARD_HAND_SIZE;
332 void (*keypoint_estimation_run_func)(
void *);
358 int64_t *out_timestamp_ns);
369run_hand_detection(
void *ptr);
386 Eigen::Array<float, 3, 21> &joints,
388 hand21_2d &out_hand);
392make_projection_instructions_angular(
xrt_vec3 direction_3d,
394 float angular_radius,
402 cv::Mat &input_image,
403 cv::Mat *debug_image,
404 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:1412
Debug instrumentation for mercury_train or others to control hand tracking.
void make_projection_instructions(t_camera_model_params &dist, bool flip_after, float expand_val, float twist, Eigen::Array< float, 3, 21 > &joints, projection_instructions &out_instructions, hand21_2d &out_hand)
Definition hg_image_distorter.cpp:494
Public interface of Mercury hand tracking.
void run_keypoint_estimation(void *ptr)
Definition hg_model.cpp:637
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
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:211
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:129
Main class of Mercury hand tracking.
Definition hg_sync.hpp:250
static void cCallbackProcess(struct t_hand_tracking_sync *ht_sync, struct xrt_frame *left_frame, struct xrt_frame *right_frame, struct xrt_hand_joint_set *out_left_hand, struct xrt_hand_joint_set *out_right_hand, int64_t *out_timestamp_ns)
Definition hg_sync.cpp:700
Definition hg_sync.hpp:185
Definition hg_sync.hpp:171
Definition hg_sync.hpp:224
Definition hg_sync.hpp:201
Definition hg_sync.hpp:195
Definition lm_defines.hpp:528
Definition hg_sync.hpp:234
Definition hg_sync.hpp:156
Definition hg_sync.hpp:136
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:1491
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:479
Image size.
Definition xrt_defines.h:423
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.