| 50 | #endif |
| 51 | |
| 52 | void mono_localization(const std::shared_ptr<PLPSLAM::config> &cfg, |
| 53 | const std::string &vocab_file_path, const unsigned int cam_num, const std::string &mask_img_path, |
| 54 | const float scale, const std::string &map_db_path, const bool mapping) |
| 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 | // load the prebuilt map |
| 62 | SLAM.load_map_database(map_db_path); |
| 63 | // startup the SLAM process (it does not need initialization of a map) |
| 64 | SLAM.startup(false); |
| 65 | // select to activate the mapping module or not |
| 66 | if (mapping) |
| 67 | { |
| 68 | SLAM.enable_mapping_module(); |
| 69 | } |
| 70 | else |
| 71 | { |
| 72 | SLAM.disable_mapping_module(); |
| 73 | } |
| 74 | |
| 75 | // create a viewer object |
| 76 | // and pass the frame_publisher and the map_publisher |
| 77 | #ifdef USE_PANGOLIN_VIEWER |
| 78 | pangolin_viewer::viewer viewer(cfg, &SLAM, SLAM.get_frame_publisher(), SLAM.get_map_publisher()); |
| 79 | #elif USE_SOCKET_PUBLISHER |
| 80 | socket_publisher::publisher publisher(cfg, &SLAM, SLAM.get_frame_publisher(), SLAM.get_map_publisher()); |
| 81 | #endif |
| 82 | |
| 83 | auto video = cv::VideoCapture(cam_num); |
| 84 | if (!video.isOpened()) |
| 85 | { |
| 86 | spdlog::critical("cannot open a camera {}", cam_num); |
| 87 | SLAM.shutdown(); |
| 88 | return; |
| 89 | } |
| 90 | |
| 91 | cv::Mat frame; |
| 92 | double timestamp = 0.0; |
| 93 | std::vector<double> track_times; |
| 94 | |
| 95 | unsigned int num_frame = 0; |
| 96 | |
| 97 | bool is_not_end = true; |
| 98 | // run the SLAM in another thread |
| 99 | std::thread thread([&]() |
| 100 | { |
| 101 | while (is_not_end) |
| 102 | { |
| 103 | // check if the termination of SLAM system is requested or not |
| 104 | if (SLAM.terminate_is_requested()) |
| 105 | { |
| 106 | break; |
| 107 | } |
| 108 | |
| 109 | is_not_end = video.read(frame); |
no test coverage detected