The open source OpenXR runtime
0
fork

Configure Feed

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

d/ht: Tidy view creation

+28 -13
+28 -13
src/xrt/drivers/ht/ht_algorithm.hpp
··· 290 290 291 291 htd->current_frame_timestamp = htd->frame_for_process->timestamp; 292 292 293 - 294 293 int64_t start, end; 295 294 start = os_monotonic_get_ns(); 296 295 297 296 297 + /* 298 + * Setup views. 299 + */ 298 300 299 - cv::Mat full_frame(960, 960 * 2, CV_8UC3, htd->frame_for_process->data, htd->frame_for_process->stride); 300 - htd->views[0].run_model_on_this = 301 - full_frame(cv::Rect(0, 0, htd->camera.one_view_size_px.w, htd->camera.one_view_size_px.h)); 302 - htd->views[1].run_model_on_this = full_frame(cv::Rect( 303 - htd->camera.one_view_size_px.w, 0, htd->camera.one_view_size_px.w, htd->camera.one_view_size_px.h)); 301 + const int full_width = htd->frame_for_process->width; 302 + const int full_height = htd->frame_for_process->height; 303 + const int view_width = htd->camera.one_view_size_px.w; 304 + const int view_height = htd->camera.one_view_size_px.h; 305 + 306 + assert(full_width == view_width * 2); 307 + assert(full_height == view_height); 308 + 309 + const cv::Size full_size = cv::Size(full_width, full_height); 310 + const cv::Size view_size = cv::Size(view_width, view_height); 311 + const cv::Point view_offsets[2] = {cv::Point(0, 0), cv::Point(view_width, 0)}; 312 + 313 + cv::Mat full_frame(full_size, CV_8UC3, htd->frame_for_process->data, htd->frame_for_process->stride); 314 + htd->views[0].run_model_on_this = full_frame(cv::Rect(view_offsets[0], view_size)); 315 + htd->views[1].run_model_on_this = full_frame(cv::Rect(view_offsets[1], view_size)); 304 316 305 317 // Check this every frame. We really, really, really don't want it to ever suddenly be null. 306 318 htd->debug_scribble = htd->debug_sink != nullptr; 307 319 308 - cv::Mat debug_output; 320 + cv::Mat debug_output = {}; 309 321 xrt_frame *debug_frame = nullptr; // only use if htd->debug_scribble 310 322 311 - 312 323 if (htd->debug_scribble) { 313 324 u_frame_clone(htd->frame_for_process, &debug_frame); 314 - debug_output = cv::Mat(960, 960 * 2, CV_8UC3, debug_frame->data, debug_frame->stride); 315 - htd->views[0].debug_out_to_this = 316 - debug_output(cv::Rect(0, 0, htd->camera.one_view_size_px.w, htd->camera.one_view_size_px.h)); 317 - htd->views[1].debug_out_to_this = debug_output(cv::Rect( 318 - htd->camera.one_view_size_px.w, 0, htd->camera.one_view_size_px.w, htd->camera.one_view_size_px.h)); 325 + debug_output = cv::Mat(full_size, CV_8UC3, debug_frame->data, debug_frame->stride); 326 + htd->views[0].debug_out_to_this = debug_output(cv::Rect(view_offsets[0], view_size)); 327 + htd->views[1].debug_out_to_this = debug_output(cv::Rect(view_offsets[1], view_size)); 319 328 } 320 329 330 + 331 + /* 332 + * Do the hand tracking! 333 + */ 334 + 321 335 std::future<std::vector<Hand2D>> future_left = 322 336 std::async(std::launch::async, htImageToKeypoints, &htd->views[0]); 323 337 std::future<std::vector<Hand2D>> future_right = 324 338 std::async(std::launch::async, htImageToKeypoints, &htd->views[1]); 325 339 std::vector<Hand2D> hands_in_left_view = future_left.get(); 326 340 std::vector<Hand2D> hands_in_right_view = future_right.get(); 341 + 327 342 end = os_monotonic_get_ns(); 328 343 329 344