The open source OpenXR runtime

t/slam: Add hand_masks sink

authored by

Mateo de Mayo and committed by
Simon Zeni
4cfe58a5 717336fa

+71 -3
+36 -3
src/xrt/auxiliary/tracking/t_tracker_slam.cpp
··· 264 264 struct xrt_frame_sink cam_sinks[XRT_TRACKING_MAX_SLAM_CAMS]; //!< Sends camera frames to the SLAM system 265 265 struct xrt_imu_sink imu_sink = {}; //!< Sends imu samples to the SLAM system 266 266 struct xrt_pose_sink gt_sink = {}; //!< Register groundtruth trajectory for stats 267 + struct xrt_hand_masks_sink hand_masks_sink = {}; //!< Register latest masks to ignore 268 + 267 269 bool submit; //!< Whether to submit data pushed to sinks to the SLAM tracker 268 270 uint32_t cam_count; //!< Number of cameras used for tracking 269 271 ··· 275 277 struct openvr_tracker *ovr_tracker; //!< OpenVR lighthouse tracker 276 278 277 279 // Used mainly for checking that the timestamps come in order 278 - timepoint_ns last_imu_ts; //!< Last received IMU sample timestamp 279 - vector<timepoint_ns> last_cam_ts; //!< Last received image timestamp per cam 280 + timepoint_ns last_imu_ts; //!< Last received IMU sample timestamp 281 + vector<timepoint_ns> last_cam_ts; //!< Last received image timestamp per cam 282 + struct xrt_hand_masks_sample last_hand_masks; //!< Last received hand masks info 283 + Mutex last_hand_masks_mutex; //!< Mutex for @ref last_hand_masks 280 284 281 285 // Prediction 282 286 ··· 1273 1277 xrt_sink_push_pose(t.euroc_recorder->gt, sample); 1274 1278 } 1275 1279 1280 + //! Receive and register masks to use in the next image 1281 + extern "C" void 1282 + t_slam_hand_mask_sink_push(struct xrt_hand_masks_sink *sink, struct xrt_hand_masks_sample *hand_masks) 1283 + { 1284 + XRT_TRACE_MARKER(); 1285 + 1286 + auto &t = *container_of(sink, TrackerSlam, hand_masks_sink); 1287 + unique_lock lock(t.last_hand_masks_mutex); 1288 + t.last_hand_masks = *hand_masks; 1289 + } 1290 + 1276 1291 //! Receive and send IMU samples to the external SLAM system 1277 1292 extern "C" void 1278 1293 t_slam_receive_imu(struct xrt_imu_sink *sink, struct xrt_imu_sample *s) ··· 1365 1380 default: SLAM_ERROR("Unknown image format"); return; 1366 1381 } 1367 1382 1368 - // TODO masks 1383 + { 1384 + unique_lock lock(t.last_hand_masks_mutex); 1385 + for (auto &view : t.last_hand_masks.views) { 1386 + if (!view.enabled) { 1387 + continue; 1388 + } 1389 + 1390 + for (auto &hand : view.hands) { 1391 + if (!hand.enabled) { 1392 + continue; 1393 + } 1394 + // TODO@mateosss: add_mask(hand.rect); 1395 + } 1396 + }; 1397 + } 1369 1398 1370 1399 { 1371 1400 XRT_TRACE_IDENT(slam_push); ··· 1551 1580 t.gt_sink.push_pose = t_slam_gt_sink_push; 1552 1581 t.sinks.gt = &t.gt_sink; 1553 1582 1583 + t.hand_masks_sink.push_hand_masks = t_slam_hand_mask_sink_push; 1584 + t.sinks.hand_masks = &t.hand_masks_sink; 1585 + 1554 1586 t.submit = config->submit_from_start; 1555 1587 t.cam_count = config->cam_count; 1556 1588 ··· 1563 1595 1564 1596 t.last_imu_ts = INT64_MIN; 1565 1597 t.last_cam_ts = vector<timepoint_ns>(t.cam_count, INT64_MIN); 1598 + t.last_hand_masks = xrt_hand_masks_sample{}; 1566 1599 1567 1600 t.pred_type = config->prediction; 1568 1601
+35
src/xrt/include/xrt/xrt_tracking.h
··· 140 140 }; 141 141 142 142 /*! 143 + * Masks (bounding boxes) of different hands from current views 144 + */ 145 + struct xrt_hand_masks_sample 146 + { 147 + struct xrt_hand_masks_sample_camera 148 + { 149 + bool enabled; //!< Whether any hand mask for this camera is being reported 150 + struct xrt_hand_masks_sample_hand 151 + { 152 + bool enabled; //!< Whether a mask for this hand is being reported 153 + struct xrt_rect rect; //!< The mask itself in pixel coordinates 154 + } hands[2]; 155 + } views[XRT_TRACKING_MAX_SLAM_CAMS]; 156 + }; 157 + 158 + /*! 143 159 * @interface xrt_imu_sink 144 160 * 145 161 * An object to send IMU samples to. ··· 168 184 }; 169 185 170 186 /*! 187 + * @interface xrt_hand_masks_sink 188 + * 189 + * An object to push @ref xrt_hand_masks_sample to. 190 + */ 191 + struct xrt_hand_masks_sink 192 + { 193 + void (*push_hand_masks)(struct xrt_hand_masks_sink *, struct xrt_hand_masks_sample *hand_masks); 194 + }; 195 + 196 + 197 + /*! 171 198 * Container of pointers to sinks that could be used for a SLAM system. Sinks 172 199 * are considered disabled if they are null. 173 200 */ ··· 177 204 struct xrt_frame_sink *cams[XRT_TRACKING_MAX_SLAM_CAMS]; 178 205 struct xrt_imu_sink *imu; 179 206 struct xrt_pose_sink *gt; //!< Can receive ground truth poses if available 207 + struct xrt_hand_masks_sink *hand_masks; 180 208 }; 181 209 182 210 /*! ··· 291 319 xrt_sink_push_pose(struct xrt_pose_sink *sink, struct xrt_pose_sample *sample) 292 320 { 293 321 sink->push_pose(sink, sample); 322 + } 323 + 324 + //! @public @memberof xrt_hand_masks_sink 325 + static inline void 326 + xrt_sink_push_hand_masks(struct xrt_hand_masks_sink *sink, struct xrt_hand_masks_sample *hand_masks) 327 + { 328 + sink->push_hand_masks(sink, hand_masks); 294 329 } 295 330 296 331 //! @public @memberof xrt_tracked_psmv