| 51 | #endif |
| 52 | |
| 53 | void mono_tracking(const std::shared_ptr<PLPSLAM::config> &cfg, |
| 54 | const std::string &vocab_file_path, const unsigned int cam_num, const std::string &mask_img_path, |
| 55 | const float scale, const std::string &map_db_path) |
| 56 | { |
| 57 | // load the mask image |
| 58 | const cv::Mat mask = mask_img_path.empty() ? cv::Mat{} : cv::imread(mask_img_path, cv::IMREAD_GRAYSCALE); |
| 59 | |
| 60 | // build a SLAM system |
| 61 | PLPSLAM::system SLAM(cfg, vocab_file_path); |
| 62 | // startup the SLAM process |
| 63 | SLAM.startup(); |
| 64 | |
| 65 | // create a viewer object |
| 66 | // and pass the frame_publisher and the map_publisher |
| 67 | #ifdef USE_PANGOLIN_VIEWER |
| 68 | pangolin_viewer::viewer viewer(cfg, &SLAM, SLAM.get_frame_publisher(), SLAM.get_map_publisher()); |
| 69 | #elif USE_SOCKET_PUBLISHER |
| 70 | socket_publisher::publisher publisher(cfg, &SLAM, SLAM.get_frame_publisher(), SLAM.get_map_publisher()); |
| 71 | #endif |
| 72 | |
| 73 | auto video = cv::VideoCapture(cam_num); |
| 74 | if (!video.isOpened()) |
| 75 | { |
| 76 | spdlog::critical("cannot open a camera {}", cam_num); |
| 77 | SLAM.shutdown(); |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | cv::Mat frame; |
| 82 | double timestamp = 0.0; |
| 83 | std::vector<double> track_times; |
| 84 | |
| 85 | unsigned int num_frame = 0; |
| 86 | |
| 87 | bool is_not_end = true; |
| 88 | // run the SLAM in another thread |
| 89 | std::thread thread([&]() |
| 90 | { |
| 91 | while (is_not_end) |
| 92 | { |
| 93 | // check if the termination of SLAM system is requested or not |
| 94 | if (SLAM.terminate_is_requested()) |
| 95 | { |
| 96 | break; |
| 97 | } |
| 98 | |
| 99 | is_not_end = video.read(frame); |
| 100 | if (frame.empty()) |
| 101 | { |
| 102 | continue; |
| 103 | } |
| 104 | if (scale != 1.0) |
| 105 | { |
| 106 | cv::resize(frame, frame, cv::Size(), scale, scale, cv::INTER_LINEAR); |
| 107 | } |
| 108 | |
| 109 | const auto tp_1 = std::chrono::steady_clock::now(); |
| 110 |
no test coverage detected