···1414#include "util/u_hand_tracking.h"
1515#include "math/m_vec2.h"
1616#include "util/u_misc.h"
1717+#include "xrt/xrt_frame.h"
171818191920#include <numeric>
···590591{
591592 this->base.process = &HandTracking::cCallbackProcess;
592593 this->base.destroy = &HandTracking::cCallbackDestroy;
593593- u_sink_debug_init(&this->debug_sink);
594594+ u_sink_debug_init(&this->debug_sink_ann);
595595+ u_sink_debug_init(&this->debug_sink_model);
594596}
595597596598HandTracking::~HandTracking()
597599{
598598- u_sink_debug_destroy(&this->debug_sink);
600600+ u_sink_debug_destroy(&this->debug_sink_ann);
601601+ u_sink_debug_destroy(&this->debug_sink_model);
602602+603603+ xrt_frame_reference(&this->visualizers.old_frame, NULL);
599604600605 release_onnx_wrap(&this->views[0].keypoint[0]);
601606 release_onnx_wrap(&this->views[0].keypoint[1]);
···672677 *out_timestamp_ns = hgt->current_frame_timestamp; // No filtering, fine to do this now. Also just a reminder
673678 // that this took you 2 HOURS TO DEBUG THAT ONE TIME.
674679675675- hgt->debug_scribble = u_sink_debug_is_active(&hgt->debug_sink);
680680+ hgt->debug_scribble =
681681+ u_sink_debug_is_active(&hgt->debug_sink_ann) && u_sink_debug_is_active(&hgt->debug_sink_model);
676682677683 cv::Mat debug_output = {};
678684 xrt_frame *debug_frame = nullptr;
···692698 hgt->views[0].debug_out_to_this = debug_output(cv::Rect(view_offsets[0], view_size));
693699 hgt->views[1].debug_out_to_this = debug_output(cv::Rect(view_offsets[1], view_size));
694700 scribble_image_boundary(hgt);
701701+702702+ //
703703+704704+ struct xrt_frame *new_model_inputs_and_outputs = NULL;
705705+706706+ // Let's check that the collage size is actually as big as we think it is
707707+ static_assert(1064 == (8 + ((128 + 8) * 4) + ((320 + 8)) + ((80 + 8) * 2) + 8));
708708+ static_assert(504 == (240 + 240 + 8 + 8 + 8));
709709+710710+ const int w = 1064;
711711+ const int h = 504;
712712+713713+ u_frame_create_one_off(XRT_FORMAT_L8, w, h, &hgt->visualizers.xrtframe);
714714+ hgt->visualizers.xrtframe->timestamp = hgt->current_frame_timestamp;
715715+716716+ cv::Size size = cv::Size(w, h);
717717+718718+ hgt->visualizers.mat =
719719+ cv::Mat(size, CV_8U, hgt->visualizers.xrtframe->data, hgt->visualizers.xrtframe->stride);
720720+721721+ if (hgt->visualizers.old_frame == NULL) {
722722+ // There wasn't a previous frame so let's setup the background
723723+ hgt->visualizers.mat = 255;
724724+ } else {
725725+ // They had better be the same size.
726726+ memcpy(hgt->visualizers.xrtframe->data, hgt->visualizers.old_frame->data,
727727+ hgt->visualizers.old_frame->size);
728728+ xrt_frame_reference(&hgt->visualizers.old_frame, NULL);
729729+ }
695730 }
696731697732 check_new_user_event(hgt);
···885920886921 // If the debug UI is active, push our debug frame
887922 if (hgt->debug_scribble) {
888888- u_sink_debug_push_frame(&hgt->debug_sink, debug_frame);
923923+ u_sink_debug_push_frame(&hgt->debug_sink_ann, debug_frame);
889924 xrt_frame_reference(&debug_frame, NULL);
925925+926926+ // We don't dereference the model inputs/outputs frame here; we make a copy of it next frame and
927927+ // dereference it then.
928928+ u_sink_debug_push_frame(&hgt->debug_sink_model, hgt->visualizers.xrtframe);
929929+ xrt_frame_reference(&hgt->visualizers.old_frame, hgt->visualizers.xrtframe);
930930+ xrt_frame_reference(&hgt->visualizers.xrtframe, NULL);
890931 }
891932892933 // done!
···10431084 "Use IK optimizer (may put tracking in unexpected state, use with care)");
104410851045108610461046- u_var_add_sink_debug(hgt, &hgt->debug_sink, "i");
10871087+ u_var_add_sink_debug(hgt, &hgt->debug_sink_ann, "Annotated camera feeds");
10881088+ u_var_add_sink_debug(hgt, &hgt->debug_sink_model, "Model inputs and outputs");
1047108910481090 HG_DEBUG(hgt, "Hand Tracker initialized!");
10491091
+16-3
src/xrt/tracking/hand/mercury/hg_sync.hpp
···172172 float hand_size_refinement_schedule_y = 0;
173173};
174174175175+struct model_output_visualizers
176176+{
177177+ // After setup, these reference the same piece of memory.
178178+ cv::Mat mat;
179179+ xrt_frame *xrtframe = NULL;
180180+181181+ // After pushing to the debug UI, we reference the frame here so that we can copy memory out of it for next
182182+ // frame.
183183+ xrt_frame *old_frame = NULL;
184184+};
185185+175186/*!
176187 * Main class of Mercury hand tracking.
177188 *
···183194 // Base thing, has to be first.
184195 t_hand_tracking_sync base = {};
185196186186- struct u_sink_debug debug_sink = {};
197197+ struct u_sink_debug debug_sink_ann = {};
198198+ struct u_sink_debug debug_sink_model = {};
187199188200 float multiply_px_coord_for_undistort;
189201···203215204216 struct ht_view views[2] = {};
205217218218+ struct model_output_visualizers visualizers;
219219+206220 u_worker_thread_pool *pool;
207221208222 u_worker_group *group;
···213227214228 uint64_t current_frame_timestamp = {};
215229216216- // Change this whenever you want
217217- volatile bool debug_scribble = true;
230230+ bool debug_scribble = false;
218231219232 char models_folder[1024];
220233