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

Function mono_tracking

example/run_image_slam.cc:52–177  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50#endif
51
52void mono_tracking(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 unsigned int frame_skip, const bool no_sleep, const bool auto_term,
55 const bool eval_log, 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 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 // startup the SLAM process
66 SLAM.startup();
67
68#ifdef USE_PANGOLIN_VIEWER
69 pangolin_viewer::viewer viewer(cfg, &SLAM, SLAM.get_frame_publisher(), SLAM.get_map_publisher());
70#elif USE_SOCKET_PUBLISHER
71 socket_publisher::publisher publisher(cfg, &SLAM, SLAM.get_frame_publisher(), SLAM.get_map_publisher());
72#endif
73
74 std::vector<double> track_times;
75 track_times.reserve(frames.size());
76
77 // run the SLAM in another thread
78 std::thread thread([&]()
79 {
80 for (unsigned int i = 0; i < frames.size(); ++i)
81 {
82 const auto &frame = frames.at(i);
83 const auto img = cv::imread(frame.img_path_, cv::IMREAD_UNCHANGED);
84
85 const auto tp_1 = std::chrono::steady_clock::now();
86
87 if (!img.empty() && (i % frame_skip == 0))
88 {
89 // input the current frame and estimate the camera pose
90 SLAM.feed_monocular_frame(img, frame.timestamp_, mask);
91 }
92
93 const auto tp_2 = std::chrono::steady_clock::now();
94
95 const auto track_time = std::chrono::duration_cast<std::chrono::duration<double>>(tp_2 - tp_1).count();
96 if (i % frame_skip == 0)
97 {
98 track_times.push_back(track_time);
99 }
100
101 // wait until the timestamp of the next frame
102 if (!no_sleep && i < frames.size() - 1)
103 {
104 const auto wait_time = frames.at(i + 1).timestamp_ - (frame.timestamp_ + track_time);
105 if (0.0 < wait_time)
106 {
107 std::this_thread::sleep_for(std::chrono::microseconds(static_cast<unsigned int>(wait_time * 1e6)));
108 }
109 }

Callers 1

mainFunction · 0.70

Calls 15

startupMethod · 0.80
get_frame_publisherMethod · 0.80
get_map_publisherMethod · 0.80
feed_monocular_frameMethod · 0.80
closeMethod · 0.80
save_map_databaseMethod · 0.80
emptyMethod · 0.45
get_framesMethod · 0.45
reserveMethod · 0.45
sizeMethod · 0.45
countMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected