SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
WAISlamTrackPool Class Reference

#include <WAISlamTrackPool.h>

Inheritance diagram for WAISlamTrackPool:
[legend]

Classes

struct  Params
 

Public Member Functions

 WAISlamTrackPool (const cv::Mat &intrinsic, const cv::Mat &distortion, WAIOrbVocabulary *voc, KPextractor *iniExtractor, KPextractor *relocExtractor, KPextractor *extractor, std::unique_ptr< WAIMap > globalMap, Params params)
 
virtual ~WAISlamTrackPool ()
 
bool update (cv::Mat &imageGray)
 
virtual WAITrackingState getTrackingState ()
 
void changeIntrinsic (cv::Mat intrinsic, cv::Mat distortion)
 
cv::Mat getPose ()
 
void drawInfo (cv::Mat &imageBGR, float scale, bool showInitLine, bool showKeyPoints, bool showKeyPointsMatched)
 
virtual std::vector< WAIMapPoint * > getMapPoints ()
 
std::vector< WAIMapPoint * > getMatchedMapPoints ()
 

Private Member Functions

void createFrame (WAIFrame &frame, cv::Mat &imageGray)
 
void updatePose (WAIFrame &frame)
 

Private Attributes

Params _params
 
unsigned int _relocFrameCounter = 0
 
unsigned long _lastRelocFrameId = 0
 
unsigned long _lastKeyFrameFrameId = 0
 
KPextractor * _extractor = nullptr
 
KPextractor * _relocExtractor = nullptr
 
KPextractor * _iniExtractor = nullptr
 
int _infoMatchedInliners = 0
 
WAITrackingState _state
 
std::mutex _cameraExtrinsicMutex
 

Additional Inherited Members

- Static Public Member Functions inherited from WAISlamTools
static void drawKeyPointInfo (WAIFrame &frame, cv::Mat &image, float scale)
 
static void drawKeyPointMatches (WAIFrame &frame, cv::Mat &image, float scale)
 
static void drawInitInfo (WAIInitializerData &iniData, WAIFrame &frame, cv::Mat &imageBGR, float scale)
 
static bool initialize (WAIInitializerData &iniData, WAIFrame &frame, WAIOrbVocabulary *voc, LocalMap &localMap, int mapPointsNeeded=100)
 
static bool genInitialMap (WAIMap *globalMap, LocalMapping *localMapper, LoopClosing *loopCloser, LocalMap &localMap)
 
static bool oldInitialize (WAIFrame &frame, WAIInitializerData &iniData, WAIMap *map, LocalMap &localMap, LocalMapping *localMapper, LoopClosing *loopCloser, WAIOrbVocabulary *voc, int mapPointsNeeded=100)
 
static int findFrameFixedMapMatches (WAIFrame &frame, WAIMap *waiMap, std::vector< cv::Point2f > &points2d, std::vector< cv::Point3f > &points3d)
 
static bool relocalization (WAIFrame &currentFrame, WAIMap *waiMap, LocalMap &localMap, float minCommonWordFactor, int &inliers, bool minAccScoreFilter=false)
 
static bool relocalizationGPS (WAIFrame &currentFrame, WAIMap *waiMap, LocalMap &localMap, cv::Mat locENU, cv::Mat dirENU, float minCommonWordFactor, int &inliers, bool minAccScoreFilter)
 
static bool tracking (WAIMap *map, LocalMap &localMap, WAIFrame &frame, WAIFrame &lastFrame, int lastRelocFrameId, cv::Mat &velocity, int &inliers)
 
static bool strictTracking (WAIMap *map, LocalMap &localMap, WAIFrame &frame, WAIFrame &lastFrame, int lastRelocFrameId, int &inliers)
 
static bool trackLocalMap (LocalMap &localMap, WAIFrame &frame, int lastRelocFrameId, int &inliers)
 
static void mapping (WAIMap *map, LocalMap &localMap, LocalMapping *localMapper, WAIFrame &frame, int inliers, const unsigned long lastRelocFrameId, unsigned long &lastKeyFrameFrameId)
 
static void strictMapping (WAIMap *map, LocalMap &localMap, LocalMapping *localMapper, WAIFrame &frame, int inliers, const unsigned long lastRelocFrameId, unsigned long &lastKeyFrameFrameId)
 
static void motionModel (WAIFrame &frame, WAIFrame &lastFrame, cv::Mat &velocity, cv::Mat &pose)
 
static bool trackReferenceKeyFrame (LocalMap &map, WAIFrame &lastFrame, WAIFrame &frame)
 
static bool strictTrackReferenceKeyFrame (LocalMap &map, WAIFrame &lastFrame, WAIFrame &frame)
 
static bool trackWithMotionModel (cv::Mat velocity, WAIFrame &previousFrame, WAIFrame &frame)
 
static void updateLocalMap (WAIFrame &frame, LocalMap &localMap)
 
static int trackLocalMapPoints (LocalMap &localMap, int lastRelocFrameId, WAIFrame &frame)
 
static bool needNewKeyFrame (WAIMap *globalMap, LocalMap &localMap, LocalMapping *localMapper, WAIFrame &frame, int nInliners, const unsigned long lastRelocFrameId, const unsigned long lastKeyFrameFrameId)
 
static bool strictNeedNewKeyFrame (WAIMap *map, LocalMap &localMap, LocalMapping *localMapper, WAIFrame &frame, int nInliers, const unsigned long lastRelocFrameId, const unsigned long lastKeyFrameFrameId)
 
static void createNewKeyFrame (LocalMapping *localMapper, LocalMap &localMap, WAIMap *globalMap, WAIFrame &frame, unsigned long &lastKeyFrameFrameId)
 
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)
 
static bool doMarkerMapPreprocessing (std::string markerFile, cv::Mat &nodeTransform, float markerWidthInM, KPextractor *markerExtractor, WAIMap *map, const cv::Mat &markerCameraIntrinsic, WAIOrbVocabulary *voc)
 
static bool detectCycle (WAIKeyFrame *kf, std::set< WAIKeyFrame * > &visitedNode)
 
static bool checkKFConnectionsTree (WAIMap *map)
 
- Protected Member Functions inherited from WAISlamTools
virtual ~WAISlamTools ()
 
 WAISlamTools ()
 
- Static Protected Member Functions inherited from WAISlamTools
static void countReprojectionOutliers (WAIFrame &frame, unsigned int &m, unsigned int &n, unsigned int &outliers)
 
- Protected Attributes inherited from WAISlamTools
cv::Mat _distortion
 
cv::Mat _cameraIntrinsic
 
cv::Mat _cameraExtrinsic
 
cv::Mat _cameraExtrinsicGuess
 
WAIInitializerData _iniData
 
WAIFrame _lastFrame
 
std::unique_ptr< WAIMap_globalMap
 
LocalMap _localMap
 
WAIOrbVocabulary_voc = nullptr
 
cv::Mat _velocity
 
bool _initialized = false
 
LocalMapping * _localMapping = nullptr
 
LoopClosing * _loopClosing = nullptr
 
std::thread * _processNewKeyFrameThread = nullptr
 
std::vector< std::thread * > _mappingThreads
 
std::thread * _loopClosingThread = nullptr
 

Detailed Description

Definition at line 6 of file WAISlamTrackPool.h.

Constructor & Destructor Documentation

◆ WAISlamTrackPool()

WAISlamTrackPool::WAISlamTrackPool ( const cv::Mat &  intrinsic,
const cv::Mat &  distortion,
WAIOrbVocabulary voc,
KPextractor *  iniExtractor,
KPextractor *  relocExtractor,
KPextractor *  extractor,
std::unique_ptr< WAIMap globalMap,
WAISlamTrackPool::Params  params 
)

Definition at line 4 of file WAISlamTrackPool.cpp.

12 {
13  _iniData.initializer = nullptr;
14  _params = params;
15 
18 
21 
22  _distortion = distortion.clone();
23  _cameraIntrinsic = intrinsic.clone();
24  _voc = voc;
25 
26  _extractor = extractor;
27  _relocExtractor = relocExtractor;
28  _iniExtractor = iniExtractor;
29 
30  if (_iniExtractor == nullptr)
32  if (_relocExtractor == nullptr)
34 
35  if (globalMap == nullptr)
36  {
37  WAIKeyFrameDB* kfDB = new WAIKeyFrameDB(voc);
38  _globalMap = std::make_unique<WAIMap>(kfDB);
40 
43  }
44  else
45  {
46  _globalMap = std::move(globalMap);
48  _initialized = true;
49  }
50 
51  _localMapping = new ORB_SLAM2::LocalMapping(_globalMap.get(),
52  _voc,
53  params.cullRedundantPerc);
54  _loopClosing = new ORB_SLAM2::LoopClosing(_globalMap.get(),
55  _voc,
56  false,
57  false);
58 
59  _localMapping->SetLoopCloser(_loopClosing);
60  _loopClosing->SetLocalMapper(_localMapping);
61 
63  {
64  _mappingThreads.push_back(new std::thread(&LocalMapping::Run, _localMapping));
65  _loopClosingThread = new std::thread(&LoopClosing::Run, _loopClosing);
66  }
67 
68  _iniData.initializer = nullptr;
69  _cameraExtrinsic = cv::Mat::eye(4, 4, CV_32F);
70 
71  _lastFrame = WAIFrame();
72 }
@ TrackingLost
Definition: WAISlamTools.h:32
@ Initializing
Definition: WAISlamTools.h:30
static long unsigned int nNextId
Definition: WAIFrame.h:158
static bool mbInitialComputations
Definition: WAIFrame.h:182
AR Keyframe database class.
Definition: WAIKeyFrameDB.h:46
static long unsigned int nNextId
Definition: WAIKeyFrame.h:174
static long unsigned int nNextId
Definition: WAIMapPoint.h:110
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
std::unique_ptr< WAIMap > _globalMap
Definition: WAISlamTools.h:208
cv::Mat _distortion
Definition: WAISlamTools.h:200
std::thread * _loopClosingThread
Definition: WAISlamTools.h:218
LocalMapping * _localMapping
Definition: WAISlamTools.h:214
WAIFrame _lastFrame
Definition: WAISlamTools.h:206
WAIOrbVocabulary * _voc
Definition: WAISlamTools.h:210
WAIInitializerData _iniData
Definition: WAISlamTools.h:205
KPextractor * _relocExtractor
WAITrackingState _state
unsigned long _lastKeyFrameFrameId
KPextractor * _extractor
KPextractor * _iniExtractor
unsigned long _lastRelocFrameId
Initializer * initializer
Definition: WAISlamTools.h:19

◆ ~WAISlamTrackPool()

WAISlamTrackPool::~WAISlamTrackPool ( )
virtual

Definition at line 74 of file WAISlamTrackPool.cpp.

75 {
76  if (!_params.serial)
77  {
78  _localMapping->RequestFinish();
79  _loopClosing->RequestFinish();
80  }
81 
82  // Wait until all thread have effectively stopped
85 
86  for (std::thread* t : _mappingThreads)
87  {
88  t->join();
89  }
90 
92  _loopClosingThread->join();
93 
94  delete _localMapping;
95  delete _loopClosing;
96 }
std::thread * _processNewKeyFrameThread
Definition: WAISlamTools.h:216

Member Function Documentation

◆ changeIntrinsic()

void WAISlamTrackPool::changeIntrinsic ( cv::Mat  intrinsic,
cv::Mat  distortion 
)

Definition at line 231 of file WAISlamTrackPool.cpp.

232 {
233  _cameraIntrinsic = intrinsic;
234  _distortion = distortion;
235 }

◆ createFrame()

void WAISlamTrackPool::createFrame ( WAIFrame frame,
cv::Mat &  imageGray 
)
private

Definition at line 111 of file WAISlamTrackPool.cpp.

112 {
113  switch (getTrackingState())
114  {
116  frame = WAIFrame(imageGray,
117  0.0,
120  _distortion,
121  _voc,
123  break;
126  frame = WAIFrame(imageGray,
127  0.0,
130  _distortion,
131  _voc,
133  break;
134  default:
135  frame = WAIFrame(imageGray,
136  0.0,
137  _extractor,
139  _distortion,
140  _voc,
142  }
143 }
@ TrackingStart
Definition: WAISlamTools.h:33
virtual WAITrackingState getTrackingState()

◆ drawInfo()

void WAISlamTrackPool::drawInfo ( cv::Mat &  imageBGR,
float  scale,
bool  showInitLine,
bool  showKeyPoints,
bool  showKeyPointsMatched 
)

Definition at line 243 of file WAISlamTrackPool.cpp.

248 {
250  {
251  if (showInitLine)
252  drawInitInfo(_iniData, _lastFrame, imageBGR, scale);
253  }
255  {
256  if (showKeyPoints)
257  drawKeyPointInfo(_lastFrame, imageBGR, scale);
258  if (showKeyPointsMatched)
259  drawKeyPointMatches(_lastFrame, imageBGR, scale);
260  }
262  {
263  if (showKeyPoints)
264  drawKeyPointInfo(_lastFrame, imageBGR, scale);
265  }
266 }
@ TrackingOK
Definition: WAISlamTools.h:31
static void drawInitInfo(WAIInitializerData &iniData, WAIFrame &frame, cv::Mat &imageBGR, float scale)
static void drawKeyPointMatches(WAIFrame &frame, cv::Mat &image, float scale)
static void drawKeyPointInfo(WAIFrame &frame, cv::Mat &image, float scale)

◆ getMapPoints()

virtual std::vector<WAIMapPoint*> WAISlamTrackPool::getMapPoints ( )
inlinevirtual

Definition at line 61 of file WAISlamTrackPool.h.

62  {
63  if (_globalMap != nullptr)
64  return _globalMap->GetAllMapPoints();
65  return std::vector<WAIMapPoint*>();
66  }

◆ getMatchedMapPoints()

std::vector< WAIMapPoint * > WAISlamTrackPool::getMatchedMapPoints ( )

Definition at line 268 of file WAISlamTrackPool.cpp.

269 {
270  std::vector<WAIMapPoint*> result;
271 
272  for (int i = 0; i < _lastFrame.N; i++)
273  {
274  if (_lastFrame.mvpMapPoints[i])
275  {
276  if (_lastFrame.mvpMapPoints[i]->Observations() > 0)
277  result.push_back(_lastFrame.mvpMapPoints[i]);
278  }
279  }
280 
281  return result;
282 }
std::vector< WAIMapPoint * > mvpMapPoints
Definition: WAIFrame.h:147
int N
Definition: WAIFrame.h:123

◆ getPose()

cv::Mat WAISlamTrackPool::getPose ( )

Definition at line 237 of file WAISlamTrackPool.cpp.

238 {
239  std::unique_lock<std::mutex> lock(_cameraExtrinsicMutex);
240  return _cameraExtrinsic;
241 }
std::mutex _cameraExtrinsicMutex

◆ getTrackingState()

virtual WAITrackingState WAISlamTrackPool::getTrackingState ( )
inlinevirtual

Definition at line 51 of file WAISlamTrackPool.h.

51 { return _state; }

◆ update()

bool WAISlamTrackPool::update ( cv::Mat &  imageGray)

Definition at line 98 of file WAISlamTrackPool.cpp.

99 {
100  WAIFrame frame;
101  createFrame(frame, imageGray);
102 
103  // if (_params.ensureKFIntegration)
104  // updatePoseKFIntegration(frame);
105  // else
106  updatePose(frame);
107 
109 }
void createFrame(WAIFrame &frame, cv::Mat &imageGray)
void updatePose(WAIFrame &frame)

◆ updatePose()

void WAISlamTrackPool::updatePose ( WAIFrame frame)
private

Definition at line 145 of file WAISlamTrackPool.cpp.

146 {
147  switch (_state)
148  {
150  {
151  if (initialize(_iniData, frame, _voc, _localMap))
152  {
153  if (genInitialMap(_globalMap.get(),
155  _loopClosing,
156  _localMap))
157  {
158  _localMapping->InsertKeyFrame(_localMap.keyFrames[0]);
159  _localMapping->InsertKeyFrame(_localMap.keyFrames[1]);
160  _lastKeyFrameFrameId = frame.mnId;
161  _lastRelocFrameId = 0;
163  _initialized = true;
164  if (_params.serial)
165  {
166  _localMapping->RunOnce();
167  _localMapping->RunOnce();
168  }
169  }
170  }
171  }
172  break;
173 
175  {
177  if (_relocFrameCounter > 0)
179  }
181  {
182  int inliers;
183  if (tracking(_globalMap.get(),
184  _localMap,
185  frame,
186  _lastFrame,
187  (int)_lastRelocFrameId,
188  _velocity,
189  inliers))
190  {
191  std::unique_lock<std::mutex> lock(_cameraExtrinsicMutex);
193  lock.unlock();
194  mapping(_globalMap.get(),
195  _localMap,
197  frame,
198  inliers,
201  if (_params.serial)
202  {
203  _localMapping->RunOnce();
204  _loopClosing->RunOnce();
205  }
206  _infoMatchedInliners = inliers;
207  }
208  else
209  {
211  }
212  }
213  break;
215  {
216  int inliers;
218  {
219  _relocFrameCounter = 0;
220  _lastRelocFrameId = frame.mnId;
221  _velocity = cv::Mat();
223  }
224  }
225  break;
226  }
227 
228  _lastFrame = WAIFrame(frame);
229 }
long unsigned int mnId
Definition: WAIFrame.h:159
static void motionModel(WAIFrame &frame, WAIFrame &lastFrame, cv::Mat &velocity, cv::Mat &pose)
static bool initialize(WAIInitializerData &iniData, WAIFrame &frame, WAIOrbVocabulary *voc, LocalMap &localMap, int mapPointsNeeded=100)
static bool tracking(WAIMap *map, LocalMap &localMap, WAIFrame &frame, WAIFrame &lastFrame, int lastRelocFrameId, cv::Mat &velocity, int &inliers)
static bool relocalization(WAIFrame &currentFrame, WAIMap *waiMap, LocalMap &localMap, float minCommonWordFactor, int &inliers, bool minAccScoreFilter=false)
LocalMap _localMap
Definition: WAISlamTools.h:209
static bool genInitialMap(WAIMap *globalMap, LocalMapping *localMapper, LoopClosing *loopCloser, LocalMap &localMap)
static void mapping(WAIMap *map, LocalMap &localMap, LocalMapping *localMapper, WAIFrame &frame, int inliers, const unsigned long lastRelocFrameId, unsigned long &lastKeyFrameFrameId)
cv::Mat _velocity
Definition: WAISlamTools.h:211
unsigned int _relocFrameCounter

Member Data Documentation

◆ _cameraExtrinsicMutex

std::mutex WAISlamTrackPool::_cameraExtrinsicMutex
private

Definition at line 85 of file WAISlamTrackPool.h.

◆ _extractor

KPextractor* WAISlamTrackPool::_extractor = nullptr
private

Definition at line 78 of file WAISlamTrackPool.h.

◆ _infoMatchedInliners

int WAISlamTrackPool::_infoMatchedInliners = 0
private

Definition at line 81 of file WAISlamTrackPool.h.

◆ _iniExtractor

KPextractor* WAISlamTrackPool::_iniExtractor = nullptr
private

Definition at line 80 of file WAISlamTrackPool.h.

◆ _lastKeyFrameFrameId

unsigned long WAISlamTrackPool::_lastKeyFrameFrameId = 0
private

Definition at line 77 of file WAISlamTrackPool.h.

◆ _lastRelocFrameId

unsigned long WAISlamTrackPool::_lastRelocFrameId = 0
private

Definition at line 76 of file WAISlamTrackPool.h.

◆ _params

Params WAISlamTrackPool::_params
private

Definition at line 73 of file WAISlamTrackPool.h.

◆ _relocExtractor

KPextractor* WAISlamTrackPool::_relocExtractor = nullptr
private

Definition at line 79 of file WAISlamTrackPool.h.

◆ _relocFrameCounter

unsigned int WAISlamTrackPool::_relocFrameCounter = 0
private

Definition at line 75 of file WAISlamTrackPool.h.

◆ _state

WAITrackingState WAISlamTrackPool::_state
private

Definition at line 83 of file WAISlamTrackPool.h.


The documentation for this class was generated from the following files: