|
@@ -57,9 +57,9 @@ int preview_camera_index = 0; // 0 for left, 1 for right
|
|
|
std::unique_ptr<simple_render> opengl_render;
|
|
std::unique_ptr<simple_render> opengl_render;
|
|
|
float process_frame_rate = 0;
|
|
float process_frame_rate = 0;
|
|
|
bool enhance_image = false;
|
|
bool enhance_image = false;
|
|
|
|
|
+bool use_crude_debayer = true, undistort_image = true; // debug options
|
|
|
bool augment_enable = false;
|
|
bool augment_enable = false;
|
|
|
-cv::Size augment_render_size;
|
|
|
|
|
-double augment_render_angle = 0;
|
|
|
|
|
|
|
+float augment_render_angle = 0;
|
|
|
std::unique_ptr<vtk_viewer> augment_viewer;
|
|
std::unique_ptr<vtk_viewer> augment_viewer;
|
|
|
|
|
|
|
|
std::unique_ptr<std::thread> encoder_thread;
|
|
std::unique_ptr<std::thread> encoder_thread;
|
|
@@ -86,6 +86,7 @@ std::string probe_model_path;
|
|
|
std::vector<registration_target> reg_targets;
|
|
std::vector<registration_target> reg_targets;
|
|
|
std::unique_ptr<registration> reg;
|
|
std::unique_ptr<registration> reg;
|
|
|
|
|
|
|
|
|
|
+bool debug_options = false;
|
|
|
bool show_vtk_debug = false;
|
|
bool show_vtk_debug = false;
|
|
|
bool show_imgui_demo = false;
|
|
bool show_imgui_demo = false;
|
|
|
std::unique_ptr<vtk_viewer> vtk_test1, vtk_test2;
|
|
std::unique_ptr<vtk_viewer> vtk_test1, vtk_test2;
|
|
@@ -107,13 +108,28 @@ struct camera_related {
|
|
|
cudaStream_t cuda_stream = nullptr;
|
|
cudaStream_t cuda_stream = nullptr;
|
|
|
std::unique_ptr<monocular_processor> processor;
|
|
std::unique_ptr<monocular_processor> processor;
|
|
|
std::string trans_var;
|
|
std::string trans_var;
|
|
|
|
|
+ image_process_config process_conf;
|
|
|
|
|
|
|
|
// remap related
|
|
// remap related
|
|
|
- std::string remap_data_path;
|
|
|
|
|
- std::unique_ptr<smart_texture> remap_tex;
|
|
|
|
|
|
|
+// std::string remap_data_path;
|
|
|
|
|
+// std::unique_ptr<smart_texture> remap_tex;
|
|
|
bool augment_available = false;
|
|
bool augment_available = false;
|
|
|
std::unique_ptr<smart_texture> augment_tex;
|
|
std::unique_ptr<smart_texture> augment_tex;
|
|
|
|
|
|
|
|
|
|
+ void load_intrinsic(YAML::Node conf) {
|
|
|
|
|
+ camera_intrinsic info;
|
|
|
|
|
+ info.fx = conf["fx"].as<float>();
|
|
|
|
|
+ info.fy = conf["fy"].as<float>();
|
|
|
|
|
+ info.cx = conf["cx"].as<float>();
|
|
|
|
|
+ info.cy = conf["cy"].as<float>();
|
|
|
|
|
+ info.k[0] = conf["k0"].as<float>();
|
|
|
|
|
+ info.k[1] = conf["k1"].as<float>();
|
|
|
|
|
+ info.width = conf["width"].as<int>();
|
|
|
|
|
+ info.height = conf["height"].as<int>();
|
|
|
|
|
+
|
|
|
|
|
+ process_conf.camera = info;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
void wait_frame(simple_mq::index_type index) const {
|
|
void wait_frame(simple_mq::index_type index) const {
|
|
|
uint64_t cur_cnt;
|
|
uint64_t cur_cnt;
|
|
|
if (auto ptr = mq().query_variable_ptr<cv::Mat>(index, &cur_cnt);
|
|
if (auto ptr = mq().query_variable_ptr<cv::Mat>(index, &cur_cnt);
|
|
@@ -127,14 +143,26 @@ struct camera_related {
|
|
|
auto raw_ptr = mq().query_variable_ptr<cv::Mat>(index, &cur_cnt);
|
|
auto raw_ptr = mq().query_variable_ptr<cv::Mat>(index, &cur_cnt);
|
|
|
assert(cur_cnt > raw_cnt);
|
|
assert(cur_cnt > raw_cnt);
|
|
|
raw_cnt = cur_cnt;
|
|
raw_cnt = cur_cnt;
|
|
|
- processor->process(*raw_ptr, img_dev.get(), enhance_image, *stream);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // OpenCV debayer does not support alpha channel
|
|
|
|
|
+ if (undistort_image) {
|
|
|
|
|
+ use_crude_debayer = true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // update process config
|
|
|
|
|
+ process_conf.crude_debayer = use_crude_debayer;
|
|
|
|
|
+ process_conf.undistort = undistort_image;
|
|
|
|
|
+ process_conf.enhance = enhance_image;
|
|
|
|
|
+
|
|
|
|
|
+ // process image
|
|
|
|
|
+ processor->process(*raw_ptr, img_dev.get(), process_conf, *stream);
|
|
|
|
|
|
|
|
if (augment_enable) {
|
|
if (augment_enable) {
|
|
|
auto trans = sophiar_conn.query_transform_variable(trans_var);
|
|
auto trans = sophiar_conn.query_transform_variable(trans_var);
|
|
|
augment_available = trans.has_value();
|
|
augment_available = trans.has_value();
|
|
|
if (augment_available) {
|
|
if (augment_available) {
|
|
|
augment_viewer->set_camera_pose(trans.value());
|
|
augment_viewer->set_camera_pose(trans.value());
|
|
|
- augment_viewer->render(augment_render_size);
|
|
|
|
|
|
|
+ augment_viewer->render(img_dev->size());
|
|
|
|
|
|
|
|
// copy rendered image
|
|
// copy rendered image
|
|
|
augment_tex->create(GL_RGBA8, img_dev->size());
|
|
augment_tex->create(GL_RGBA8, img_dev->size());
|
|
@@ -146,20 +174,11 @@ struct camera_related {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- void render(const simple_rect &rect) {
|
|
|
|
|
|
|
+ void render(const simple_rect &rect, bool flip_y = false) {
|
|
|
assert(img_dev != nullptr);
|
|
assert(img_dev != nullptr);
|
|
|
- opengl_render->render_rect(*img_dev, rect, false, cuda_stream);
|
|
|
|
|
|
|
+ opengl_render->render_rect(*img_dev, rect, !flip_y, cuda_stream);
|
|
|
if (augment_available) {
|
|
if (augment_available) {
|
|
|
- // create remap file if needed
|
|
|
|
|
- if (remap_tex == nullptr) [[unlikely]] {
|
|
|
|
|
- auto remap_file = mapped_file{remap_data_path, mapped_file::readonly};
|
|
|
|
|
- auto size = img_dev->size();
|
|
|
|
|
- assert(remap_file.size() == size.area() * CV_ELEM_SIZE(CV_32FC2));
|
|
|
|
|
- auto remap_data = cv::Mat{size, CV_32FC2, (void *) remap_file.const_data()};
|
|
|
|
|
- remap_tex = std::make_unique<smart_texture>();
|
|
|
|
|
- upload_remap_data(remap_tex.get(), remap_data);
|
|
|
|
|
- }
|
|
|
|
|
- opengl_render->render_rect(augment_tex->id, rect, remap_tex->id);
|
|
|
|
|
|
|
+ opengl_render->render_rect(augment_tex->id, rect, flip_y);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
@@ -216,13 +235,18 @@ void load_config() {
|
|
|
main_encoder_conf.frame_rate = capture_conf.frame_rate;
|
|
main_encoder_conf.frame_rate = capture_conf.frame_rate;
|
|
|
capture_conf.expo_time_ms = capture_param["expo_time_ms"].as<float>();
|
|
capture_conf.expo_time_ms = capture_param["expo_time_ms"].as<float>();
|
|
|
capture_conf.gain_db = capture_param["gain_db"].as<float>();
|
|
capture_conf.gain_db = capture_param["gain_db"].as<float>();
|
|
|
- auto remap_conf = camera_conf["remap"];
|
|
|
|
|
- augment_render_size = {remap_conf["width"].as<int>(),
|
|
|
|
|
- remap_conf["height"].as<int>()};
|
|
|
|
|
- augment_render_angle = remap_conf["angle"].as<double>();
|
|
|
|
|
- auto remap_data_conf = remap_conf["data"];
|
|
|
|
|
- left.remap_data_path = remap_data_conf["left"].as<std::string>();
|
|
|
|
|
- right.remap_data_path = remap_data_conf["right"].as<std::string>();
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // load camera intrinsics
|
|
|
|
|
+ auto intrinsic_conf = camera_conf["intrinsic"];
|
|
|
|
|
+ left.load_intrinsic(intrinsic_conf["left"]);
|
|
|
|
|
+ right.load_intrinsic(intrinsic_conf["right"]);
|
|
|
|
|
+
|
|
|
|
|
+ // calculate valid resample range
|
|
|
|
|
+ auto range = calc_valid_range(left.process_conf.camera,
|
|
|
|
|
+ right.process_conf.camera,
|
|
|
|
|
+ &augment_render_angle);
|
|
|
|
|
+ left.process_conf.valid_range = range;
|
|
|
|
|
+ right.process_conf.valid_range = range;
|
|
|
|
|
|
|
|
// load main window config
|
|
// load main window config
|
|
|
auto window_conf = conf["main_window"];
|
|
auto window_conf = conf["main_window"];
|
|
@@ -234,6 +258,8 @@ void load_config() {
|
|
|
output_width = output_conf["width"].as<int>();
|
|
output_width = output_conf["width"].as<int>();
|
|
|
output_height = output_conf["height"].as<int>();
|
|
output_height = output_conf["height"].as<int>();
|
|
|
main_encoder_conf.bitrate_mbps = output_conf["bitrate"].as<float>();
|
|
main_encoder_conf.bitrate_mbps = output_conf["bitrate"].as<float>();
|
|
|
|
|
+ left.process_conf.resample_height = output_height; // use output height as resample height
|
|
|
|
|
+ right.process_conf.resample_height = output_height;
|
|
|
|
|
|
|
|
// load sender config
|
|
// load sender config
|
|
|
auto sender_conf = conf["sender"];
|
|
auto sender_conf = conf["sender"];
|
|
@@ -620,6 +646,12 @@ void prepare_imgui_frame() {
|
|
|
simple_eq.emplace(upload_capture_config);
|
|
simple_eq.emplace(upload_capture_config);
|
|
|
}
|
|
}
|
|
|
ImGui::Checkbox("Enhance", &enhance_image);
|
|
ImGui::Checkbox("Enhance", &enhance_image);
|
|
|
|
|
+ if (debug_options) {
|
|
|
|
|
+ ImGui::SameLine();
|
|
|
|
|
+ ImGui::Checkbox("Crude Debayer", &use_crude_debayer);
|
|
|
|
|
+ ImGui::SameLine();
|
|
|
|
|
+ ImGui::Checkbox("Undistort", &undistort_image);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (is_capturing()) {
|
|
if (is_capturing()) {
|
|
|
// preview config
|
|
// preview config
|
|
@@ -793,6 +825,7 @@ void prepare_imgui_frame() {
|
|
|
ImGui::PushID("Debug");
|
|
ImGui::PushID("Debug");
|
|
|
ImGui::Checkbox("Debug VTK Viewer", &show_vtk_debug);
|
|
ImGui::Checkbox("Debug VTK Viewer", &show_vtk_debug);
|
|
|
ImGui::Checkbox("Show ImGui Demo", &show_imgui_demo);
|
|
ImGui::Checkbox("Show ImGui Demo", &show_imgui_demo);
|
|
|
|
|
+ ImGui::Checkbox("Debug Options", &debug_options);
|
|
|
ImGui::PopID();
|
|
ImGui::PopID();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -859,7 +892,7 @@ void render_main_window() {
|
|
|
assert(left.img_dev->size() == right.img_dev->size());
|
|
assert(left.img_dev->size() == right.img_dev->size());
|
|
|
float width_normal = left.img_dev->size().aspectRatio() / frame_size.aspectRatio();
|
|
float width_normal = left.img_dev->size().aspectRatio() / frame_size.aspectRatio();
|
|
|
auto render_rect = simple_rect{
|
|
auto render_rect = simple_rect{
|
|
|
- -width_normal, 1, 2 * width_normal, -2
|
|
|
|
|
|
|
+ -width_normal, -1, 2 * width_normal, 2
|
|
|
};
|
|
};
|
|
|
if (preview_camera_index == 0) { // left camera
|
|
if (preview_camera_index == 0) { // left camera
|
|
|
if (!left.img_dev->empty()) {
|
|
if (!left.img_dev->empty()) {
|
|
@@ -897,8 +930,8 @@ void generate_output_frame() {
|
|
|
left_rect = simple_rect{-0.5f - width_normal / 2, -1, width_normal, 2};
|
|
left_rect = simple_rect{-0.5f - width_normal / 2, -1, width_normal, 2};
|
|
|
right_rect = simple_rect{0.5f - width_normal / 2, -1, width_normal, 2};
|
|
right_rect = simple_rect{0.5f - width_normal / 2, -1, width_normal, 2};
|
|
|
}
|
|
}
|
|
|
- left.render(left_rect);
|
|
|
|
|
- right.render(right_rect);
|
|
|
|
|
|
|
+ left.render(left_rect, true);
|
|
|
|
|
+ right.render(right_rect, true);
|
|
|
|
|
|
|
|
// wait encoder idle
|
|
// wait encoder idle
|
|
|
for (uint64_t cur_cnt = 0;;) {
|
|
for (uint64_t cur_cnt = 0;;) {
|