diff --git a/src/xrt/auxiliary/tracking/t_tracker_slam.cpp b/src/xrt/auxiliary/tracking/t_tracker_slam.cpp index ee1b6efcc..17610804c 100644 --- a/src/xrt/auxiliary/tracking/t_tracker_slam.cpp +++ b/src/xrt/auxiliary/tracking/t_tracker_slam.cpp @@ -1380,20 +1380,29 @@ receive_frame(TrackerSlam &t, struct xrt_frame *frame, uint32_t cam_index) default: SLAM_ERROR("Unknown image format"); return; } + xrt_hand_masks_sample hand_masks{}; { unique_lock lock(t.last_hand_masks_mutex); - for (auto &view : t.last_hand_masks.views) { - if (!view.enabled) { + hand_masks = t.last_hand_masks; + } + + auto &view = hand_masks.views[cam_index]; + std::vector masks; + if (view.enabled) { + for (auto &hand : view.hands) { + if (!hand.enabled) { continue; } + vit_mask_t mask{}; + mask.x = hand.rect.x; + mask.y = hand.rect.y; + mask.w = hand.rect.w; + mask.h = hand.rect.h; + masks.push_back(mask); + } - for (auto &hand : view.hands) { - if (!hand.enabled) { - continue; - } - // TODO@mateosss: add_mask(hand.rect); - } - }; + sample.mask_count = masks.size(); + sample.masks = masks.empty() ? nullptr : masks.data(); } { diff --git a/src/xrt/include/xrt/xrt_defines.h b/src/xrt/include/xrt/xrt_defines.h index ad9628c4a..2689faf65 100644 --- a/src/xrt/include/xrt/xrt_defines.h +++ b/src/xrt/include/xrt/xrt_defines.h @@ -391,6 +391,18 @@ struct xrt_rect struct xrt_size extent; }; +/*! + * Image rectangle + * + * @todo Unify xrt_rect and xrt_rect_f32 field names + * + * @ingroup xrt_iface math + */ +struct xrt_rect_f32 +{ + float x, y, w, h; +}; + /*! * Normalized image rectangle, coordinates and size in 0 .. 1 range. * diff --git a/src/xrt/include/xrt/xrt_tracking.h b/src/xrt/include/xrt/xrt_tracking.h index e7dc38162..b63b245f3 100644 --- a/src/xrt/include/xrt/xrt_tracking.h +++ b/src/xrt/include/xrt/xrt_tracking.h @@ -149,8 +149,8 @@ struct xrt_hand_masks_sample bool enabled; //!< Whether any hand mask for this camera is being reported struct xrt_hand_masks_sample_hand { - bool enabled; //!< Whether a mask for this hand is being reported - struct xrt_rect rect; //!< The mask itself in pixel coordinates + bool enabled; //!< Whether a mask for this hand is being reported + struct xrt_rect_f32 rect; //!< The mask itself in pixel coordinates } hands[2]; } views[XRT_TRACKING_MAX_SLAM_CAMS]; }; diff --git a/src/xrt/tracking/hand/mercury/hg_sync.cpp b/src/xrt/tracking/hand/mercury/hg_sync.cpp index d2cf25869..c21e2317b 100644 --- a/src/xrt/tracking/hand/mercury/hg_sync.cpp +++ b/src/xrt/tracking/hand/mercury/hg_sync.cpp @@ -572,12 +572,10 @@ predict_new_regions_of_interest(struct HandTracking *hgt) hroi.provenance = ROIProvenance::POSE_PREDICTION; hroi.found = true; - xrt_vec2 ¢er = hroi.center_px; - float &size = hroi.size_px; - masks_hand.rect.offset.w = int(center.x - size / 2); - masks_hand.rect.offset.h = int(center.y - size / 2); - masks_hand.rect.extent.w = int(size); - masks_hand.rect.extent.h = int(size); + const float SCALER = 1.25f; + float s = hroi.size_px * SCALER; + xrt_vec2 &c = hroi.center_px; + masks_hand.rect = xrt_rect_f32{c.x - s / 2, c.y - s / 2, s, s}; masks_hand.enabled = true; } else { hroi.found = false;