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

Function mono_tracking

example/run_image_slam_planeSeg.cc:52–191  ·  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,
54 const std::string &image_dir_path,
55 const std::string &mask_img_path,
56 const unsigned int frame_skip,
57 const bool no_sleep,
58 const bool auto_term,
59 const bool eval_log,
60 const std::string &map_db_path)
61{
62 // load the mask image
63 const cv::Mat mask = mask_img_path.empty() ? cv::Mat{} : cv::imread(mask_img_path, cv::IMREAD_GRAYSCALE);
64
65 const image_sequence sequence(image_dir_path, cfg->camera_->fps_);
66 const auto frames = sequence.get_frames();
67
68 // build a SLAM system
69 PLPSLAM::system SLAM(cfg, vocab_file_path, true); // true means: we have segmentation mask -> _b_seg_or_not = true
70 // startup the SLAM process
71 SLAM.startup();
72
73#ifdef USE_PANGOLIN_VIEWER
74 pangolin_viewer::viewer viewer(cfg, &SLAM, SLAM.get_frame_publisher(), SLAM.get_map_publisher());
75#elif USE_SOCKET_PUBLISHER
76 socket_publisher::publisher publisher(cfg, &SLAM, SLAM.get_frame_publisher(), SLAM.get_map_publisher());
77#endif
78
79 std::vector<double> track_times;
80 track_times.reserve(frames.size());
81
82 // run the SLAM in another thread
83 std::thread thread([&]()
84 {
85 for (unsigned int i = 0; i < frames.size(); ++i)
86 {
87 const auto &frame = frames.at(i);
88 const auto img = cv::imread(frame.img_path_, cv::IMREAD_UNCHANGED);
89
90 // FW: read planar segmentation mask
91 const auto seg_mask_img = cv::imread(frame.mask_img_path_, cv::IMREAD_UNCHANGED);
92
93 const auto tp_1 = std::chrono::steady_clock::now();
94
95 if (!img.empty() && (i % frame_skip == 0))
96 {
97 // input the current frame and estimate the camera pose
98 SLAM.feed_monocular_frame(img, seg_mask_img, frame.timestamp_, mask);
99 }
100
101 const auto tp_2 = std::chrono::steady_clock::now();
102
103 const auto track_time = std::chrono::duration_cast<std::chrono::duration<double>>(tp_2 - tp_1).count();
104 if (i % frame_skip == 0)
105 {
106 track_times.push_back(track_time);
107 }
108
109 // wait until the timestamp of the next frame

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

Tested by

no test coverage detected