32                const std::string & map_file, 
bool load_map): 
    33                mSensor(sensor), mbReset(false),mbActivateLocalizationMode(false), mbDeactivateLocalizationMode(false),
    34                map_file(map_file), load_map(load_map)
    38     "ORB-SLAM2 Copyright (C) 2014-2016 Raul Mur-Artal, University of Zaragoza." << endl <<
    39     "This program comes with ABSOLUTELY NO WARRANTY;" << endl  <<
    40     "This is free software, and you are welcome to redistribute it" << endl <<
    41     "under certain conditions. See LICENSE.txt." << endl << endl;
    43     cout << 
"OpenCV version : " << CV_VERSION << endl;
    44     cout << 
"Major version : " << CV_MAJOR_VERSION << endl;
    45     cout << 
"Minor version : " << CV_MINOR_VERSION << endl;
    46     cout << 
"Subminor version : " << CV_SUBMINOR_VERSION << endl;
    48     cout << 
"Input sensor was set to: ";
    51         cout << 
"Monocular" << endl;
    53         cout << 
"Stereo" << endl;
    55         cout << 
"RGB-D" << endl;
    58     cout << endl << 
"Loading ORB Vocabulary." << endl;
    67         cerr << 
"Cannot find binary file for vocabulary. " << endl;
    68         cerr << 
"Failed to open at: " << strVocFile+
".bin" << endl;
    69         cerr << 
"Trying to open the text file. This could take a while..." << endl;
    73             cerr << 
"Wrong path to vocabulary. " << endl;
    74             cerr << 
"Failed to open at: " << strVocFile << endl;
    77         cerr << 
"Saving the vocabulary to binary for the next time to " << strVocFile+
".bin" << endl;
    81     cout << 
"Vocabulary loaded!" << endl << endl;
    85     if (load_map && 
LoadMap(map_file)) {
    86         std::cout << 
"Using loaded map with " << 
mpMap->
MapPointsInMap() << 
" points\n" << std::endl;
   129         cerr << 
"ERROR: you called TrackStereo but input sensor was not set to STEREO." << endl;
   143                 std::this_thread::sleep_for(std::chrono::microseconds(1000));
   180         cerr << 
"ERROR: you called TrackRGBD but input sensor was not set to RGBD." << endl;
   194                 std::this_thread::sleep_for(std::chrono::microseconds(1000));
   231         cerr << 
"ERROR: you called TrackMonocular but input sensor was not set to Monocular." << endl;
   245                 std::this_thread::sleep_for(std::chrono::microseconds(1000));
   311         std::this_thread::sleep_for(std::chrono::microseconds(5000));
   317     cout << endl << 
"Saving camera trajectory to " << filename << 
" ..." << endl;
   320         cerr << 
"ERROR: SaveTrajectoryTUM cannot be used for monocular." << endl;
   329     cv::Mat Two = vpKFs[0]->GetPoseInverse();
   332     f.open(filename.c_str());
   352         cv::Mat Trw = cv::Mat::eye(4,4,CV_32F);
   363         cv::Mat Tcw = (*lit)*Trw;
   364         cv::Mat Rwc = Tcw.rowRange(0,3).colRange(0,3).t();
   365         cv::Mat twc = -Rwc*Tcw.rowRange(0,3).col(3);
   369         f << setprecision(6) << *lT << 
" " <<  setprecision(9) << twc.at<
float>(0) << 
" " << twc.at<
float>(1) << 
" " << twc.at<
float>(2) << 
" " << q[0] << 
" " << q[1] << 
" " << q[2] << 
" " << q[3] << endl;
   372     cout << endl << 
"trajectory saved!" << endl;
   378     cout << endl << 
"Saving keyframe trajectory to " << filename << 
" ..." << endl;
   388     f.open(filename.c_str());
   391     for(
size_t i=0; i<vpKFs.size(); i++)
   403         f << setprecision(6) << pKF->
mTimeStamp << setprecision(7) << 
" " << t.at<
float>(0) << 
" " << t.at<
float>(1) << 
" " << t.at<
float>(2)
   404           << 
" " << q[0] << 
" " << q[1] << 
" " << q[2] << 
" " << q[3] << endl;
   409     cout << endl << 
"trajectory saved!" << endl;
   414     cout << endl << 
"Saving camera trajectory to " << filename << 
" ..." << endl;
   417         cerr << 
"ERROR: SaveTrajectoryKITTI cannot be used for monocular." << endl;
   426     cv::Mat Two = vpKFs[0]->GetPoseInverse();
   429     f.open(filename.c_str());
   444         cv::Mat Trw = cv::Mat::eye(4,4,CV_32F);
   455         cv::Mat Tcw = (*lit)*Trw;
   456         cv::Mat Rwc = Tcw.rowRange(0,3).colRange(0,3).t();
   457         cv::Mat twc = -Rwc*Tcw.rowRange(0,3).col(3);
   459         f << setprecision(9) << Rwc.at<
float>(0,0) << 
" " << Rwc.at<
float>(0,1)  << 
" " << Rwc.at<
float>(0,2) << 
" "  << twc.at<
float>(0) << 
" " <<
   460              Rwc.at<
float>(1,0) << 
" " << Rwc.at<
float>(1,1)  << 
" " << Rwc.at<
float>(1,2) << 
" "  << twc.at<
float>(1) << 
" " <<
   461              Rwc.at<
float>(2,0) << 
" " << Rwc.at<
float>(2,1)  << 
" " << Rwc.at<
float>(2,2) << 
" "  << twc.at<
float>(2) << endl;
   464     cout << endl << 
"trajectory saved!" << endl;
   503     struct rlimit rlimit;
   504     int operation_result;
   506     operation_result = getrlimit(RLIMIT_STACK, &rlimit);
   507     if (operation_result != 0) {
   508         std::cerr << 
"Error getting the call stack struct" << std::endl;
   512     if (kNewStackSize > rlimit.rlim_max) {
   513         std::cerr << 
"Requested call stack size too large" << std::endl;
   517     if (rlimit.rlim_cur <= kNewStackSize) {
   518         rlimit.rlim_cur = kNewStackSize;
   519         operation_result = setrlimit(RLIMIT_STACK, &rlimit);
   520         if (operation_result != 0) {
   521             std::cerr << 
"Setrlimit returned result: " << operation_result << std::endl;
   531     struct rlimit rlimit;
   532     int operation_result;
   534     operation_result = getrlimit(RLIMIT_STACK, &rlimit);
   535     if (operation_result != 0) {
   536         std::cerr << 
"Error getting the call stack struct" << std::endl;
   537         return 16 * 1024L * 1024L; 
   540     return rlimit.rlim_cur;
   568   std::cout << 
"Enable localization only: " << (localize_only?
"true":
"false") << std::endl;
   575     std::ofstream out(filename, std::ios_base::binary);
   577         std::cerr << 
"cannot write to map file: " << 
map_file << std::endl;
   581     const rlim_t kNewStackSize = 64L * 1024L * 1024L;   
   584         std::cerr << 
"Error changing the call stack size; Aborting" << std::endl;
   589         std::cout << 
"saving map file: " << 
map_file << std::flush;
   590         boost::archive::binary_oarchive oa(out, boost::archive::no_header);
   593         std::cout << 
" ... done" << std::endl;
   595     } 
catch (
const std::exception &e) {
   596         std::cerr << e.what() << std::endl;
   600         std::cerr << 
"Unknows exeption" << std::endl;
   612     std::ifstream in(filename, std::ios_base::binary);
   614         cerr << 
"Cannot open map file: " << 
map_file << 
" , you need create it first!" << std::endl;
   618     const rlim_t kNewStackSize = 64L * 1024L * 1024L;   
   621         std::cerr << 
"Error changing the call stack size; Aborting" << std::endl;
   625     std::cout << 
"Loading map file: " << 
map_file << std::flush;
   626     boost::archive::binary_iarchive ia(in, boost::archive::no_header);
   630     std::cout << 
" ... done" << std::endl;
   632     std::cout << 
"Map reconstructing" << flush;
   633     vector<ORB_SLAM2::KeyFrame*> vpKFS = mpMap->GetAllKeyFrames();
   634     unsigned long mnFrameId = 0;
   635     for (
auto it:vpKFS) {
   640         if (it->mnFrameId > mnFrameId) {
   641             mnFrameId = it->mnFrameId;
   647     std::cout << 
" ... done" << std::endl;
 
KeyFrameDatabase * mpKeyFrameDatabase
ORBVocabulary * mpVocabulary
void saveToBinFile(const std::string &filename) const 
std::vector< MapPoint * > mvpMapPoints
std::vector< MapPoint * > GetTrackedMapPoints()
cv::Mat GetCameraCenter()
void SetLoopClosing(LoopClosing *pLoopClosing)
cv::Mat current_position_
std::vector< MapPoint * > mTrackedMapPoints
bool SaveMap(const string &filename)
rlim_t GetCurrentCallStackSize()
void SetTracker(Tracking *pTracker)
void TrackMonocular(const cv::Mat &im, const double ×tamp)
bool currently_localizing_only_
std::thread * mptLocalMapping
LoopClosing * mpLoopCloser
bool SetCallStackSize(const rlim_t kNewStackSize)
std::vector< KeyFrame * > GetAllKeyFrames()
void SetLocalMapper(LocalMapping *pLocalMapper)
cv::Mat GrabImageRGBD(const cv::Mat &imRGB, const cv::Mat &imD, const double ×tamp)
System(const string strVocFile, const eSensor sensor, ORBParameters ¶meters, const std::string &map_file="", bool load_map=false)
LocalMapping * mpLocalMapper
static std::vector< float > toQuaternion(const cv::Mat &M)
void TrackStereo(const cv::Mat &imLeft, const cv::Mat &imRight, const double ×tamp)
void SetLocalMapper(LocalMapping *pLocalMapper)
void EnableLocalizationOnly(bool localize_only)
cv::Mat GrabImageStereo(const cv::Mat &imRectLeft, const cv::Mat &imRectRight, const double ×tamp)
std::vector< cv::KeyPoint > GetTrackedKeyPointsUn()
std::vector< cv::KeyPoint > mvKeysUn
std::vector< MapPoint * > GetAllMapPoints()
static std::mutex mGlobalMutex
static bool lId(KeyFrame *pKF1, KeyFrame *pKF2)
void SetTracker(Tracking *pTracker)
std::thread * mptLoopClosing
std::vector< cv::KeyPoint > mTrackedKeyPointsUn
bool mbActivateLocalizationMode
void TrackRGBD(const cv::Mat &im, const cv::Mat &depthmap, const double ×tamp)
void SaveTrajectoryKITTI(const string &filename)
void SaveTrajectoryTUM(const string &filename)
list< double > mlFrameTimes
static long unsigned int nNextId
long unsigned int MapPointsInMap()
void SetMinimumKeyFrames(int min_num_kf)
bool loadFromTextFile(const std::string &filename)
void SetORBvocabulary(ORBVocabulary *porbv)
cv::Mat GetCurrentPosition()
void InformOnlyTracking(const bool &flag)
void SetLoopCloser(LoopClosing *pLoopCloser)
bool mbDeactivateLocalizationMode
DBoW2::TemplatedVocabulary< DBoW2::FORB::TDescriptor, DBoW2::FORB > ORBVocabulary
list< KeyFrame * > mlpReferences
void DeactivateLocalizationMode()
FrameDrawer * mpFrameDrawer
bool loadFromBinFile(const std::string &filename)
list< cv::Mat > mlRelativeFramePoses
std::vector< MapPoint * > GetAllMapPoints()
void SaveKeyFrameTrajectoryTUM(const string &filename)
bool LoadMap(const string &filename)
void ActivateLocalizationMode()
cv::Mat GrabImageMonocular(const cv::Mat &im, const double ×tamp)
cv::Mat DrawCurrentFrame()
void SetMinimumKeyFrames(int min_num_kf)
int GetLastBigChangeIdx()