| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- #include "orb_camera_ui_impl.h"
- #include "core/image_utility.hpp"
- #include "core/imgui_utility.hpp"
- #include <boost/asio/io_context.hpp>
- #include <boost/asio/post.hpp>
- using boost::asio::io_context;
- using boost::asio::post;
- extern io_context *main_ctx;
- orb_camera_ui::impl::impl(create_config conf) {
- cam_c_conf.stream = conf.stream;
- cam_c_conf.ctx = main_ctx;
- cam_s_conf.color.name = conf.cf_name;
- cam_s_conf.depth.name = conf.df_name;
- refresh_dev_info_list();
- }
- void orb_camera_ui::impl::refresh_dev_info_list() {
- dev_info_list = orb_camera::query_device_info();
- }
- void orb_camera_ui::impl::open_camera() {
- cam_c_conf.sn_str = dev_info_list[dev_index].sn_str.c_str();
- cam = std::unique_ptr<orb_camera>(orb_camera::create(cam_c_conf));
- assert(cam != nullptr);
- c_conf_list.clear();
- auto cv_info = cam->query_video_info(orb_camera::V_COLOR);
- for (auto v_info: *cv_info) {
- if (strcmp(v_info.fmt_name, "rgb") == 0 ||
- strcmp(v_info.fmt_name, "mjpg") == 0) {
- c_conf_list.emplace_back(v_info.index, std::string(v_info));
- }
- }
- d_conf_list.clear();
- auto dv_info = cam->query_video_info(orb_camera::V_DEPTH);
- for (auto v_info: *dv_info) {
- if (strcmp(v_info.fmt_name, "y16") == 0) {
- d_conf_list.emplace_back(v_info.index, std::string(v_info));
- }
- }
- }
- void orb_camera_ui::impl::start_camera() {
- assert(cam != nullptr);
- cam_s_conf.color.config_index = c_conf_list[c_conf_index].index;
- cam_s_conf.depth.config_index = d_conf_list[d_conf_index].index;
- cam->start(cam_s_conf);
- }
- void orb_camera_ui::impl::show_config() {
- // select device by S/N
- if (!dev_info_list.empty()) {
- auto guard = imgui_disable_guard(cam != nullptr);
- auto dev_sn_preview = dev_info_list[dev_index].sn_str.c_str();
- if (ImGui::BeginCombo("Device SN", dev_sn_preview)) {
- for (int k = 0; k < dev_info_list.size(); ++k) {
- auto is_selected = (dev_index == k);
- if (ImGui::Selectable(dev_info_list[k].sn_str.c_str(), is_selected)) {
- dev_index = k;
- }
- if (is_selected) {
- ImGui::SetItemDefaultFocus();
- }
- }
- ImGui::EndCombo();
- }
- } else { // No device found.
- auto guard = imgui_disable_guard();
- if (ImGui::BeginCombo("Device SN", "No device")) {
- ImGui::EndCombo();
- }
- }
- ImGui::SameLine();
- if (ImGui::Button("R")) {
- post(*main_ctx, [this] { refresh_dev_info_list(); });
- }
- // select video config
- if (cam != nullptr) {
- auto guard = imgui_disable_guard(cam->is_capturing());
- auto c_conf_preview = c_conf_list[c_conf_index].dis_name.c_str();
- if (ImGui::BeginCombo("Color", c_conf_preview)) {
- for (int k = 0; k < c_conf_list.size(); ++k) {
- auto is_selected = (c_conf_index == k);
- if (ImGui::Selectable(c_conf_list[k].dis_name.c_str(), is_selected)) {
- c_conf_index = k;
- }
- if (is_selected) {
- ImGui::SetItemDefaultFocus();
- }
- }
- ImGui::EndCombo();
- }
- auto d_conf_preview = d_conf_list[d_conf_index].dis_name.c_str();
- if (ImGui::BeginCombo("Depth", d_conf_preview)) {
- for (int k = 0; k < d_conf_list.size(); ++k) {
- auto is_selected = (d_conf_index == k);
- if (ImGui::Selectable(d_conf_list[k].dis_name.c_str(), is_selected)) {
- d_conf_index = k;
- }
- if (is_selected) {
- ImGui::SetItemDefaultFocus();
- }
- }
- ImGui::EndCombo();
- }
- }
- }
- void orb_camera_ui::impl::show() {
- ImGui::SeparatorText("Actions");
- if (cam == nullptr) {
- auto guard = imgui_disable_guard(dev_info_list.empty());
- if (ImGui::Button("Open")) {
- post(*main_ctx, [this] { open_camera(); });
- }
- } else {
- assert(cam != nullptr);
- if (ImGui::Button("Close")) {
- post(*main_ctx, [this] { cam = nullptr; });
- }
- ImGui::SameLine();
- if (!cam->is_capturing()) {
- if (ImGui::Button("Start")) {
- post(*main_ctx, [this] { start_camera(); });
- }
- } else {
- if (ImGui::Button("Stop")) {
- post(*main_ctx, [this] { cam->stop(); });
- }
- }
- }
- ImGui::SeparatorText("Configs");
- show_config();
- ImGui::SeparatorText("Info");
- auto c_img = OBJ_QUERY(image_u8c3, cam_s_conf.color.name);
- if (c_img != nullptr) {
- auto size = c_img->size();
- ImGui::Text("Color Stream: %dx%d", size.width, size.height);
- }
- auto d_img = OBJ_QUERY(image_f32c1, cam_s_conf.depth.name);
- if (d_img != nullptr) {
- auto size = d_img->size();
- ImGui::Text("Depth Stream: %dx%d", size.width, size.height);
- }
- }
- orb_camera_ui::orb_camera_ui(create_config conf)
- : pimpl(std::make_unique<impl>(conf)) {}
- orb_camera_ui::~orb_camera_ui() = default;
- void orb_camera_ui::show() {
- pimpl->show();
- }
|