123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188 |
- #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: ./stereo_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 << endl << "-------" << endl;
- cout.precision(17);
-
-
- ORB_SLAM3::System SLAM(argv[1],argv[2],ORB_SLAM3::System::STEREO, true, 0, file_name);
- float imageScale = SLAM.GetImageScale();
- cv::Mat imLeft, imRight;
- vector<ORB_SLAM3::IMU::Point> vImuMeas;
- rs2::stream_profile fisheye_stream_left = pipe_profile.get_stream(RS2_STREAM_FISHEYE, 1);
- rs2_intrinsics intrinsics_left = fisheye_stream_left.as<rs2::video_stream_profile>().get_intrinsics();
- int width_left = intrinsics_left.width;
- int height_left = intrinsics_left.height;
- rs2::stream_profile fisheye_stream_right = pipe_profile.get_stream(RS2_STREAM_FISHEYE, 2);
- rs2_intrinsics intrinsics_right = fisheye_stream_right.as<rs2::video_stream_profile>().get_intrinsics();
- int width_right = intrinsics_right.width;
- int height_right = intrinsics_right.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 = frame_set.get_timestamp();
- if(rs2::video_frame image_frame = frame_set.first_or_default(RS2_STREAM_FISHEYE))
- {
- rs2::video_frame frame_left = frame_set.get_fisheye_frame(1);
- rs2::video_frame frame_right = frame_set.get_fisheye_frame(2);
- imLeft = cv::Mat(cv::Size(width_left, height_left), CV_8UC1, (void*)(frame_left.get_data()), cv::Mat::AUTO_STEP);
- imRight = cv::Mat(cv::Size(width_right, height_right), CV_8UC1, (void*)(frame_right.get_data()), cv::Mat::AUTO_STEP);
- if(imageScale != 1.f)
- {
- #ifdef REGISTER_TIMES
- #ifdef COMPILEDWITHC14
- 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 = imLeft.cols * imageScale;
- int height = imLeft.rows * imageScale;
- cv::resize(imLeft, imLeft, cv::Size(width, height));
- cv::resize(imRight, imRight, cv::Size(width, height));
- #ifdef REGISTER_TIMES
- #ifdef COMPILEDWITHC14
- 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 COMPILEDWITHC14
- 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.TrackStereo(imLeft, imRight, timestamp);
- #ifdef REGISTER_TIMES
- #ifdef COMPILEDWITHC14
- 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
- #endif
- #ifdef REGISTER_TIMES
- 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;
- }
|