The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

mercury: Correctly handle lower resolution input images

And better calibration debug prints

+64 -9
+59 -7
src/xrt/tracking/hand/mercury/hg_sync.cpp
··· 11 11 12 12 #include "hg_sync.hpp" 13 13 #include "hg_model.hpp" 14 + #include <numeric> 14 15 15 16 namespace xrt::tracking::hand::mercury { 16 17 // Flags to tell state tracker that these are indeed valid joints ··· 49 50 xrt_vec3 trans = {(float)wrap.camera_translation_mat(0, 0), (float)wrap.camera_translation_mat(1, 0), 50 51 (float)wrap.camera_translation_mat(2, 0)}; 51 52 htd->baseline = m_vec3_len(trans); 53 + HT_DEBUG(htd, "I think the baseline is %f meters!", htd->baseline); 52 54 // Note, this assumes camera 0 is the left camera and camera 1 is the right camera. 53 55 // If you find one with the opposite arrangement, you'll need to invert htd->baseline, and look at 54 56 // hgJointDisparityMath 55 57 56 58 htd->use_fisheye = wrap.view[0].use_fisheye; 57 59 60 + if (htd->use_fisheye) { 61 + HT_DEBUG(htd, "I think the cameras are fisheye!"); 62 + } else { 63 + HT_DEBUG(htd, "I think the cameras are not fisheye!"); 64 + } 65 + 58 66 cv::Matx34d P1; 59 67 cv::Matx34d P2; 60 68 ··· 105 113 } else { 106 114 htd->views[i].distortion = wrap.view[i].distortion_mat; 107 115 } 116 + 117 + if (htd->log_level <= U_LOGGING_DEBUG) { 118 + HT_DEBUG(htd, "R%d ->", i); 119 + std::cout << htd->views[i].rotate_camera_to_stereo_camera << std::endl; 120 + 121 + HT_DEBUG(htd, "K%d ->", i); 122 + std::cout << htd->views[i].cameraMatrix << std::endl; 123 + 124 + HT_DEBUG(htd, "D%d ->", i); 125 + std::cout << htd->views[i].distortion << std::endl; 126 + } 108 127 } 109 128 110 - htd->one_view_size_px.w = wrap.view[0].image_size_pixels.w; 111 - htd->one_view_size_px.h = wrap.view[0].image_size_pixels.h; 129 + htd->calibration_one_view_size_px.w = wrap.view[0].image_size_pixels.w; 130 + htd->calibration_one_view_size_px.h = wrap.view[0].image_size_pixels.h; 131 + 132 + htd->last_frame_one_view_size_px = htd->calibration_one_view_size_px; 133 + htd->multiply_px_coord_for_undistort = 1.0f; 112 134 113 135 cv::Matx33d rotate_stereo_camera_to_left_camera = htd->views[0].rotate_camera_to_stereo_camera.inv(); 114 136 ··· 235 257 .040f * .5f; // Measured my wrist thickness with calipers 236 258 } 237 259 260 + static bool handle_changed_image_size(HandTracking *htd, xrt_size &new_one_view_size) 261 + { 262 + int gcd_calib = std::gcd(htd->calibration_one_view_size_px.h, htd->calibration_one_view_size_px.w); 263 + int gcd_new = std::gcd(new_one_view_size.h, new_one_view_size.w); 264 + 265 + int lcm_h_calib = htd->calibration_one_view_size_px.h/gcd_calib; 266 + int lcm_w_calib = htd->calibration_one_view_size_px.w/gcd_calib; 267 + 268 + int lcm_h_new = new_one_view_size.h/gcd_new; 269 + int lcm_w_new = new_one_view_size.w/gcd_new; 270 + 271 + bool good = (lcm_h_calib == lcm_h_new) && (lcm_w_calib == lcm_w_new); 272 + 273 + if (!good) { 274 + HT_WARN(htd, "Can't process this frame, wrong aspect ratio."); 275 + return false; 276 + } 277 + 278 + htd->multiply_px_coord_for_undistort = (float)htd->calibration_one_view_size_px.h/(float)new_one_view_size.h; 279 + htd->last_frame_one_view_size_px = new_one_view_size; 280 + return true; 281 + } 282 + 238 283 /* 239 284 * 240 285 * Member functions. ··· 296 341 const int full_height = left_frame->height; 297 342 const int full_width = left_frame->width*2; 298 343 299 - const int view_width = htd->one_view_size_px.w; 300 - const int view_height = htd->one_view_size_px.h; 301 - 302 - assert(full_height == view_height); 344 + if ((left_frame->width != (uint32_t)htd->last_frame_one_view_size_px.w) || (left_frame->height != (uint32_t)htd->last_frame_one_view_size_px.h)) 345 + { 346 + xrt_size new_one_view_size; 347 + new_one_view_size.h = left_frame->height; 348 + new_one_view_size.w = left_frame->width; 349 + // Could be an assert, should never happen. 350 + if (!handle_changed_image_size(htd, new_one_view_size)) { 351 + return; 352 + } 353 + } 303 354 304 - htd->multiply_px_coord_for_undistort = 1.0f; 355 + const int view_width = htd->last_frame_one_view_size_px.w; 356 + const int view_height = htd->last_frame_one_view_size_px.h; 305 357 306 358 const cv::Size full_size = cv::Size(full_width, full_height); 307 359 const cv::Size view_size = cv::Size(view_width, view_height);
+5 -2
src/xrt/tracking/hand/mercury/hg_sync.hpp
··· 169 169 170 170 struct u_sink_debug debug_sink = {}; 171 171 172 - int multiply_px_coord_for_undistort; 172 + float multiply_px_coord_for_undistort; 173 173 174 174 bool use_fisheye; 175 175 ··· 177 177 178 178 struct t_stereo_camera_calibration *calib; 179 179 180 - struct xrt_size one_view_size_px = {}; 180 + struct xrt_size calibration_one_view_size_px = {}; 181 + 182 + // So that we can calibrate cameras at 1280x800 but ship images over USB at 640x400 183 + struct xrt_size last_frame_one_view_size_px = {}; 181 184 182 185 #ifdef USE_NCNN 183 186 ncnn_net_t net;