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

#include <WAISlam.h>

Inheritance diagram for WAISlam:
[legend]

Classes

struct  Params
 

Public Member Functions

 WAISlam (const cv::Mat &intrinsic, const cv::Mat &distortion, WAIOrbVocabulary *voc, KPextractor *iniExtractor, KPextractor *relocExtractor, KPextractor *extractor, std::unique_ptr< WAIMap > globalMap, WAISlam::Params params)
 
virtual ~WAISlam ()
 
virtual void reset ()
 
void changeIntrinsic (cv::Mat intrinsic, cv::Mat distortion)
 
void createFrame (WAIFrame &frame, cv::Mat &imageGray)
 
virtual void updatePose (WAIFrame &frame)
 
virtual bool update (cv::Mat &imageGray)
 
virtual void updatePoseKFIntegration (WAIFrame &frame)
 
virtual void resume ()
 
virtual bool isTracking ()
 
virtual bool hasStateIdle ()
 
virtual void requestStateIdle ()
 
virtual bool retainImage ()
 
void transformCoords (cv::Mat transform)
 
std::vector< WAIMapPoint * > getMatchedMapPoints (WAIFrame *frame)
 
int getMatchedCorrespondances (WAIFrame *frame, std::pair< std::vector< cv::Point2f >, std::vector< cv::Point3f >> &matching)
 
virtual bool isInitialized ()
 
virtual WAIMapgetMap ()
 
virtual WAIFrame getLastFrame ()
 
virtual WAIFramegetLastFramePtr ()
 
virtual std::vector< WAIMapPoint * > getLocalMapPoints ()
 
virtual int getNumKeyFrames ()
 
virtual std::vector< WAIMapPoint * > getMapPoints ()
 
virtual std::vector< WAIKeyFrame * > getKeyFrames ()
 
virtual std::string getPrintableState ()
 
virtual int getKeyPointCount ()
 
virtual int getKeyFrameCount ()
 
virtual int getMapPointCount ()
 
virtual cv::Mat getPose ()
 
virtual void setCamExrinsicGuess (cv::Mat extrinsicGuess)
 
virtual void setMap (std::unique_ptr< WAIMap > globalMap)
 
virtual WAITrackingState getTrackingState ()
 
virtual void drawInfo (cv::Mat &imageBGR, float scale, bool showInitLine, bool showKeyPoints, bool showKeyPointsMatched)
 
KPextractor * getKPextractor ()
 
int getMapPointMatchesCount () const
 
std::string getLoopCloseStatus ()
 
int getLoopCloseCount ()
 
int getKeyFramesInLoopCloseQueueCount ()
 

Protected Member Functions

void updateState (WAITrackingState state)
 
bool finishRequested ()
 
void requestFinish ()
 
bool isStop ()
 
bool isFinished ()
 
void flushQueue ()
 
int getNextFrame (WAIFrame &frame)
 
- Protected Member Functions inherited from WAISlamTools
virtual ~WAISlamTools ()
 
 WAISlamTools ()
 

Static Protected Member Functions

static void updatePoseThread (WAISlam *ptr)
 
- Static Protected Member Functions inherited from WAISlamTools
static void countReprojectionOutliers (WAIFrame &frame, unsigned int &m, unsigned int &n, unsigned int &outliers)
 

Protected Attributes

bool _requestFinish
 
bool _isFinish
 
bool _isStop
 
std::mutex _stateMutex
 
WAITrackingState _state = WAITrackingState::Idle
 
std::mutex _cameraExtrinsicMutex
 
std::mutex _cameraExtrinsicGuessMutex
 
std::mutex _mutexStates
 
std::mutex _lastFrameMutex
 
WAISlam::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
 
std::thread * _poseUpdateThread
 
std::queue< WAIFrame_framesQueue
 
std::mutex _frameQueueMutex
 
- 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
 

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)
 

Detailed Description

Definition at line 26 of file WAISlam.h.

Constructor & Destructor Documentation

◆ WAISlam()

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

Definition at line 15 of file WAISlam.cpp.

23 {
24  _iniData.initializer = nullptr;
25  _params = params;
26 
29 
32 
33  _distortion = distortion.clone();
34  _cameraIntrinsic = intrinsic.clone();
35  _voc = voc;
36 
37  _extractor = extractor;
38  _relocExtractor = relocExtractor;
39  _iniExtractor = iniExtractor;
40 
41  if (_iniExtractor == nullptr)
43  if (_relocExtractor == nullptr)
45 
46  if (globalMap == nullptr)
47  {
48  WAIKeyFrameDB* kfDB = new WAIKeyFrameDB(voc);
49  _globalMap = std::make_unique<WAIMap>(kfDB);
51 
54  }
55  else
56  {
57  _globalMap = std::move(globalMap);
59  _initialized = true;
60  }
61 
62  _localMapping = new ORB_SLAM2::LocalMapping(_globalMap.get(),
63  _voc,
64  params.cullRedundantPerc);
65  _loopClosing = new ORB_SLAM2::LoopClosing(_globalMap.get(),
66  _voc,
68  false,
69  false);
70 
71  _localMapping->SetLoopCloser(_loopClosing);
72  _loopClosing->SetLocalMapper(_localMapping);
73 
75  {
76  _mappingThreads.push_back(new std::thread(&LocalMapping::Run, _localMapping));
77  _loopClosingThread = new std::thread(&LoopClosing::Run, _loopClosing);
78  }
79 
80 #if MULTI_THREAD_FRAME_PROCESSING
81  _poseUpdateThread = new std::thread(updatePoseThread, this);
82  _isFinish = false;
83  _isStop = false;
84  _requestFinish = false;
85 #endif
86 
87  _iniData.initializer = nullptr;
88  _cameraExtrinsic = cv::Mat::eye(4, 4, CV_32F);
89 
90  _lastFrame = WAIFrame();
91 }
@ 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
KPextractor * _iniExtractor
Definition: WAISlam.h:198
unsigned long _lastRelocFrameId
Definition: WAISlam.h:194
WAISlam::Params _params
Definition: WAISlam.h:191
bool _isFinish
Definition: WAISlam.h:174
bool _requestFinish
Definition: WAISlam.h:173
KPextractor * _extractor
Definition: WAISlam.h:196
unsigned long _lastKeyFrameFrameId
Definition: WAISlam.h:195
WAITrackingState _state
Definition: WAISlam.h:185
bool _isStop
Definition: WAISlam.h:175
static void updatePoseThread(WAISlam *ptr)
Definition: WAISlam.cpp:257
KPextractor * _relocExtractor
Definition: WAISlam.h:197
std::thread * _poseUpdateThread
Definition: WAISlam.h:200
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
Initializer * initializer
Definition: WAISlamTools.h:19
float cullRedundantPerc
Definition: WAISlam.h:48
float minCommonWordFactor
Definition: WAISlam.h:52
bool onlyTracking
Definition: WAISlam.h:38

◆ ~WAISlam()

WAISlam::~WAISlam ( )
virtual

Definition at line 93 of file WAISlam.cpp.

94 {
95  if (!_params.serial)
96  {
97  _localMapping->RequestFinish();
98  _loopClosing->RequestFinish();
99  }
100 
101  // Wait until all thread have effectively stopped
104 
105  for (std::thread* t : _mappingThreads) { t->join(); }
106 
107  if (_loopClosingThread)
108  _loopClosingThread->join();
109 
110 #if MULTI_THREAD_FRAME_PROCESSING
111  requestFinish();
112  _poseUpdateThread->join();
113  delete _poseUpdateThread;
114  _poseUpdateThread = nullptr;
115 #endif
116 
117  delete _localMapping;
118  delete _loopClosing;
119 }
void requestFinish()
Definition: WAISlam.cpp:225
std::thread * _processNewKeyFrameThread
Definition: WAISlamTools.h:216

Member Function Documentation

◆ changeIntrinsic()

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

Definition at line 156 of file WAISlam.cpp.

157 {
158  _cameraIntrinsic = intrinsic;
159  _distortion = distortion;
160 }

◆ createFrame()

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

Definition at line 162 of file WAISlam.cpp.

163 {
164  switch (getTrackingState())
165  {
167  frame = WAIFrame(imageGray,
168  0.0,
171  _distortion,
172  _voc,
174  break;
177  frame = WAIFrame(imageGray,
178  0.0,
181  _distortion,
182  _voc,
184  break;
185  default:
186  frame = WAIFrame(imageGray,
187  0.0,
188  _extractor,
190  _distortion,
191  _voc,
193  }
194 }
@ TrackingStart
Definition: WAISlamTools.h:33
virtual WAITrackingState getTrackingState()
Definition: WAISlam.h:149
bool retainImg
Definition: WAISlam.h:36

◆ drawInfo()

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

Definition at line 488 of file WAISlam.cpp.

493 {
494  std::unique_lock<std::mutex> lock(_lastFrameMutex);
495  std::unique_lock<std::mutex> lock2(_stateMutex);
497  {
498  if (showInitLine)
499  drawInitInfo(_iniData, _lastFrame, imageBGR, scale);
500  }
502  {
503  if (showKeyPoints)
504  drawKeyPointInfo(_lastFrame, imageBGR, scale);
505  if (showKeyPointsMatched)
506  drawKeyPointMatches(_lastFrame, imageBGR, scale);
507  }
509  {
510  if (showKeyPoints)
511  drawKeyPointInfo(_lastFrame, imageBGR, scale);
512  }
513 }
@ TrackingOK
Definition: WAISlamTools.h:31
std::mutex _stateMutex
Definition: WAISlam.h:176
std::mutex _lastFrameMutex
Definition: WAISlam.h:189
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)

◆ finishRequested()

bool WAISlam::finishRequested ( )
protected

Definition at line 231 of file WAISlam.cpp.

232 {
233  std::unique_lock<std::mutex> lock(_stateMutex);
234  return _requestFinish;
235 }

◆ flushQueue()

void WAISlam::flushQueue ( )
protected

Definition at line 197 of file WAISlam.cpp.

198 {
199  std::unique_lock<std::mutex> lock(_lastFrameMutex);
200  while (!_framesQueue.empty())
201  {
202  _framesQueue.pop();
203  }
204 }
std::queue< WAIFrame > _framesQueue
Definition: WAISlam.h:201

◆ getKeyFrameCount()

virtual int WAISlam::getKeyFrameCount ( )
inlinevirtual

Definition at line 141 of file WAISlam.h.

141 { return (int)_globalMap->KeyFramesInMap(); }

◆ getKeyFrames()

virtual std::vector<WAIKeyFrame*> WAISlam::getKeyFrames ( )
inlinevirtual

Definition at line 106 of file WAISlam.h.

107  {
108  if (_globalMap != nullptr)
109  return _globalMap->GetAllKeyFrames();
110  return std::vector<WAIKeyFrame*>();
111  }

◆ getKeyFramesInLoopCloseQueueCount()

int WAISlam::getKeyFramesInLoopCloseQueueCount ( )

Definition at line 639 of file WAISlam.cpp.

640 {
641  return _loopClosing->numOfKfsInQueue();
642 }

◆ getKeyPointCount()

virtual int WAISlam::getKeyPointCount ( )
inlinevirtual

Definition at line 140 of file WAISlam.h.

140 { return _lastFrame.N; }
int N
Definition: WAIFrame.h:123

◆ getKPextractor()

KPextractor* WAISlam::getKPextractor ( )
inline

Definition at line 157 of file WAISlam.h.

158  {
159  return _extractor;
160  };

◆ getLastFrame()

WAIFrame WAISlam::getLastFrame ( )
virtual

Definition at line 459 of file WAISlam.cpp.

460 {
461  std::unique_lock<std::mutex> lock(_lastFrameMutex);
462  return _lastFrame;
463 }

◆ getLastFramePtr()

WAIFrame * WAISlam::getLastFramePtr ( )
virtual

Definition at line 465 of file WAISlam.cpp.

466 {
467  std::unique_lock<std::mutex> lock(_lastFrameMutex);
468  return &_lastFrame;
469 }

◆ getLocalMapPoints()

virtual std::vector<WAIMapPoint*> WAISlam::getLocalMapPoints ( )
inlinevirtual

Definition at line 96 of file WAISlam.h.

96 { return _localMap.mapPoints; }
LocalMap _localMap
Definition: WAISlamTools.h:209

◆ getLoopCloseCount()

int WAISlam::getLoopCloseCount ( )

Definition at line 634 of file WAISlam.cpp.

635 {
636  return _globalMap->getNumLoopClosings();
637 }

◆ getLoopCloseStatus()

std::string WAISlam::getLoopCloseStatus ( )

Definition at line 629 of file WAISlam.cpp.

630 {
631  return _loopClosing->getStatusString();
632 }

◆ getMap()

virtual WAIMap* WAISlam::getMap ( )
inlinevirtual

Definition at line 93 of file WAISlam.h.

93 { return _globalMap.get(); }

◆ getMapPointCount()

virtual int WAISlam::getMapPointCount ( )
inlinevirtual

Definition at line 142 of file WAISlam.h.

142 { return (int)_globalMap->MapPointsInMap(); }

◆ getMapPointMatchesCount()

int WAISlam::getMapPointMatchesCount ( ) const

Definition at line 624 of file WAISlam.cpp.

625 {
626  return _infoMatchedInliners;
627 }
int _infoMatchedInliners
Definition: WAISlam.h:199

◆ getMapPoints()

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

Definition at line 99 of file WAISlam.h.

100  {
101  if (_globalMap != nullptr)
102  return _globalMap->GetAllMapPoints();
103  return std::vector<WAIMapPoint*>();
104  }

◆ getMatchedCorrespondances()

int WAISlam::getMatchedCorrespondances ( WAIFrame frame,
std::pair< std::vector< cv::Point2f >, std::vector< cv::Point3f >> &  matching 
)

Definition at line 531 of file WAISlam.cpp.

534 {
535  for (int i = 0; i < frame->N; i++)
536  {
537  WAIMapPoint* mp = frame->mvpMapPoints[i];
538  if (mp)
539  {
540  if (mp->isFixed())
541  {
542  WAI::V3 v = mp->worldPosVec();
543  matching.first.push_back(frame->mvKeysUn[i].pt);
544  matching.second.push_back(cv::Point3f(v.x, v.y, v.z));
545  }
546  }
547  }
548  return (int)matching.first.size();
549 }
std::vector< WAIMapPoint * > mvpMapPoints
Definition: WAIFrame.h:147
std::vector< cv::KeyPoint > mvKeysUn
Definition: WAIFrame.h:129
bool isFixed() const
Definition: WAIMapPoint.h:105
WAI::V3 worldPosVec()
Definition: WAIMapPoint.cpp:95
float x
Definition: WAIMath.h:33
float z
Definition: WAIMath.h:33
float y
Definition: WAIMath.h:33

◆ getMatchedMapPoints()

std::vector< WAIMapPoint * > WAISlam::getMatchedMapPoints ( WAIFrame frame)

Definition at line 515 of file WAISlam.cpp.

516 {
517  std::vector<WAIMapPoint*> result;
518 
519  for (int i = 0; i < frame->N; i++)
520  {
521  if (frame->mvpMapPoints[i])
522  {
523  if (frame->mvpMapPoints[i]->Observations() > 0)
524  result.push_back(frame->mvpMapPoints[i]);
525  }
526  }
527 
528  return result;
529 }

◆ getNextFrame()

int WAISlam::getNextFrame ( WAIFrame frame)
protected

Definition at line 212 of file WAISlam.cpp.

213 {
214  int nbFrameInQueue;
215  std::unique_lock<std::mutex> lock(_frameQueueMutex);
216  nbFrameInQueue = (int)_framesQueue.size();
217  if (nbFrameInQueue == 0)
218  return 0;
219 
220  frame = _framesQueue.front();
221  _framesQueue.pop();
222  return nbFrameInQueue;
223 }
std::mutex _frameQueueMutex
Definition: WAISlam.h:202

◆ getNumKeyFrames()

virtual int WAISlam::getNumKeyFrames ( )
inlinevirtual

Definition at line 97 of file WAISlam.h.

97 { return (int)_globalMap->KeyFramesInMap(); }

◆ getPose()

cv::Mat WAISlam::getPose ( )
virtual

Definition at line 551 of file WAISlam.cpp.

552 {
553  std::unique_lock<std::mutex> lock(_cameraExtrinsicMutex);
554  return _cameraExtrinsic;
555 }
std::mutex _cameraExtrinsicMutex
Definition: WAISlam.h:186

◆ getPrintableState()

virtual std::string WAISlam::getPrintableState ( )
inlinevirtual

Definition at line 113 of file WAISlam.h.

114  {
115  switch (_state)
116  {
118  return std::string("TrackingState_Idle\n");
119  break;
121  return std::string("Initializing");
122  break;
124  return std::string("None");
125  break;
127  return std::string("TrackingLost");
128  break;
130  return std::string("TrackingOK");
131  break;
133  return std::string("TrackingStart");
134  break;
135  default:
136  return std::string("");
137  }
138  }
@ None
Definition: WAISlamTools.h:28
@ Idle
Definition: WAISlamTools.h:29

◆ getTrackingState()

virtual WAITrackingState WAISlam::getTrackingState ( )
inlinevirtual

Definition at line 149 of file WAISlam.h.

149 { return _state; }

◆ hasStateIdle()

bool WAISlam::hasStateIdle ( )
virtual

Definition at line 579 of file WAISlam.cpp.

580 {
581  std::unique_lock<std::mutex> guard(_mutexStates);
582  return (_state == WAITrackingState::Idle);
583 }
std::mutex _mutexStates
Definition: WAISlam.h:188

◆ isFinished()

bool WAISlam::isFinished ( )
protected

Definition at line 237 of file WAISlam.cpp.

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

◆ isInitialized()

virtual bool WAISlam::isInitialized ( )
inlinevirtual

Definition at line 92 of file WAISlam.h.

92 { return _initialized; }

◆ isStop()

bool WAISlam::isStop ( )
protected

Definition at line 243 of file WAISlam.cpp.

244 {
245  std::unique_lock<std::mutex> lock(_stateMutex);
246  return _isStop;
247 }

◆ isTracking()

bool WAISlam::isTracking ( )
virtual

Definition at line 585 of file WAISlam.cpp.

586 {
587  std::unique_lock<std::mutex> guard(_mutexStates);
589 }

◆ requestFinish()

void WAISlam::requestFinish ( )
protected

Definition at line 225 of file WAISlam.cpp.

226 {
227  std::unique_lock<std::mutex> lock(_stateMutex);
228  _requestFinish = true;
229 }

◆ requestStateIdle()

void WAISlam::requestStateIdle ( )
virtual

Definition at line 563 of file WAISlam.cpp.

564 {
566  {
567  std::unique_lock<std::mutex> guard(_mutexStates);
568  _localMapping->RequestPause();
569  while (!_localMapping->isPaused())
570  {
571  std::this_thread::sleep_for(std::chrono::microseconds(10));
572  }
573  std::cout << "localMapping is stopped" << std::endl;
574  }
575 
577 }

◆ reset()

void WAISlam::reset ( )
virtual

Definition at line 121 of file WAISlam.cpp.

122 {
123  if (!_params.serial)
124  {
125  _localMapping->RequestReset();
126  _loopClosing->RequestReset();
127  }
128 
129 #if MULTI_THREAD_FRAME_PROCESSING
130  requestFinish();
131  _poseUpdateThread->join();
132 #endif
133 
134  _globalMap->clear();
135  _localMap.keyFrames.clear();
136  _localMap.mapPoints.clear();
137  _localMap.refKF = nullptr;
138 
140  _lastRelocFrameId = 0;
141 
142 #if MULTI_THREAD_FRAME_PROCESSING
143  _poseUpdateThread = new std::thread(updatePoseThread, this);
144  _isFinish = false;
145  _isStop = false;
146  _requestFinish = false;
147 #endif
148 
150  WAIFrame::nNextId = 0;
154 }

◆ resume()

void WAISlam::resume ( )
virtual

Definition at line 249 of file WAISlam.cpp.

250 {
251  std::unique_lock<std::mutex> lock(_stateMutex);
252  _isStop = false;
253  _localMapping->RequestContinue();
255 }

◆ retainImage()

bool WAISlam::retainImage ( )
virtual

Definition at line 591 of file WAISlam.cpp.

592 {
593  return false;
594 }

◆ setCamExrinsicGuess()

void WAISlam::setCamExrinsicGuess ( cv::Mat  extrinsicGuess)
virtual

Definition at line 557 of file WAISlam.cpp.

558 {
559  std::unique_lock<std::mutex> lock(_cameraExtrinsicGuessMutex);
560  _cameraExtrinsicGuess = extrinsicGuess;
561 }
std::mutex _cameraExtrinsicGuessMutex
Definition: WAISlam.h:187
cv::Mat _cameraExtrinsicGuess
Definition: WAISlamTools.h:204

◆ setMap()

void WAISlam::setMap ( std::unique_ptr< WAIMap globalMap)
virtual

Definition at line 615 of file WAISlam.cpp.

616 {
618  reset();
619  _globalMap = std::move(globalMap);
620  _initialized = true;
621  resume();
622 }
virtual void reset()
Definition: WAISlam.cpp:121
virtual void resume()
Definition: WAISlam.cpp:249
virtual void requestStateIdle()
Definition: WAISlam.cpp:563

◆ transformCoords()

void WAISlam::transformCoords ( cv::Mat  transform)

Definition at line 596 of file WAISlam.cpp.

597 {
598  if (_loopClosingThread != nullptr)
599  {
600  _localMapping->RequestPause();
601  while (!_localMapping->isPaused() && !_localMapping->isFinished())
602  {
603  std::this_thread::sleep_for(std::chrono::seconds(1));
604  }
605  }
606 
607  WAIMap* map = _globalMap.get();
608 
609  map->transform(transform);
610 
611  _initialized = true;
612  _localMapping->RequestContinue();
613 }
Definition: WAIMap.h:52
void transform(cv::Mat transform)
Definition: WAIMap.cpp:192

◆ update()

bool WAISlam::update ( cv::Mat &  imageGray)
virtual

Definition at line 471 of file WAISlam.cpp.

472 {
473  WAIFrame frame;
474  createFrame(frame, imageGray);
475 
476 #if MULTI_THREAD_FRAME_PROCESSING
477  std::unique_lock<std::mutex> lock(_frameQueueMutex);
478  _framesQueue.push(frame);
479 #else
482  else
483  updatePose(frame);
484 #endif
485  return isTracking();
486 }
virtual bool isTracking()
Definition: WAISlam.cpp:585
void createFrame(WAIFrame &frame, cv::Mat &imageGray)
Definition: WAISlam.cpp:162
virtual void updatePoseKFIntegration(WAIFrame &frame)
Definition: WAISlam.cpp:395
virtual void updatePose(WAIFrame &frame)
Definition: WAISlam.cpp:291
bool ensureKFIntegration
Definition: WAISlam.h:32

◆ updatePose()

void WAISlam::updatePose ( WAIFrame frame)
virtual

Definition at line 291 of file WAISlam.cpp.

292 {
293  std::unique_lock<std::mutex> guard(_mutexStates);
294 
295  switch (_state)
296  {
298  {
299 #if 0
301  if (ok)
302  {
303  _lastKeyFrameFrameId = frame.mnId;
304  _lastRelocFrameId = 0;
306  _initialized = true;
307  }
308 #else
309  if (initialize(_iniData, frame, _voc, _localMap))
310  {
312  {
313  _localMapping->InsertKeyFrame(_localMap.keyFrames[0]);
314  _localMapping->InsertKeyFrame(_localMap.keyFrames[1]);
315  _lastKeyFrameFrameId = frame.mnId;
316  _lastRelocFrameId = 0;
318  _initialized = true;
319  if (_params.serial)
320  {
321  _localMapping->RunOnce();
322  _localMapping->RunOnce();
323  }
324  }
325  }
326 #endif
327  }
328  break;
330  {
332  if (_relocFrameCounter > 30)
334  }
336  {
337  int inliers;
338  if (tracking(_globalMap.get(),
339  _localMap,
340  frame,
341  _lastFrame,
342  (int)_lastRelocFrameId,
343  _velocity,
344  inliers))
345  {
346  std::unique_lock<std::mutex> lock(_cameraExtrinsicMutex);
347  motionModel(frame,
348  _lastFrame,
349  _velocity,
351  lock.unlock();
352  mapping(_globalMap.get(),
353  _localMap,
355  frame,
356  inliers,
359  if (_params.serial)
360  {
361  _localMapping->RunOnce();
362  _loopClosing->RunOnce();
363  }
364  _infoMatchedInliners = inliers;
365  }
366  else
367  {
369  }
370  }
371  break;
373  {
374  int inliers;
375  if (relocalization(frame,
376  _globalMap.get(),
377  _localMap,
379  inliers,
381  {
382  _relocFrameCounter = 0;
383  _lastRelocFrameId = frame.mnId;
384  _velocity = cv::Mat();
386  }
387  }
388  break;
389  }
390 
391  std::unique_lock<std::mutex> lock(_lastFrameMutex);
392  _lastFrame = WAIFrame(frame);
393 }
long unsigned int mnId
Definition: WAIFrame.h:159
unsigned int _relocFrameCounter
Definition: WAISlam.h:193
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 oldInitialize(WAIFrame &frame, WAIInitializerData &iniData, WAIMap *map, LocalMap &localMap, LocalMapping *localMapper, LoopClosing *loopCloser, WAIOrbVocabulary *voc, 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)
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
bool minAccScoreFilter
Definition: WAISlam.h:55

◆ updatePoseKFIntegration()

void WAISlam::updatePoseKFIntegration ( WAIFrame frame)
virtual

Definition at line 395 of file WAISlam.cpp.

396 {
397  switch (_state)
398  {
400  {
401  int inliers;
402  if (tracking(_globalMap.get(),
403  _localMap,
404  frame,
405  _lastFrame,
406  (int)_lastRelocFrameId,
407  _velocity,
408  inliers))
409  {
410  std::unique_lock<std::mutex> lock(_cameraExtrinsicMutex);
411  motionModel(frame,
412  _lastFrame,
413  _velocity,
415  lock.unlock();
417  _localMap,
419  frame,
420  inliers,
423  if (_params.serial)
424  {
425  _localMapping->RunOnce();
426  _loopClosing->RunOnce();
427  }
428  _infoMatchedInliners = inliers;
429  }
430  else
431  {
433  }
434  }
435  break;
437  {
438  int inliers;
439  if (relocalization(frame,
440  _globalMap.get(),
441  _localMap,
443  inliers,
445  {
446  _lastRelocFrameId = frame.mnId;
447  _velocity = cv::Mat();
449  _infoMatchedInliners = inliers;
450  }
451  }
452  break;
453  }
454 
455  std::unique_lock<std::mutex> lock(_lastFrameMutex);
456  _lastFrame = WAIFrame(frame);
457 }
static void strictMapping(WAIMap *map, LocalMap &localMap, LocalMapping *localMapper, WAIFrame &frame, int inliers, const unsigned long lastRelocFrameId, unsigned long &lastKeyFrameFrameId)

◆ updatePoseThread()

void WAISlam::updatePoseThread ( WAISlam ptr)
staticprotected

Definition at line 257 of file WAISlam.cpp.

258 {
259  while (1)
260  {
261  WAIFrame f;
262  while (ptr->getNextFrame(f) && !ptr->finishRequested())
263  {
264  if (ptr->_params.ensureKFIntegration)
265  ptr->updatePoseKFIntegration(f);
266  else
267  ptr->updatePose(f);
268  }
269 
270  if (ptr->finishRequested())
271  {
272  std::unique_lock<std::mutex> lock(ptr->_frameQueueMutex);
273 
274  while (!ptr->_framesQueue.empty())
275  ptr->_framesQueue.pop();
276 
277  break;
278  }
279 
280  while (ptr->isStop() && !ptr->isFinished() && !ptr->finishRequested())
281  {
282  std::this_thread::sleep_for(25ms);
283  }
284  }
285 
286  std::unique_lock<std::mutex> lock(ptr->_stateMutex);
287  ptr->_requestFinish = false;
288  ptr->_isFinish = true;
289 }
bool isStop()
Definition: WAISlam.cpp:243
bool finishRequested()
Definition: WAISlam.cpp:231
int getNextFrame(WAIFrame &frame)
Definition: WAISlam.cpp:212
bool isFinished()
Definition: WAISlam.cpp:237

◆ updateState()

void WAISlam::updateState ( WAITrackingState  state)
protected

Definition at line 206 of file WAISlam.cpp.

207 {
208  std::unique_lock<std::mutex> lock(_mutexStates);
209  _state = state;
210 }

Member Data Documentation

◆ _cameraExtrinsicGuessMutex

std::mutex WAISlam::_cameraExtrinsicGuessMutex
protected

Definition at line 187 of file WAISlam.h.

◆ _cameraExtrinsicMutex

std::mutex WAISlam::_cameraExtrinsicMutex
protected

Definition at line 186 of file WAISlam.h.

◆ _extractor

KPextractor* WAISlam::_extractor = nullptr
protected

Definition at line 196 of file WAISlam.h.

◆ _frameQueueMutex

std::mutex WAISlam::_frameQueueMutex
protected

Definition at line 202 of file WAISlam.h.

◆ _framesQueue

std::queue<WAIFrame> WAISlam::_framesQueue
protected

Definition at line 201 of file WAISlam.h.

◆ _infoMatchedInliners

int WAISlam::_infoMatchedInliners = 0
protected

Definition at line 199 of file WAISlam.h.

◆ _iniExtractor

KPextractor* WAISlam::_iniExtractor = nullptr
protected

Definition at line 198 of file WAISlam.h.

◆ _isFinish

bool WAISlam::_isFinish
protected

Definition at line 174 of file WAISlam.h.

◆ _isStop

bool WAISlam::_isStop
protected

Definition at line 175 of file WAISlam.h.

◆ _lastFrameMutex

std::mutex WAISlam::_lastFrameMutex
protected

Definition at line 189 of file WAISlam.h.

◆ _lastKeyFrameFrameId

unsigned long WAISlam::_lastKeyFrameFrameId = 0
protected

Definition at line 195 of file WAISlam.h.

◆ _lastRelocFrameId

unsigned long WAISlam::_lastRelocFrameId = 0
protected

Definition at line 194 of file WAISlam.h.

◆ _mutexStates

std::mutex WAISlam::_mutexStates
protected

Definition at line 188 of file WAISlam.h.

◆ _params

WAISlam::Params WAISlam::_params
protected

Definition at line 191 of file WAISlam.h.

◆ _poseUpdateThread

std::thread* WAISlam::_poseUpdateThread
protected

Definition at line 200 of file WAISlam.h.

◆ _relocExtractor

KPextractor* WAISlam::_relocExtractor = nullptr
protected

Definition at line 197 of file WAISlam.h.

◆ _relocFrameCounter

unsigned int WAISlam::_relocFrameCounter = 0
protected

Definition at line 193 of file WAISlam.h.

◆ _requestFinish

bool WAISlam::_requestFinish
protected

Definition at line 173 of file WAISlam.h.

◆ _state

WAITrackingState WAISlam::_state = WAITrackingState::Idle
protected

Definition at line 185 of file WAISlam.h.

◆ _stateMutex

std::mutex WAISlam::_stateMutex
protected

Definition at line 176 of file WAISlam.h.


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