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

Function mono_localization

example/run_image_localization.cc:52–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50#endif
51
52void mono_localization(const std::shared_ptr<PLPSLAM::config> &cfg,
53 const std::string &vocab_file_path, const std::string &image_dir_path, const std::string &mask_img_path,
54 const std::string &map_db_path, const bool mapping,
55 const unsigned int frame_skip, const bool no_sleep, const bool auto_term)
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 const image_sequence sequence(image_dir_path, cfg->camera_->fps_);
61 const auto frames = sequence.get_frames();
62
63 // build a SLAM system
64 PLPSLAM::system SLAM(cfg, vocab_file_path);
65 // load the prebuilt map
66 SLAM.load_map_database(map_db_path);
67 // startup the SLAM process (it does not need initialization of a map)
68 SLAM.startup(false);
69 // select to activate the mapping module or not
70 if (mapping)
71 {
72 SLAM.enable_mapping_module();
73 }
74 else
75 {
76 SLAM.disable_mapping_module();
77 }
78
79 // create a viewer object
80 // and pass the frame_publisher and the map_publisher
81#ifdef USE_PANGOLIN_VIEWER
82 pangolin_viewer::viewer viewer(cfg, &SLAM, SLAM.get_frame_publisher(), SLAM.get_map_publisher());
83#elif USE_SOCKET_PUBLISHER
84 socket_publisher::publisher publisher(cfg, &SLAM, SLAM.get_frame_publisher(), SLAM.get_map_publisher());
85#endif
86
87 std::vector<double> track_times;
88 track_times.reserve(frames.size());
89
90 // run the SLAM in another thread
91 std::thread thread([&]()
92 {
93 for (unsigned int i = 0; i < frames.size(); ++i)
94 {
95 const auto &frame = frames.at(i);
96 const auto img = cv::imread(frame.img_path_, cv::IMREAD_UNCHANGED);
97
98 const auto tp_1 = std::chrono::steady_clock::now();
99
100 if (!img.empty() && (i % frame_skip == 0))
101 {
102 // input the current frame and estimate the camera pose
103 SLAM.feed_monocular_frame(img, frame.timestamp_, mask);
104 }
105
106 const auto tp_2 = std::chrono::steady_clock::now();
107
108 const auto track_time = std::chrono::duration_cast<std::chrono::duration<double>>(tp_2 - tp_1).count();
109 if (i % frame_skip == 0)

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
get_framesMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected