123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- #include <signal.h>
- #include <stdlib.h>
- #include <iostream>
- #include <algorithm>
- #include <fstream>
- #include <chrono>
- #include <ctime>
- #include <sstream>
- #include <opencv2/core/core.hpp>
- #include <librealsense2/rs.hpp>
- #include <System.h>
- using namespace std;
- bool b_continue_session;
- void exit_loop_handler(int s){
- cout << "Finishing session" << endl;
- b_continue_session = false;
- }
- int main(int argc, char **argv)
- {
- if(argc < 3 || argc > 4)
- {
- cerr << endl << "Usage: ./mono_realsense_t265 path_to_vocabulary path_to_settings (trajectory_file_name)" << endl;
- return 1;
- }
- string file_name;
- bool bFileName = false;
- if (argc == 4)
- {
- file_name = string(argv[argc-1]);
- bFileName = true;
- }
- struct sigaction sigIntHandler;
- sigIntHandler.sa_handler = exit_loop_handler;
- sigemptyset(&sigIntHandler.sa_mask);
- sigIntHandler.sa_flags = 0;
- sigaction(SIGINT, &sigIntHandler, NULL);
- b_continue_session = true;
-
- rs2::pipeline pipe;
-
- rs2::config cfg;
-
- cfg.enable_stream(RS2_STREAM_FISHEYE, 1, RS2_FORMAT_Y8);
- cfg.enable_stream(RS2_STREAM_FISHEYE, 2, RS2_FORMAT_Y8);
- rs2::pipeline_profile pipe_profile = pipe.start(cfg);
- cout.precision(17);
-
-
- ORB_SLAM3::System SLAM(argv[1],argv[2],ORB_SLAM3::System::MONOCULAR, true);
- float imageScale = SLAM.GetImageScale();
- cv::Mat imCV;
- rs2::stream_profile fisheye_stream = pipe_profile.get_stream(RS2_STREAM_FISHEYE, 1);
- rs2_intrinsics intrinsics = fisheye_stream.as<rs2::video_stream_profile>().get_intrinsics();
- int width_img = intrinsics.width;
- int height_img = intrinsics.height;
- double t_resize = 0.f;
- double t_track = 0.f;
- while(b_continue_session)
- {
-
-
- rs2::frameset frame_set = pipe.wait_for_frames();
- double timestamp_ms = frame_set.get_timestamp();
-
- if(rs2::video_frame image_frame = frame_set.first_or_default(RS2_STREAM_FISHEYE))
- {
- rs2::video_frame frame = frame_set.get_fisheye_frame(1);
- imCV = cv::Mat(cv::Size(width_img, height_img), CV_8UC1, (void*)(frame.get_data()), cv::Mat::AUTO_STEP);
- if(imageScale != 1.f)
- {
- #ifdef REGISTER_TIMES
- #ifdef COMPILEDWITHC11
- std::chrono::steady_clock::time_point t_Start_Resize = std::chrono::steady_clock::now();
- #else
- std::chrono::monotonic_clock::time_point t_Start_Resize = std::chrono::monotonic_clock::now();
- #endif
- #endif
- int width = imCV.cols * imageScale;
- int height = imCV.rows * imageScale;
- cv::resize(imCV, imCV, cv::Size(width, height));
- #ifdef REGISTER_TIMES
- #ifdef COMPILEDWITHC11
- std::chrono::steady_clock::time_point t_End_Resize = std::chrono::steady_clock::now();
- #else
- std::chrono::monotonic_clock::time_point t_End_Resize = std::chrono::monotonic_clock::now();
- #endif
- t_resize = std::chrono::duration_cast<std::chrono::duration<double,std::milli> >(t_End_Resize - t_Start_Resize).count();
- SLAM.InsertResizeTime(t_resize);
- #endif
- }
-
-
-
- #ifdef REGISTER_TIMES
- #ifdef COMPILEDWITHC11
- std::chrono::steady_clock::time_point t1 = std::chrono::steady_clock::now();
- #else
- std::chrono::monotonic_clock::time_point t1 = std::chrono::monotonic_clock::now();
- #endif
- #endif
-
- SLAM.TrackMonocular(imCV, timestamp_ms);
- #ifdef REGISTER_TIMES
- #ifdef COMPILEDWITHC11
- std::chrono::steady_clock::time_point t2 = std::chrono::steady_clock::now();
- #else
- std::chrono::monotonic_clock::time_point t2 = std::chrono::monotonic_clock::now();
- #endif
- t_track = t_resize + std::chrono::duration_cast<std::chrono::duration<double,std::milli> >(t2 - t1).count();
- SLAM.InsertTrackTime(t_track);
- #endif
- }
- }
- pipe.stop();
-
- SLAM.Shutdown();
- return 0;
- }
|