SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
WAISlamTools.h
Go to the documentation of this file.
1 #ifndef WAISLAMTOOLS_H
2 #define WAISLAMTOOLS_H
3 #include <WAIHelper.h>
4 #include <WAIKeyFrameDB.h>
5 #include <WAIMap.h>
6 #include <WAIOrbVocabulary.h>
7 #include <orb_slam/LocalMapping.h>
8 #include <orb_slam/LoopClosing.h>
9 #include <orb_slam/Initializer.h>
10 #include <orb_slam/ORBmatcher.h>
11 #include <orb_slam/Optimizer.h>
12 #include <orb_slam/PnPsolver.h>
13 #include <LocalMap.h>
14 #include <opencv2/core.hpp>
15 
16 //-----------------------------------------------------------------------------
18 {
19  Initializer* initializer;
21  std::vector<cv::Point2f> prevMatched; // all keypoints in initialFrame
22  std::vector<cv::Point3f> iniPoint3D;
23  std::vector<int> iniMatches; // has length of keypoints of initial frame and contains matched keypoint index in current frame
24 };
25 //-----------------------------------------------------------------------------
27 {
34 };
35 //-----------------------------------------------------------------------------
36 /*!
37  * This class should not be instanced. It contains only pure virtual methods
38  * and some variables with getter that are useful for slam in a subclass.
39  */
41 {
42 public:
43  static void drawKeyPointInfo(WAIFrame& frame,
44  cv::Mat& image,
45  float scale);
46  static void drawKeyPointMatches(WAIFrame& frame,
47  cv::Mat& image,
48  float scale);
49  static void drawInitInfo(WAIInitializerData& iniData,
50  WAIFrame& frame,
51  cv::Mat& imageBGR,
52  float scale);
53 
54  static bool initialize(WAIInitializerData& iniData,
55  WAIFrame& frame,
56  WAIOrbVocabulary* voc,
57  LocalMap& localMap,
58  int mapPointsNeeded = 100);
59 
60  static bool genInitialMap(WAIMap* globalMap,
61  LocalMapping* localMapper,
62  LoopClosing* loopCloser,
63  LocalMap& localMap);
64 
65  static bool oldInitialize(WAIFrame& frame,
66  WAIInitializerData& iniData,
67  WAIMap* map,
68  LocalMap& localMap,
69  LocalMapping* localMapper,
70  LoopClosing* loopCloser,
71  WAIOrbVocabulary* voc,
72  int mapPointsNeeded = 100);
73 
75  WAIMap* waiMap,
76  std::vector<cv::Point2f>& points2d,
77  std::vector<cv::Point3f>& points3d);
78 
79  static bool relocalization(WAIFrame& currentFrame,
80  WAIMap* waiMap,
81  LocalMap& localMap,
82  float minCommonWordFactor,
83  int& inliers,
84  bool minAccScoreFilter = false);
85 
86  static bool relocalizationGPS(WAIFrame& currentFrame,
87  WAIMap* waiMap,
88  LocalMap& localMap,
89  cv::Mat locENU,
90  cv::Mat dirENU,
91  float minCommonWordFactor,
92  int& inliers,
93  bool minAccScoreFilter);
94 
95  static bool tracking(WAIMap* map,
96  LocalMap& localMap,
97  WAIFrame& frame,
98  WAIFrame& lastFrame,
99  int lastRelocFrameId,
100  cv::Mat& velocity,
101  int& inliers);
102 
103  static bool strictTracking(WAIMap* map,
104  LocalMap& localMap,
105  WAIFrame& frame,
106  WAIFrame& lastFrame,
107  int lastRelocFrameId,
108  int& inliers);
109 
110  static bool trackLocalMap(LocalMap& localMap,
111  WAIFrame& frame,
112  int lastRelocFrameId,
113  int& inliers);
114 
115  static void mapping(WAIMap* map,
116  LocalMap& localMap,
117  LocalMapping* localMapper,
118  WAIFrame& frame,
119  int inliers,
120  const unsigned long lastRelocFrameId,
121  unsigned long& lastKeyFrameFrameId);
122 
123  static void strictMapping(WAIMap* map,
124  LocalMap& localMap,
125  LocalMapping* localMapper,
126  WAIFrame& frame,
127  int inliers,
128  const unsigned long lastRelocFrameId,
129  unsigned long& lastKeyFrameFrameId);
130 
131  static void motionModel(WAIFrame& frame,
132  WAIFrame& lastFrame,
133  cv::Mat& velocity,
134  cv::Mat& pose);
135 
136  static bool trackReferenceKeyFrame(LocalMap& map, WAIFrame& lastFrame, WAIFrame& frame);
137 
138  static bool strictTrackReferenceKeyFrame(LocalMap& map, WAIFrame& lastFrame, WAIFrame& frame);
139 
140  static bool trackWithMotionModel(cv::Mat velocity, WAIFrame& previousFrame, WAIFrame& frame);
141 
142  static void updateLocalMap(WAIFrame& frame, LocalMap& localMap);
143 
144  static int trackLocalMapPoints(LocalMap& localMap, int lastRelocFrameId, WAIFrame& frame);
145 
146  static bool needNewKeyFrame(WAIMap* globalMap,
147  LocalMap& localMap,
148  LocalMapping* localMapper,
149  WAIFrame& frame,
150  int nInliners,
151  const unsigned long lastRelocFrameId,
152  const unsigned long lastKeyFrameFrameId);
153 
154  static bool strictNeedNewKeyFrame(WAIMap* map,
155  LocalMap& localMap,
156  LocalMapping* localMapper,
157  WAIFrame& frame,
158  int nInliers,
159  const unsigned long lastRelocFrameId,
160  const unsigned long lastKeyFrameFrameId);
161 
162  static void createNewKeyFrame(LocalMapping* localMapper,
163  LocalMap& localMap,
164  WAIMap* globalMap,
165  WAIFrame& frame,
166  unsigned long& lastKeyFrameFrameId);
167 
168  static WAIFrame createMarkerFrame(std::string markerFile,
169  KPextractor* markerExtractor,
170  const cv::Mat& markerCameraIntrinsic,
171  WAIOrbVocabulary* voc);
172 
173  static bool findMarkerHomography(WAIFrame& markerFrame,
174  WAIKeyFrame* kfCand,
175  cv::Mat& homography,
176  int minMatches);
177 
178  static bool doMarkerMapPreprocessing(std::string markerFile,
179  cv::Mat& nodeTransform,
180  float markerWidthInM,
181  KPextractor* markerExtractor,
182  WAIMap* map,
183  const cv::Mat& markerCameraIntrinsic,
184  WAIOrbVocabulary* voc);
185 
186  static bool detectCycle(WAIKeyFrame* kf, std::set<WAIKeyFrame*>& visitedNode);
187 
188  static bool checkKFConnectionsTree(WAIMap* map);
189 
190 protected:
191  // virtual destructor is mandatory
192  virtual ~WAISlamTools() {}
194 
195  static void countReprojectionOutliers(WAIFrame& frame,
196  unsigned int& m,
197  unsigned int& n,
198  unsigned int& outliers);
199 
200  cv::Mat _distortion;
203  // extrinsic guess (e.g. estimated using gps and device orientation)
207 
208  std::unique_ptr<WAIMap> _globalMap;
209  LocalMap _localMap;
210  WAIOrbVocabulary* _voc = nullptr;
211  cv::Mat _velocity;
212  bool _initialized = false;
213 
214  LocalMapping* _localMapping = nullptr;
215  LoopClosing* _loopClosing = nullptr;
216  std::thread* _processNewKeyFrameThread = nullptr;
217  std::vector<std::thread*> _mappingThreads;
218  std::thread* _loopClosingThread = nullptr;
219 };
220 //-----------------------------------------------------------------------------
221 #endif
WAITrackingState
Definition: WAISlamTools.h:27
@ TrackingOK
Definition: WAISlamTools.h:31
@ TrackingStart
Definition: WAISlamTools.h:33
@ TrackingLost
Definition: WAISlamTools.h:32
@ None
Definition: WAISlamTools.h:28
@ Initializing
Definition: WAISlamTools.h:30
@ Idle
Definition: WAISlamTools.h:29
AR Keyframe node class.
Definition: WAIKeyFrame.h:60
Definition: WAIMap.h:52
static void motionModel(WAIFrame &frame, WAIFrame &lastFrame, cv::Mat &velocity, cv::Mat &pose)
cv::Mat _cameraIntrinsic
Definition: WAISlamTools.h:201
cv::Mat _cameraExtrinsic
Definition: WAISlamTools.h:202
std::vector< std::thread * > _mappingThreads
Definition: WAISlamTools.h:217
LoopClosing * _loopClosing
Definition: WAISlamTools.h:215
static void countReprojectionOutliers(WAIFrame &frame, unsigned int &m, unsigned int &n, unsigned int &outliers)
static bool strictTrackReferenceKeyFrame(LocalMap &map, WAIFrame &lastFrame, WAIFrame &frame)
static bool initialize(WAIInitializerData &iniData, WAIFrame &frame, WAIOrbVocabulary *voc, LocalMap &localMap, int mapPointsNeeded=100)
static bool trackLocalMap(LocalMap &localMap, WAIFrame &frame, int lastRelocFrameId, int &inliers)
std::unique_ptr< WAIMap > _globalMap
Definition: WAISlamTools.h:208
static bool doMarkerMapPreprocessing(std::string markerFile, cv::Mat &nodeTransform, float markerWidthInM, KPextractor *markerExtractor, WAIMap *map, const cv::Mat &markerCameraIntrinsic, WAIOrbVocabulary *voc)
static bool relocalizationGPS(WAIFrame &currentFrame, WAIMap *waiMap, LocalMap &localMap, cv::Mat locENU, cv::Mat dirENU, float minCommonWordFactor, int &inliers, bool minAccScoreFilter)
cv::Mat _distortion
Definition: WAISlamTools.h:200
static bool oldInitialize(WAIFrame &frame, WAIInitializerData &iniData, WAIMap *map, LocalMap &localMap, LocalMapping *localMapper, LoopClosing *loopCloser, WAIOrbVocabulary *voc, int mapPointsNeeded=100)
static bool checkKFConnectionsTree(WAIMap *map)
std::thread * _loopClosingThread
Definition: WAISlamTools.h:218
static bool tracking(WAIMap *map, LocalMap &localMap, WAIFrame &frame, WAIFrame &lastFrame, int lastRelocFrameId, cv::Mat &velocity, int &inliers)
static bool strictNeedNewKeyFrame(WAIMap *map, LocalMap &localMap, LocalMapping *localMapper, WAIFrame &frame, int nInliers, const unsigned long lastRelocFrameId, const unsigned long lastKeyFrameFrameId)
virtual ~WAISlamTools()
Definition: WAISlamTools.h:192
static bool trackReferenceKeyFrame(LocalMap &map, WAIFrame &lastFrame, WAIFrame &frame)
static void drawInitInfo(WAIInitializerData &iniData, WAIFrame &frame, cv::Mat &imageBGR, float scale)
static bool strictTracking(WAIMap *map, LocalMap &localMap, WAIFrame &frame, WAIFrame &lastFrame, int lastRelocFrameId, int &inliers)
static WAIFrame createMarkerFrame(std::string markerFile, KPextractor *markerExtractor, const cv::Mat &markerCameraIntrinsic, WAIOrbVocabulary *voc)
static bool findMarkerHomography(WAIFrame &markerFrame, WAIKeyFrame *kfCand, cv::Mat &homography, int minMatches)
LocalMapping * _localMapping
Definition: WAISlamTools.h:214
static bool relocalization(WAIFrame &currentFrame, WAIMap *waiMap, LocalMap &localMap, float minCommonWordFactor, int &inliers, bool minAccScoreFilter=false)
static void drawKeyPointMatches(WAIFrame &frame, cv::Mat &image, float scale)
static bool detectCycle(WAIKeyFrame *kf, std::set< WAIKeyFrame * > &visitedNode)
static void updateLocalMap(WAIFrame &frame, LocalMap &localMap)
WAIFrame _lastFrame
Definition: WAISlamTools.h:206
cv::Mat _cameraExtrinsicGuess
Definition: WAISlamTools.h:204
static bool needNewKeyFrame(WAIMap *globalMap, LocalMap &localMap, LocalMapping *localMapper, WAIFrame &frame, int nInliners, const unsigned long lastRelocFrameId, const unsigned long lastKeyFrameFrameId)
static void createNewKeyFrame(LocalMapping *localMapper, LocalMap &localMap, WAIMap *globalMap, WAIFrame &frame, unsigned long &lastKeyFrameFrameId)
static void strictMapping(WAIMap *map, LocalMap &localMap, LocalMapping *localMapper, WAIFrame &frame, int inliers, const unsigned long lastRelocFrameId, unsigned long &lastKeyFrameFrameId)
static bool trackWithMotionModel(cv::Mat velocity, WAIFrame &previousFrame, WAIFrame &frame)
LocalMap _localMap
Definition: WAISlamTools.h:209
WAIOrbVocabulary * _voc
Definition: WAISlamTools.h:210
static bool genInitialMap(WAIMap *globalMap, LocalMapping *localMapper, LoopClosing *loopCloser, LocalMap &localMap)
static int trackLocalMapPoints(LocalMap &localMap, int lastRelocFrameId, WAIFrame &frame)
WAIInitializerData _iniData
Definition: WAISlamTools.h:205
std::thread * _processNewKeyFrameThread
Definition: WAISlamTools.h:216
static void mapping(WAIMap *map, LocalMap &localMap, LocalMapping *localMapper, WAIFrame &frame, int inliers, const unsigned long lastRelocFrameId, unsigned long &lastKeyFrameFrameId)
static void drawKeyPointInfo(WAIFrame &frame, cv::Mat &image, float scale)
cv::Mat _velocity
Definition: WAISlamTools.h:211
static int findFrameFixedMapMatches(WAIFrame &frame, WAIMap *waiMap, std::vector< cv::Point2f > &points2d, std::vector< cv::Point3f > &points3d)
std::vector< int > iniMatches
Definition: WAISlamTools.h:23
WAIFrame initialFrame
Definition: WAISlamTools.h:20
Initializer * initializer
Definition: WAISlamTools.h:19
std::vector< cv::Point2f > prevMatched
Definition: WAISlamTools.h:21
std::vector< cv::Point3f > iniPoint3D
Definition: WAISlamTools.h:22