The open source OpenXR runtime

h/mercury: Push hand rect masks to the SLAM tracker sinks

authored by

Mateo de Mayo and committed by
Simon Zeni
e79d2d39 4cfe58a5

+68 -16
+2 -2
src/xrt/drivers/ht/ht_driver.c
··· 234 234 int 235 235 ht_device_create(struct xrt_frame_context *xfctx, 236 236 struct t_stereo_camera_calibration *calib, 237 - struct t_camera_extra_info extra_camera_info, 237 + struct t_hand_tracking_create_info create_info, 238 238 struct xrt_slam_sinks **out_sinks, 239 239 struct xrt_device **out_device) 240 240 { ··· 254 254 return -1; 255 255 } 256 256 257 - sync = t_hand_tracking_sync_mercury_create(calib, extra_camera_info, path); 257 + sync = t_hand_tracking_sync_mercury_create(calib, create_info, path); 258 258 259 259 struct ht_device *htd = ht_device_create_common(calib, false, xfctx, sync); 260 260
+3 -1
src/xrt/drivers/ht/ht_interface.h
··· 16 16 #include "tracking/t_tracking.h" 17 17 #include "tracking/t_hand_tracking.h" 18 18 #include "xrt/xrt_prober.h" 19 + #include "xrt/xrt_tracking.h" 19 20 20 21 21 22 #ifdef __cplusplus ··· 36 37 * 37 38 * @param xfctx Frame context to attach the tracker to 38 39 * @param calib Calibration struct for stereo camera 40 + * @param create_info Additional creation options 39 41 * @param out_sinks Sinks to stream camera data to 40 42 * @param out_device Newly created hand tracker "device" 41 43 * @return int 0 on success ··· 43 45 int 44 46 ht_device_create(struct xrt_frame_context *xfctx, 45 47 struct t_stereo_camera_calibration *calib, 46 - struct t_camera_extra_info extra_camera_info, 48 + struct t_hand_tracking_create_info create_info, 47 49 struct xrt_slam_sinks **out_sinks, 48 50 struct xrt_device **out_device); 49 51
+5 -2
src/xrt/drivers/rift_s/rift_s_tracker.c
··· 252 252 extra_camera_info.views[0].camera_orientation = CAMERA_ORIENTATION_90; 253 253 extra_camera_info.views[1].camera_orientation = CAMERA_ORIENTATION_90; 254 254 255 + // TODO@mateosss: Use proper masks_sink in all drivers and not null 256 + struct t_hand_tracking_create_info create_info = {.cams_info = extra_camera_info, .masks_sink = NULL}; 257 + 255 258 int create_status = ht_device_create(xfctx, // 256 259 t->stereo_calib, // 257 - extra_camera_info, 258 - &sinks, // 260 + create_info, // 261 + &sinks, // 259 262 &device); 260 263 if (create_status != 0) { 261 264 return create_status;
+7 -2
src/xrt/drivers/wmr/wmr_hmd.c
··· 1651 1651 static int 1652 1652 wmr_hmd_hand_track(struct wmr_hmd *wh, 1653 1653 struct t_stereo_camera_calibration *stereo_calib, 1654 + struct xrt_hand_masks_sink *masks_sink, 1654 1655 struct xrt_slam_sinks **out_sinks, 1655 1656 struct xrt_device **out_device) 1656 1657 { ··· 1674 1675 1675 1676 //!@todo Turning it off is okay for now, but we should plug metric_radius (or whatever it's called) in, at some 1676 1677 //! point. 1678 + // TODO@mateosss: do it now 1677 1679 extra_camera_info.views[0].boundary_type = HT_IMAGE_BOUNDARY_NONE; 1678 1680 extra_camera_info.views[1].boundary_type = HT_IMAGE_BOUNDARY_NONE; 1681 + 1682 + struct t_hand_tracking_create_info create_info = {.cams_info = extra_camera_info, .masks_sink = masks_sink}; 1679 1683 1680 1684 int create_status = ht_device_create(&wh->tracking.xfctx, // 1681 1685 stereo_calib, // 1682 - extra_camera_info, // 1686 + create_info, // 1683 1687 &sinks, // 1684 1688 &device); 1685 1689 if (create_status != 0) { ··· 1819 1823 // Initialize hand tracker 1820 1824 struct xrt_slam_sinks *hand_sinks = NULL; 1821 1825 struct xrt_device *hand_device = NULL; 1826 + struct xrt_hand_masks_sink *masks_sink = slam_sinks->hand_masks; 1822 1827 if (wh->tracking.hand_enabled) { 1823 - int hand_status = wmr_hmd_hand_track(wh, stereo_calib, &hand_sinks, &hand_device); 1828 + int hand_status = wmr_hmd_hand_track(wh, stereo_calib, masks_sink, &hand_sinks, &hand_device); 1824 1829 if (hand_status != 0 || hand_sinks == NULL || hand_device == NULL) { 1825 1830 WMR_WARN(wh, "Unable to setup the hand tracker"); 1826 1831 return false;
+9
src/xrt/include/tracking/t_hand_tracking.h
··· 105 105 }; 106 106 107 107 /*! 108 + * Creation info for the creation of a hand tracker 109 + */ 110 + struct t_hand_tracking_create_info 111 + { 112 + struct t_camera_extra_info cams_info; //!< Extra camera info 113 + struct xrt_hand_masks_sink *masks_sink; //!< Optional sink to stream hand bounding boxes to 114 + }; 115 + 116 + /*! 108 117 * Synchronously processes frames and returns two hands. 109 118 */ 110 119 struct t_hand_tracking_sync
+3 -1
src/xrt/state_trackers/gui/gui_scene_hand_tracking_demo.c
··· 77 77 extra_camera_info.views[1].boundary_type = HT_IMAGE_BOUNDARY_NONE; 78 78 extra_camera_info.views[1].camera_orientation = CAMERA_ORIENTATION_0; 79 79 80 + struct t_hand_tracking_create_info create_info = {.cams_info = extra_camera_info, .masks_sink = NULL}; 81 + 80 82 int create_status = ht_device_create( // 81 83 &usysd->xfctx, // 82 84 calib, // 83 - extra_camera_info, // 85 + create_info, // 84 86 &hand_sinks, // 85 87 &ht_dev); // 86 88 t_stereo_camera_calibration_reference(&calib, NULL);
+3 -1
src/xrt/targets/common/target_builder_lighthouse.c
··· 233 233 info.views[0].boundary.circle.normalized_radius = 0.55; 234 234 info.views[1].boundary.circle.normalized_radius = 0.55; 235 235 236 + struct t_hand_tracking_create_info create_info = {.cams_info = info, .masks_sink = NULL}; 237 + 236 238 struct xrt_device *ht_device = NULL; 237 239 int create_status = ht_device_create( // 238 240 xfctx, // 239 241 stereo_calib, // 240 - info, // 242 + create_info, // 241 243 &sinks, // 242 244 &ht_device); 243 245 if (create_status != 0) {
+3 -1
src/xrt/targets/common/target_builder_north_star.c
··· 311 311 extra_camera_info.views[0].boundary_type = HT_IMAGE_BOUNDARY_NONE; 312 312 extra_camera_info.views[1].boundary_type = HT_IMAGE_BOUNDARY_NONE; 313 313 314 + struct t_hand_tracking_create_info create_info = {.cams_info = extra_camera_info, .masks_sink = NULL}; 315 + 314 316 int create_status = ht_device_create( // 315 317 xfctx, // 316 318 calib, // 317 - extra_camera_info, // 319 + create_info, // 318 320 &hand_sinks, // 319 321 out_hand_device); // 320 322 t_stereo_camera_calibration_reference(&calib, NULL);
+1 -1
src/xrt/tracking/hand/mercury/hg_interface.h
··· 23 23 */ 24 24 struct t_hand_tracking_sync * 25 25 t_hand_tracking_sync_mercury_create(struct t_stereo_camera_calibration *calib, 26 - struct t_camera_extra_info extra_camera_info, 26 + struct t_hand_tracking_create_info create_info, 27 27 const char *models_folder); 28 28 29 29 #ifdef __cplusplus
+30 -5
src/xrt/tracking/hand/mercury/hg_sync.cpp
··· 11 11 12 12 #include "hg_sync.hpp" 13 13 #include "hg_image_math.inl" 14 + #include "tracking/t_hand_tracking.h" 14 15 #include "util/u_box_iou.hpp" 15 16 #include "util/u_hand_tracking.h" 16 17 #include "math/m_vec2.h" 17 18 #include "util/u_misc.h" 19 + #include "xrt/xrt_defines.h" 18 20 #include "xrt/xrt_frame.h" 21 + #include "xrt/xrt_tracking.h" 19 22 20 23 21 24 #include <numeric> ··· 509 512 predict_new_regions_of_interest(struct HandTracking *hgt) 510 513 { 511 514 515 + xrt_hand_masks_sample masks{}; // Zero initialization 516 + 512 517 for (int hand_idx = 0; hand_idx < 2; hand_idx++) { 513 518 // If we don't have the past two frames, this code doesn't do what we want. 514 519 // If we only have *one* frame, we just reuse the same bounding box and hope the hand ··· 557 562 num_outside); 558 563 559 564 for (int view_idx = 0; view_idx < 2; view_idx++) { 565 + hand_region_of_interest &hroi = hgt->views[view_idx].regions_of_interest_this_frame[hand_idx]; 566 + auto &masks_view = masks.views[view_idx]; 567 + auto &masks_hand = masks_view.hands[hand_idx]; 568 + 569 + masks_view.enabled = true; 570 + 560 571 if (num_outside[view_idx] < hgt->tuneable_values.max_num_outside_view) { 561 - hgt->views[view_idx].regions_of_interest_this_frame[hand_idx].provenance = 562 - ROIProvenance::POSE_PREDICTION; 563 - hgt->views[view_idx].regions_of_interest_this_frame[hand_idx].found = true; 572 + hroi.provenance = ROIProvenance::POSE_PREDICTION; 573 + hroi.found = true; 564 574 575 + xrt_vec2 &center = hroi.center_px; 576 + float &size = hroi.size_px; 577 + masks_hand.rect.offset.w = int(center.x - size / 2); 578 + masks_hand.rect.offset.h = int(center.y - size / 2); 579 + masks_hand.rect.extent.w = int(size); 580 + masks_hand.rect.extent.h = int(size); 581 + masks_hand.enabled = true; 565 582 } else { 566 - hgt->views[view_idx].regions_of_interest_this_frame[hand_idx].found = false; 583 + hroi.found = false; 584 + masks_hand.enabled = false; 567 585 } 568 586 } 587 + } 588 + 589 + if (hgt->hand_masks_sink != NULL) { 590 + xrt_sink_push_hand_masks(hgt->hand_masks_sink, &masks); 569 591 } 570 592 } 571 593 ··· 1070 1092 1071 1093 extern "C" t_hand_tracking_sync * 1072 1094 t_hand_tracking_sync_mercury_create(struct t_stereo_camera_calibration *calib, 1073 - struct t_camera_extra_info extra_camera_info, 1095 + struct t_hand_tracking_create_info create_info, 1074 1096 const char *models_folder) 1075 1097 { 1076 1098 XRT_TRACE_MARKER(); ··· 1095 1117 hgt->views[0].hgt = hgt; 1096 1118 hgt->views[1].hgt = hgt; // :) 1097 1119 1120 + hgt->hand_masks_sink = create_info.masks_sink; 1121 + 1122 + struct t_camera_extra_info &extra_camera_info = create_info.cams_info; 1098 1123 hgt->views[0].camera_info = extra_camera_info.views[0]; 1099 1124 hgt->views[1].camera_info = extra_camera_info.views[1]; 1100 1125
+2
src/xrt/tracking/hand/mercury/hg_sync.hpp
··· 18 18 19 19 #include "xrt/xrt_defines.h" 20 20 #include "xrt/xrt_frame.h" 21 + #include "xrt/xrt_tracking.h" 21 22 22 23 #include "math/m_api.h" 23 24 #include "math/m_vec2.h" ··· 253 254 254 255 struct u_sink_debug debug_sink_ann = {}; 255 256 struct u_sink_debug debug_sink_model = {}; 257 + struct xrt_hand_masks_sink *hand_masks_sink; 256 258 257 259 float multiply_px_coord_for_undistort; 258 260