2020-12-01 11:58:17 +08:00
|
|
|
/**
|
|
|
|
* This file is part of ORB-SLAM3
|
|
|
|
*
|
2022-03-28 21:20:28 +08:00
|
|
|
* Copyright (C) 2017-2021 Carlos Campos, Richard Elvira, Juan J. Gómez Rodríguez, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
|
2020-12-01 11:58:17 +08:00
|
|
|
* Copyright (C) 2014-2016 Raúl Mur-Artal, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
|
|
|
|
*
|
|
|
|
* ORB-SLAM3 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
|
|
|
|
* License as published by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* ORB-SLAM3 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
|
|
|
|
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with ORB-SLAM3.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef SYSTEM_H
|
|
|
|
#define SYSTEM_H
|
|
|
|
|
2022-03-28 21:20:28 +08:00
|
|
|
|
2020-12-01 11:58:17 +08:00
|
|
|
#include <unistd.h>
|
|
|
|
#include<stdio.h>
|
|
|
|
#include<stdlib.h>
|
|
|
|
#include<string>
|
|
|
|
#include<thread>
|
|
|
|
#include<opencv2/core/core.hpp>
|
|
|
|
|
|
|
|
#include "Tracking.h"
|
|
|
|
#include "FrameDrawer.h"
|
|
|
|
#include "MapDrawer.h"
|
|
|
|
#include "Atlas.h"
|
|
|
|
#include "LocalMapping.h"
|
|
|
|
#include "LoopClosing.h"
|
|
|
|
#include "KeyFrameDatabase.h"
|
|
|
|
#include "ORBVocabulary.h"
|
|
|
|
#include "Viewer.h"
|
|
|
|
#include "ImuTypes.h"
|
2022-03-28 21:20:28 +08:00
|
|
|
#include "Settings.h"
|
2020-12-01 11:58:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
namespace ORB_SLAM3
|
|
|
|
{
|
|
|
|
|
|
|
|
class Verbose
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum eLevel
|
|
|
|
{
|
|
|
|
VERBOSITY_QUIET=0,
|
|
|
|
VERBOSITY_NORMAL=1,
|
|
|
|
VERBOSITY_VERBOSE=2,
|
|
|
|
VERBOSITY_VERY_VERBOSE=3,
|
|
|
|
VERBOSITY_DEBUG=4
|
|
|
|
};
|
|
|
|
|
|
|
|
static eLevel th;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static void PrintMess(std::string str, eLevel lev)
|
|
|
|
{
|
|
|
|
if(lev <= th)
|
|
|
|
cout << str << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SetTh(eLevel _th)
|
|
|
|
{
|
|
|
|
th = _th;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class Viewer;
|
|
|
|
class FrameDrawer;
|
2022-03-28 21:20:28 +08:00
|
|
|
class MapDrawer;
|
2020-12-01 11:58:17 +08:00
|
|
|
class Atlas;
|
|
|
|
class Tracking;
|
|
|
|
class LocalMapping;
|
|
|
|
class LoopClosing;
|
2022-03-28 21:20:28 +08:00
|
|
|
class Settings;
|
2020-12-01 11:58:17 +08:00
|
|
|
|
|
|
|
class System
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Input sensor
|
|
|
|
enum eSensor{
|
|
|
|
MONOCULAR=0,
|
|
|
|
STEREO=1,
|
|
|
|
RGBD=2,
|
|
|
|
IMU_MONOCULAR=3,
|
2022-03-28 21:20:28 +08:00
|
|
|
IMU_STEREO=4,
|
|
|
|
IMU_RGBD=5,
|
2020-12-01 11:58:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// File type
|
2022-03-28 21:20:28 +08:00
|
|
|
enum FileType{
|
2020-12-01 11:58:17 +08:00
|
|
|
TEXT_FILE=0,
|
|
|
|
BINARY_FILE=1,
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
2022-03-28 21:20:28 +08:00
|
|
|
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
|
2020-12-01 11:58:17 +08:00
|
|
|
// Initialize the SLAM system. It launches the Local Mapping, Loop Closing and Viewer threads.
|
2022-03-28 21:20:28 +08:00
|
|
|
System(const string &strVocFile, const string &strSettingsFile, const eSensor sensor, const bool bUseViewer = true, const int initFr = 0, const string &strSequence = std::string());
|
2020-12-01 11:58:17 +08:00
|
|
|
|
|
|
|
// Proccess the given stereo frame. Images must be synchronized and rectified.
|
|
|
|
// Input images: RGB (CV_8UC3) or grayscale (CV_8U). RGB is converted to grayscale.
|
|
|
|
// Returns the camera pose (empty if tracking fails).
|
2022-03-28 21:20:28 +08:00
|
|
|
Sophus::SE3f TrackStereo(const cv::Mat &imLeft, const cv::Mat &imRight, const double ×tamp, const vector<IMU::Point>& vImuMeas = vector<IMU::Point>(), string filename="");
|
2020-12-01 11:58:17 +08:00
|
|
|
|
|
|
|
// Process the given rgbd frame. Depthmap must be registered to the RGB frame.
|
|
|
|
// Input image: RGB (CV_8UC3) or grayscale (CV_8U). RGB is converted to grayscale.
|
|
|
|
// Input depthmap: Float (CV_32F).
|
|
|
|
// Returns the camera pose (empty if tracking fails).
|
2022-03-28 21:20:28 +08:00
|
|
|
Sophus::SE3f TrackRGBD(const cv::Mat &im, const cv::Mat &depthmap, const double ×tamp, const vector<IMU::Point>& vImuMeas = vector<IMU::Point>(), string filename="");
|
2020-12-01 11:58:17 +08:00
|
|
|
|
|
|
|
// Proccess the given monocular frame and optionally imu data
|
|
|
|
// Input images: RGB (CV_8UC3) or grayscale (CV_8U). RGB is converted to grayscale.
|
|
|
|
// Returns the camera pose (empty if tracking fails).
|
2022-03-28 21:20:28 +08:00
|
|
|
Sophus::SE3f TrackMonocular(const cv::Mat &im, const double ×tamp, const vector<IMU::Point>& vImuMeas = vector<IMU::Point>(), string filename="");
|
2020-12-01 11:58:17 +08:00
|
|
|
|
|
|
|
|
|
|
|
// This stops local mapping thread (map building) and performs only camera tracking.
|
|
|
|
void ActivateLocalizationMode();
|
|
|
|
// This resumes local mapping thread and performs SLAM again.
|
|
|
|
void DeactivateLocalizationMode();
|
|
|
|
|
|
|
|
// Returns true if there have been a big map change (loop closure, global BA)
|
|
|
|
// since last call to this function
|
|
|
|
bool MapChanged();
|
|
|
|
|
|
|
|
// Reset the system (clear Atlas or the active map)
|
|
|
|
void Reset();
|
|
|
|
void ResetActiveMap();
|
|
|
|
|
|
|
|
// All threads will be requested to finish.
|
|
|
|
// It waits until all threads have finished.
|
|
|
|
// This function must be called before saving the trajectory.
|
|
|
|
void Shutdown();
|
2022-03-28 21:20:28 +08:00
|
|
|
bool isShutDown();
|
2020-12-01 11:58:17 +08:00
|
|
|
|
|
|
|
// Save camera trajectory in the TUM RGB-D dataset format.
|
|
|
|
// Only for stereo and RGB-D. This method does not work for monocular.
|
|
|
|
// Call first Shutdown()
|
|
|
|
// See format details at: http://vision.in.tum.de/data/datasets/rgbd-dataset
|
|
|
|
void SaveTrajectoryTUM(const string &filename);
|
|
|
|
|
|
|
|
// Save keyframe poses in the TUM RGB-D dataset format.
|
|
|
|
// This method works for all sensor input.
|
|
|
|
// Call first Shutdown()
|
|
|
|
// See format details at: http://vision.in.tum.de/data/datasets/rgbd-dataset
|
|
|
|
void SaveKeyFrameTrajectoryTUM(const string &filename);
|
|
|
|
|
|
|
|
void SaveTrajectoryEuRoC(const string &filename);
|
|
|
|
void SaveKeyFrameTrajectoryEuRoC(const string &filename);
|
|
|
|
|
2022-03-28 21:20:28 +08:00
|
|
|
void SaveTrajectoryEuRoC(const string &filename, Map* pMap);
|
|
|
|
void SaveKeyFrameTrajectoryEuRoC(const string &filename, Map* pMap);
|
|
|
|
|
|
|
|
// Save data used for initialization debug
|
|
|
|
void SaveDebugData(const int &iniIdx);
|
|
|
|
|
2020-12-01 11:58:17 +08:00
|
|
|
// Save camera trajectory in the KITTI dataset format.
|
|
|
|
// Only for stereo and RGB-D. This method does not work for monocular.
|
|
|
|
// Call first Shutdown()
|
|
|
|
// See format details at: http://www.cvlibs.net/datasets/kitti/eval_odometry.php
|
|
|
|
void SaveTrajectoryKITTI(const string &filename);
|
|
|
|
|
|
|
|
// TODO: Save/Load functions
|
|
|
|
// SaveMap(const string &filename);
|
|
|
|
// LoadMap(const string &filename);
|
|
|
|
|
|
|
|
// Information from most recent processed frame
|
|
|
|
// You can call this right after TrackMonocular (or stereo or RGBD)
|
|
|
|
int GetTrackingState();
|
|
|
|
std::vector<MapPoint*> GetTrackedMapPoints();
|
|
|
|
std::vector<cv::KeyPoint> GetTrackedKeyPointsUn();
|
|
|
|
|
|
|
|
// For debugging
|
|
|
|
double GetTimeFromIMUInit();
|
|
|
|
bool isLost();
|
|
|
|
bool isFinished();
|
|
|
|
|
|
|
|
void ChangeDataset();
|
|
|
|
|
2022-03-28 21:20:28 +08:00
|
|
|
float GetImageScale();
|
|
|
|
|
2021-08-09 19:34:51 +08:00
|
|
|
#ifdef REGISTER_TIMES
|
|
|
|
void InsertRectTime(double& time);
|
2022-03-28 21:20:28 +08:00
|
|
|
void InsertResizeTime(double& time);
|
2021-08-09 19:34:51 +08:00
|
|
|
void InsertTrackTime(double& time);
|
|
|
|
#endif
|
2020-12-01 11:58:17 +08:00
|
|
|
|
2021-08-09 19:34:51 +08:00
|
|
|
private:
|
2020-12-01 11:58:17 +08:00
|
|
|
|
2022-03-28 21:20:28 +08:00
|
|
|
void SaveAtlas(int type);
|
|
|
|
bool LoadAtlas(int type);
|
|
|
|
|
|
|
|
string CalculateCheckSum(string filename, int type);
|
|
|
|
|
2020-12-01 11:58:17 +08:00
|
|
|
// Input sensor
|
|
|
|
eSensor mSensor;
|
|
|
|
|
|
|
|
// ORB vocabulary used for place recognition and feature matching.
|
|
|
|
ORBVocabulary* mpVocabulary;
|
|
|
|
|
|
|
|
// KeyFrame database for place recognition (relocalization and loop detection).
|
|
|
|
KeyFrameDatabase* mpKeyFrameDatabase;
|
|
|
|
|
2022-03-28 21:20:28 +08:00
|
|
|
// Map structure that stores the pointers to all KeyFrames and MapPoints.
|
|
|
|
//Map* mpMap;
|
2020-12-01 11:58:17 +08:00
|
|
|
Atlas* mpAtlas;
|
|
|
|
|
|
|
|
// Tracker. It receives a frame and computes the associated camera pose.
|
|
|
|
// It also decides when to insert a new keyframe, create some new MapPoints and
|
|
|
|
// performs relocalization if tracking fails.
|
|
|
|
Tracking* mpTracker;
|
|
|
|
|
|
|
|
// Local Mapper. It manages the local map and performs local bundle adjustment.
|
|
|
|
LocalMapping* mpLocalMapper;
|
|
|
|
|
|
|
|
// Loop Closer. It searches loops with every new keyframe. If there is a loop it performs
|
|
|
|
// a pose graph optimization and full bundle adjustment (in a new thread) afterwards.
|
|
|
|
LoopClosing* mpLoopCloser;
|
|
|
|
|
|
|
|
// The viewer draws the map and the current camera pose. It uses Pangolin.
|
|
|
|
Viewer* mpViewer;
|
|
|
|
|
|
|
|
FrameDrawer* mpFrameDrawer;
|
|
|
|
MapDrawer* mpMapDrawer;
|
|
|
|
|
|
|
|
// System threads: Local Mapping, Loop Closing, Viewer.
|
|
|
|
// The Tracking thread "lives" in the main execution thread that creates the System object.
|
|
|
|
std::thread* mptLocalMapping;
|
|
|
|
std::thread* mptLoopClosing;
|
|
|
|
std::thread* mptViewer;
|
|
|
|
|
|
|
|
// Reset flag
|
|
|
|
std::mutex mMutexReset;
|
|
|
|
bool mbReset;
|
|
|
|
bool mbResetActiveMap;
|
|
|
|
|
|
|
|
// Change mode flags
|
|
|
|
std::mutex mMutexMode;
|
|
|
|
bool mbActivateLocalizationMode;
|
|
|
|
bool mbDeactivateLocalizationMode;
|
|
|
|
|
2022-03-28 21:20:28 +08:00
|
|
|
// Shutdown flag
|
|
|
|
bool mbShutDown;
|
|
|
|
|
2020-12-01 11:58:17 +08:00
|
|
|
// Tracking state
|
|
|
|
int mTrackingState;
|
|
|
|
std::vector<MapPoint*> mTrackedMapPoints;
|
|
|
|
std::vector<cv::KeyPoint> mTrackedKeyPointsUn;
|
|
|
|
std::mutex mMutexState;
|
2022-03-28 21:20:28 +08:00
|
|
|
|
|
|
|
//
|
|
|
|
string mStrLoadAtlasFromFile;
|
|
|
|
string mStrSaveAtlasToFile;
|
|
|
|
|
|
|
|
string mStrVocabularyFilePath;
|
|
|
|
|
|
|
|
Settings* settings_;
|
2020-12-01 11:58:17 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}// namespace ORB_SLAM
|
|
|
|
|
|
|
|
#endif // SYSTEM_H
|