depth_guide.cpp 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #include "depth_guide.h"
  2. #include "core/image_utility.hpp"
  3. #include "core/imgui_utility.hpp"
  4. #include "image_process/impl/versatile_convertor_impl.h"
  5. app_depth_guide::app_depth_guide(const create_config &_conf) {
  6. conf = _conf;
  7. // initialize object manager
  8. OBJ_SAVE(img_color, image_u8c3());
  9. OBJ_SAVE(img_depth, image_f32c1());
  10. OBJ_SAVE(img_depth_fake, image_u8c3());
  11. auto fake_info = fake_color_config{.mode = FAKE_800P, .lower = 200, .upper = 1000};
  12. OBJ_SAVE(img_depth_fake_info, versatile_convertor_impl::encode_config(fake_info));
  13. OBJ_SAVE(img_out, image_u8c4());
  14. // initialize modules
  15. auto orb_cam_conf = orb_camera_ui::create_config{
  16. .cf_name = img_color, .df_name = img_depth,
  17. .ctx = conf.asio_ctx, .stream = default_cuda_stream,
  18. };
  19. orb_cam = std::make_unique<orb_camera_ui>(orb_cam_conf);
  20. auto fake_conf = versatile_convertor::create_config{
  21. .in_name = img_depth, .ext_in = img_depth_fake_info, .out_name = img_depth_fake,
  22. .cvt_opt = CVT_FAKE_ENCODE_800P, .stream = default_cuda_stream,
  23. };
  24. depth_encode = std::make_unique<versatile_convertor>(fake_conf);
  25. auto out_conf = stereo_augment_helper::create_config{
  26. .left_name = img_color, .right_name = img_depth_fake, .out_name = img_out,
  27. .stream = default_cuda_stream
  28. };
  29. out_combiner = std::make_unique<stereo_augment_helper>(out_conf);
  30. out_combiner->fix_ui_config({.follow_image_size=true, .enable_halve_width=false});
  31. auto bg_viewer_conf = image_viewer::create_config{
  32. .mode = VIEW_COLOR_DEPTH, .flip_y = true,
  33. .stream = default_cuda_stream,
  34. };
  35. auto &bg_extra_conf = bg_viewer_conf.extra.color_depth;
  36. bg_extra_conf.c_name = img_color;
  37. bg_extra_conf.d_name = img_depth;
  38. bg_viewer = std::make_unique<image_viewer>(bg_viewer_conf);
  39. auto out_streamer_conf = image_streamer::create_config{
  40. .img_name = img_out,
  41. .ext_name = img_depth_fake_info, // comment this for tiny player to work
  42. .asio_ctx = conf.asio_ctx,
  43. .cuda_ctx = conf.cuda_ctx, .stream = default_cuda_stream
  44. };
  45. out_streamer = std::make_unique<image_streamer>(out_streamer_conf);
  46. }
  47. void app_depth_guide::show_ui() {
  48. auto ctx = conf.asio_ctx;
  49. if (ImGui::Begin("Depth Guide Control")) {
  50. ImGui::PushItemWidth(200);
  51. if (ImGui::CollapsingHeader("Camera")) {
  52. auto id_guard = imgui_id_guard("camera");
  53. orb_cam->show();
  54. }
  55. if (ImGui::CollapsingHeader("Streamer")) {
  56. auto id_guard = imgui_id_guard("streamer");
  57. out_streamer->show();
  58. }
  59. if (ImGui::CollapsingHeader("Debug")) {
  60. if (ImGui::TreeNode("Background")) {
  61. bg_viewer->show();
  62. ImGui::TreePop();
  63. }
  64. if (ImGui::TreeNode("Memory Pool")) {
  65. if (ImGui::Button("Purge")) {
  66. post(*ctx, [] { global_mp.purge(); });
  67. }
  68. ImGui::TreePop();
  69. }
  70. if (ImGui::TreeNode("Performance")) {
  71. ImGui::Text("UI Refresh Rate: %.2fms", perf_timer.query().interval);
  72. ImGui::TreePop();
  73. }
  74. }
  75. ImGui::PopItemWidth();
  76. }
  77. ImGui::End();
  78. perf_timer.record();
  79. }
  80. void app_depth_guide::render_background() {
  81. bg_viewer->render();
  82. }