| 49 | #endif |
| 50 | |
| 51 | void mono_tracking(const std::shared_ptr<PLPSLAM::config> &cfg, |
| 52 | const std::string &vocab_file_path, const std::string &video_file_path, const std::string &mask_img_path, |
| 53 | const unsigned int frame_skip, const bool no_sleep, const bool auto_term, |
| 54 | const bool eval_log, const std::string &map_db_path) |
| 55 | { |
| 56 | // load the mask image |
| 57 | const cv::Mat mask = mask_img_path.empty() ? cv::Mat{} : cv::imread(mask_img_path, cv::IMREAD_GRAYSCALE); |
| 58 | |
| 59 | // build a SLAM system |
| 60 | PLPSLAM::system SLAM(cfg, vocab_file_path); |
| 61 | // startup the SLAM process |
| 62 | SLAM.startup(); |
| 63 | |
| 64 | // create a viewer object |
| 65 | // and pass the frame_publisher and the map_publisher |
| 66 | #ifdef USE_PANGOLIN_VIEWER |
| 67 | pangolin_viewer::viewer viewer(cfg, &SLAM, SLAM.get_frame_publisher(), SLAM.get_map_publisher()); |
| 68 | #elif USE_SOCKET_PUBLISHER |
| 69 | socket_publisher::publisher publisher(cfg, &SLAM, SLAM.get_frame_publisher(), SLAM.get_map_publisher()); |
| 70 | #endif |
| 71 | |
| 72 | auto video = cv::VideoCapture(video_file_path, cv::CAP_FFMPEG); |
| 73 | std::vector<double> track_times; |
| 74 | |
| 75 | cv::Mat frame; |
| 76 | double timestamp = 0.0; |
| 77 | |
| 78 | unsigned int num_frame = 0; |
| 79 | |
| 80 | bool is_not_end = true; |
| 81 | // run the SLAM in another thread |
| 82 | std::thread thread([&]() |
| 83 | { |
| 84 | while (is_not_end) |
| 85 | { |
| 86 | is_not_end = video.read(frame); |
| 87 | |
| 88 | const auto tp_1 = std::chrono::steady_clock::now(); |
| 89 | |
| 90 | if (!frame.empty() && (num_frame % frame_skip == 0)) |
| 91 | { |
| 92 | // input the current frame and estimate the camera pose |
| 93 | SLAM.feed_monocular_frame(frame, timestamp, mask); |
| 94 | } |
| 95 | |
| 96 | const auto tp_2 = std::chrono::steady_clock::now(); |
| 97 | |
| 98 | const auto track_time = std::chrono::duration_cast<std::chrono::duration<double>>(tp_2 - tp_1).count(); |
| 99 | if (num_frame % frame_skip == 0) |
| 100 | { |
| 101 | track_times.push_back(track_time); |
| 102 | } |
| 103 | |
| 104 | // wait until the timestamp of the next frame |
| 105 | if (!no_sleep) |
| 106 | { |
| 107 | const auto wait_time = 1.0 / cfg->camera_->fps_ - track_time; |
| 108 | if (0.0 < wait_time) |
no test coverage detected