Tracking.h
Go to the documentation of this file.
1 
22 #ifndef TRACKING_H
23 #define TRACKING_H
24 
25 #include<opencv2/core/core.hpp>
26 #include<opencv2/features2d/features2d.hpp>
27 #include<opencv2/imgproc/types_c.h>
28 
29 #include <ros/ros.h>
30 #include <sensor_msgs/CameraInfo.h>
31 
32 
33 #include"FrameDrawer.h"
34 #include"Map.h"
35 #include"LocalMapping.h"
36 #include"LoopClosing.h"
37 #include"Frame.h"
38 #include "ORBVocabulary.h"
39 #include"KeyFrameDatabase.h"
40 #include"ORBextractor.h"
41 #include "Initializer.h"
42 #include "System.h"
43 
44 #include <mutex>
45 
46 namespace ORB_SLAM2
47 {
48 
49 class FrameDrawer;
50 class Map;
51 class LocalMapping;
52 class LoopClosing;
53 class System;
54 
56  // general parameters for the ORB detector
58  bool RGB;
60  // camera parameters
61  float fx, fy, cx, cy, baseline;
62  float k1, k2, p1, p2, k3;
63 };
64 
65 class Tracking
66 {
67 
68 public:
69  Tracking(System* pSys, ORBVocabulary* pVoc, FrameDrawer* pFrameDrawer, Map* pMap,
70  KeyFrameDatabase* pKFDB, const int sensor, ORBParameters& parameters);
71 
72  // Preprocess the input and call Track(). Extract features and performs stereo matching.
73  cv::Mat GrabImageStereo(const cv::Mat &imRectLeft,const cv::Mat &imRectRight, const double &timestamp);
74  cv::Mat GrabImageRGBD(const cv::Mat &imRGB,const cv::Mat &imD, const double &timestamp);
75  cv::Mat GrabImageMonocular(const cv::Mat &im, const double &timestamp);
76 
77  void SetLocalMapper(LocalMapping* pLocalMapper);
78  void SetLoopClosing(LoopClosing* pLoopClosing);
79  void SetMinimumKeyFrames (int min_num_kf) {mnMinimumKeyFrames = min_num_kf;}
80 
81  // Load new settings
82  // The focal lenght should be similar or scale prediction will fail when projecting points
83  // TODO: Modify MapPoint::PredictScale to take into account focal lenght
84  void ChangeCalibration(const string &strSettingPath);
85 
86  // Use this function if you have deactivated local mapping and you only want to localize the camera.
87  void InformOnlyTracking(const bool &flag);
88 
89 
90 public:
91 
92  // Tracking states
94  SYSTEM_NOT_READY=-1,
95  NO_IMAGES_YET=0,
96  NOT_INITIALIZED=1,
97  OK=2,
98  LOST=3
99  };
100 
103 
104  // Input sensor
105  int mSensor;
106 
107  // Current Frame
109  cv::Mat mImGray;
110 
111  // Initialization Variables (Monocular)
112  std::vector<int> mvIniLastMatches;
113  std::vector<int> mvIniMatches;
114  std::vector<cv::Point2f> mvbPrevMatched;
115  std::vector<cv::Point3f> mvIniP3D;
117 
118  // Lists used to recover the full camera trajectory at the end of the execution.
119  // Basically we store the reference keyframe for each frame and its relative transformation
120  list<cv::Mat> mlRelativeFramePoses;
121  list<KeyFrame*> mlpReferences;
122  list<double> mlFrameTimes;
123  list<bool> mlbLost;
124 
125  // True if local mapping is deactivated and we are performing only localization
127 
128  void Reset();
129 
130 protected:
131 
132  // Main tracking function. It is independent of the input sensor.
133  void Track();
134 
135  // Map initialization for stereo and RGB-D
136  void StereoInitialization();
137 
138  // Map initialization for monocular
139  void MonocularInitialization();
140  void CreateInitialMapMonocular();
141 
142  void CheckReplacedInLastFrame();
143  bool TrackReferenceKeyFrame();
144  void UpdateLastFrame();
145  bool TrackWithMotionModel();
146 
147  bool Relocalization();
148 
149  void UpdateLocalMap();
150  void UpdateLocalPoints();
151  void UpdateLocalKeyFrames();
152 
153  bool TrackLocalMap();
154  void SearchLocalPoints();
155 
156  bool NeedNewKeyFrame();
157  void CreateNewKeyFrame();
158 
159  // In case of performing only localization, this flag is true when there are no matches to
160  // points in the map. Still tracking will continue if there are enough matches with temporal points.
161  // In that case we are doing visual odometry. The system will try to do relocalization to recover
162  // "zero-drift" localization to the map.
163  bool mbVO;
164 
165  //Numer of Keyframes a map has to have to not get a reset in the event of lost tracking.
167 
168  //Other Thread Pointers
171 
172  //ORB
173  ORBextractor* mpORBextractorLeft, *mpORBextractorRight;
175 
176  //BoW
179 
180  // Initalization (only for monocular)
182 
183  //Local Map
185  std::vector<KeyFrame*> mvpLocalKeyFrames;
186  std::vector<MapPoint*> mvpLocalMapPoints;
187 
188  // System
190 
191  //Drawers
193 
194  //Map
196 
197  //Calibration matrix
198  cv::Mat mK;
199  cv::Mat mDistCoef;
200  float mbf;
201 
202  //New KeyFrame rules (according to fps)
205 
206  // Threshold close/far points
207  // Points seen as close by the stereo/RGBD sensor are considered reliable
208  // and inserted from just one frame. Far points requiere a match in two keyframes.
209  float mThDepth;
210 
211  // For RGB-D inputs only. For some datasets (e.g. TUM) the depthmap values are scaled.
213 
214  //Current matches in frame
216 
217  //Last Frame, KeyFrame and Relocalisation Info
220  unsigned int mnLastKeyFrameId;
221  unsigned int mnLastRelocFrameId;
222 
223  //Motion Model
224  cv::Mat mVelocity;
225 
226  //Color order (true RGB, false BGR, ignored if grayscale)
227  bool mbRGB;
228 
229  list<MapPoint*> mlpTemporalPoints;
230 
231 
232  // These parameters are for the ORB features extractor
235  int nLevels;
238 };
239 
240 } //namespace ORB_SLAM
241 
242 #endif // TRACKING_H
std::vector< MapPoint * > mvpLocalMapPoints
Definition: Tracking.h:186
std::vector< KeyFrame * > mvpLocalKeyFrames
Definition: Tracking.h:185
unsigned int mnLastKeyFrameId
Definition: Tracking.h:220
unsigned int mnLastRelocFrameId
Definition: Tracking.h:221
KeyFrame * mpLastKeyFrame
Definition: Tracking.h:218
std::vector< int > mvIniMatches
Definition: Tracking.h:113
Initializer * mpInitializer
Definition: Tracking.h:181
list< bool > mlbLost
Definition: Tracking.h:123
FrameDrawer * mpFrameDrawer
Definition: Tracking.h:192
ORBVocabulary * mpORBVocabulary
Definition: Tracking.h:177
System * mpSystem
Definition: Tracking.h:189
KeyFrameDatabase * mpKeyFrameDB
Definition: Tracking.h:178
eTrackingState mState
Definition: Tracking.h:101
LoopClosing * mpLoopClosing
Definition: Tracking.h:170
list< double > mlFrameTimes
Definition: Tracking.h:122
KeyFrame * mpReferenceKF
Definition: Tracking.h:184
void SetMinimumKeyFrames(int min_num_kf)
Definition: Tracking.h:79
ORBextractor * mpIniORBextractor
Definition: Tracking.h:174
list< KeyFrame * > mlpReferences
Definition: Tracking.h:121
eTrackingState mLastProcessedState
Definition: Tracking.h:102
std::vector< int > mvIniLastMatches
Definition: Tracking.h:112
list< MapPoint * > mlpTemporalPoints
Definition: Tracking.h:229
list< cv::Mat > mlRelativeFramePoses
Definition: Tracking.h:120
LocalMapping * mpLocalMapper
Definition: Tracking.h:169
std::vector< cv::Point3f > mvIniP3D
Definition: Tracking.h:115
std::vector< cv::Point2f > mvbPrevMatched
Definition: Tracking.h:114
ORBextractor * mpORBextractorRight
Definition: Tracking.h:173


orb_slam2_ros
Author(s):
autogenerated on Wed Apr 21 2021 02:53:05