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

Function mono_tracking

example/run_camera_slam.cc:53–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51#endif
52
53void mono_tracking(const std::shared_ptr<PLPSLAM::config> &cfg,
54 const std::string &vocab_file_path, const unsigned int cam_num, const std::string &mask_img_path,
55 const float scale, 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 // build a SLAM system
61 PLPSLAM::system SLAM(cfg, vocab_file_path);
62 // startup the SLAM process
63 SLAM.startup();
64
65 // create a viewer object
66 // and pass the frame_publisher and the map_publisher
67#ifdef USE_PANGOLIN_VIEWER
68 pangolin_viewer::viewer viewer(cfg, &SLAM, SLAM.get_frame_publisher(), SLAM.get_map_publisher());
69#elif USE_SOCKET_PUBLISHER
70 socket_publisher::publisher publisher(cfg, &SLAM, SLAM.get_frame_publisher(), SLAM.get_map_publisher());
71#endif
72
73 auto video = cv::VideoCapture(cam_num);
74 if (!video.isOpened())
75 {
76 spdlog::critical("cannot open a camera {}", cam_num);
77 SLAM.shutdown();
78 return;
79 }
80
81 cv::Mat frame;
82 double timestamp = 0.0;
83 std::vector<double> track_times;
84
85 unsigned int num_frame = 0;
86
87 bool is_not_end = true;
88 // run the SLAM in another thread
89 std::thread thread([&]()
90 {
91 while (is_not_end)
92 {
93 // check if the termination of SLAM system is requested or not
94 if (SLAM.terminate_is_requested())
95 {
96 break;
97 }
98
99 is_not_end = video.read(frame);
100 if (frame.empty())
101 {
102 continue;
103 }
104 if (scale != 1.0)
105 {
106 cv::resize(frame, frame, cv::Size(), scale, scale, cv::INTER_LINEAR);
107 }
108
109 const auto tp_1 = std::chrono::steady_clock::now();
110

Callers 1

mainFunction · 0.70

Calls 15

criticalFunction · 0.85
startupMethod · 0.80
get_frame_publisherMethod · 0.80
get_map_publisherMethod · 0.80
feed_monocular_frameMethod · 0.80
save_map_databaseMethod · 0.80
emptyMethod · 0.45
shutdownMethod · 0.45
readMethod · 0.45
countMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected