remote_ar_v2.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #include "remote_ar_v2.h"
  2. #include "image_process_v5/sp_image.h"
  3. #include "image_process_v5/osg_helper.h"
  4. #include "image_process_v5/image_process.h"
  5. #include "core/yaml_utility.hpp"
  6. #include "core/imgui_utility.hpp"
  7. #include "device_v5/ndi_stray_point_tracker.h"
  8. // from sophiar
  9. #include "core/local_connection.h"
  10. app_remote_ar_v2::app_remote_ar_v2(create_config _conf)
  11. : main_conf(std::move(_conf)) {
  12. auto conf = main_conf.ext_conf;
  13. // OBJ_SIG(left_img_id)->connect([](auto _) { auto img = OBJ_QUERY(sp_image, left_img_id); raise(SIGTRAP); });
  14. // OBJ_SIG(output_img_id)->connect([](auto _) { auto img = OBJ_QUERY(sp_image, left_img_id); raise(SIGTRAP); });
  15. if (true) {
  16. auto sub_conf = mvs_camera_ui::create_config{.ctx = main_conf.asio_ctx};
  17. sub_conf.cameras.push_back({.dev_name = LOAD_STR("left_camera_name"), .img_name = left_img_id});
  18. sub_conf.cameras.push_back({.dev_name = LOAD_STR("right_camera_name"), .img_name = right_img_id});
  19. mvs_cam.emplace(sub_conf);
  20. // mvs_cam->cap_info_sig.connect([this](auto info) {
  21. // out_streamer->change_frame_rate(info.frame_rate);
  22. // });
  23. }
  24. if (true) {
  25. auto uvc_cam_conf = uvc_camera_ui::create_config{
  26. .img_name = uvc_img_id,
  27. .ctx = main_conf.asio_ctx,
  28. };
  29. uvc_cam.emplace(uvc_cam_conf);
  30. }
  31. if (true) {
  32. auto sub_conf = stereo_output_helper::create_config();
  33. sub_conf.left_name = left_img_id;
  34. sub_conf.right_name = right_img_id;
  35. sub_conf.out_name = output_img_id;
  36. // sub_conf.size = cv::Size(1920, 804);
  37. sub_conf.halve_width = false;
  38. output_helper.emplace(sub_conf);
  39. }
  40. if (true) {
  41. auto sub_conf = image_viewer_v2::create_config();
  42. sub_conf.items.emplace_back(uvc_img_id, "Endoscope", true);
  43. sub_conf.items.emplace_back(left_img_id, "Left", true);
  44. sub_conf.items.emplace_back(right_img_id, "Right", true);
  45. bg_viewer.emplace(sub_conf);
  46. }
  47. if (true) {
  48. auto sub_conf = image_streamer::create_config();
  49. sub_conf.img_name = output_img_id;
  50. sub_conf.asio_ctx = main_conf.asio_ctx;
  51. streamer.emplace(sub_conf);
  52. }
  53. if (true) {
  54. auto sub_conf = versatile_saver::create_config();
  55. // sub_conf.items.emplace_back(left_img_id, "Left", true);
  56. // sub_conf.items.emplace_back(right_img_id, "Right", true);
  57. sub_conf.items.emplace_back(uvc_img_id, "Endoscope", true);
  58. saver.emplace(sub_conf);
  59. }
  60. start_sophiar(LOAD_STR("sophiar_config"),
  61. LOAD_STR("sophiar_start_name"));
  62. if (true) {
  63. auto sub_conf = ndi_stray_point_tracker::create_config();
  64. sub_conf.ip_addr = LOAD_STR("ndi_ip");
  65. sub_conf.port = LOAD_NUMBER(uint16_t, "ndi_port");
  66. create_ndi_stray_points_tracker(sub_conf);
  67. }
  68. if (true) {
  69. auto sub_conf = oblique_calibrator::create_config();
  70. sub_conf.camera_ref_name = LOAD_STR("camera_ref_transform_var");
  71. endo_calib.emplace(sub_conf);
  72. }
  73. }
  74. app_remote_ar_v2::~app_remote_ar_v2() = default;
  75. void app_remote_ar_v2::render_background() {
  76. bg_viewer->render();
  77. }
  78. void app_remote_ar_v2::show_ui() {
  79. if (ImGui::Begin("Remote AR Control")) {
  80. ImGui::PushItemWidth(200);
  81. if (ImGui::CollapsingHeader("MVS Camera")) {
  82. auto id_guard = imgui_id_guard("mvs_camera");
  83. mvs_cam->show();
  84. }
  85. if (ImGui::CollapsingHeader("UVC Camera")) {
  86. auto id_guard = imgui_id_guard("uvc_camera");
  87. uvc_cam->show();
  88. }
  89. if (ImGui::CollapsingHeader("Endoscope Calibration")) {
  90. auto id_guard = imgui_id_guard("endo_calib");
  91. endo_calib->show_ui();
  92. }
  93. if (ImGui::CollapsingHeader("Streamer")) {
  94. auto id_guard = imgui_id_guard("streamer");
  95. streamer->show();
  96. }
  97. if (ImGui::CollapsingHeader("Debug")) {
  98. if (ImGui::TreeNode("Background")) {
  99. bg_viewer->show_ui();
  100. ImGui::TreePop();
  101. }
  102. if (ImGui::TreeNode("Saver")) {
  103. saver->show_ui();
  104. ImGui::TreePop();
  105. }
  106. }
  107. ImGui::PopItemWidth();
  108. }
  109. ImGui::End();
  110. }