MCPcopy Create free account
hub / github.com/PeterFWS/Structure-PLP-SLAM / mono_localization

Function mono_localization

example/run_video_localization.cc:51–171  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49#endif
50
51void mono_localization(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 std::string &map_db_path, const bool mapping,
54 const unsigned int frame_skip, const bool no_sleep, const bool auto_term)
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(video_file_path, cv::CAP_FFMPEG);
84 std::vector<double> track_times;
85
86 cv::Mat frame;
87 double timestamp = 0.0;
88
89 unsigned int num_frame = 0;
90
91 bool is_not_end = true;
92 // run the SLAM in another thread
93 std::thread thread([&]()
94 {
95 while (is_not_end)
96 {
97 is_not_end = video.read(frame);
98
99 const auto tp_1 = std::chrono::steady_clock::now();
100
101 if (!frame.empty() && (num_frame % frame_skip == 0))
102 {
103 // input the current frame and estimate the camera pose
104 SLAM.feed_monocular_frame(frame, timestamp, mask);
105 }
106
107 const auto tp_2 = std::chrono::steady_clock::now();
108

Callers 1

mainFunction · 0.70

Calls 15

load_map_databaseMethod · 0.80
startupMethod · 0.80
enable_mapping_moduleMethod · 0.80
get_frame_publisherMethod · 0.80
get_map_publisherMethod · 0.80
feed_monocular_frameMethod · 0.80
emptyMethod · 0.45
readMethod · 0.45
countMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected