1 #ifndef WAI_MODE_ORB_SLAM_2 
    2 #define WAI_MODE_ORB_SLAM_2 
    6 #include <opencv2/core.hpp> 
   12 #include <orb_slam/SURFextractor.h> 
   13 #include <orb_slam/LocalMapping.h> 
   14 #include <orb_slam/LoopClosing.h> 
   15 #include <orb_slam/Initializer.h> 
   16 #include <orb_slam/ORBmatcher.h> 
   17 #include <orb_slam/Optimizer.h> 
   18 #include <orb_slam/PnPsolver.h> 
   20 #define OPTFLOW_GRID_COLS 7 
   21 #define OPTFLOW_GRID_ROWS 4 
   43         bool retainImg = 
false;
 
   45         bool onlyTracking = 
false;
 
   48         bool fixOldKfs = 
false;
 
   50         bool trackOptFlow = 
false;
 
   55         float cullRedundantPerc = 0.95f; 
 
   59                  ORB_SLAM2::KPextractor* kpIniExtractor,
 
   61                  cv::Mat                 distortionMat,
 
   63                  std::string             orbVocFile,
 
   64                  bool                    applyMinAccScoreFilter = 
false);
 
   67                  ORB_SLAM2::KPextractor* kpIniExtractor,
 
   68                  ORB_SLAM2::KPextractor* kpMarkerExtractor,
 
   69                  std::string             markerFile,
 
   71                  cv::Mat                 distortionMat,
 
   73                  std::string             orbVocFile,
 
   74                  bool                    applyMinAccScoreFilter = 
false);
 
   77     bool getPose(cv::Mat* pose);
 
   78     bool update(cv::Mat& imageGray, cv::Mat& imageRGB);
 
   80     static bool relocalization(
WAIFrame&      currentFrame,
 
   82                                unsigned int*  lastRelocFrameId,
 
   84                                bool           applyMinAccScoreFilter = 
true,
 
   85                                bool           relocWithAllKFs        = 
false);
 
   90     void disableMapping();
 
  102     std::string   getPrintableState();
 
  104     std::string   getPrintableType();
 
  105     int           getKeyPointCount();
 
  106     int           getMapPointCount();
 
  107     int           getMapPointMatchesCount();
 
  108     int           getKeyFrameCount();
 
  109     int           getNMapMatches();
 
  110     int           getNumKeyFrames();
 
  111     float         poseDifference();
 
  112     float         getMeanReprojectionError();
 
  113     void          findMatches(std::vector<cv::Point2f>& vP2D, std::vector<cv::Point3f>& vP3Dw);
 
  115     std::string getLoopCloseStatus();
 
  116     int         getLoopCloseCount();
 
  117     int         getKeyFramesInLoopCloseQueueCount();
 
  119     std::vector<WAIMapPoint*>                                 getMapPoints();
 
  120     std::vector<WAIMapPoint*>                                 getMatchedMapPoints();
 
  121     std::vector<WAIMapPoint*>                                 getLocalMapPoints();
 
  122     std::vector<WAIMapPoint*>                                 getMarkerCornerMapPoints();
 
  123     std::vector<WAIKeyFrame*>                                 getKeyFrames();
 
  124     std::pair<std::vector<cv::Vec3f>, std::vector<cv::Vec2f>> getMatchedCorrespondances();
 
  125     std::pair<std::vector<cv::Vec3f>, std::vector<cv::Vec2f>> getCorrespondances();
 
  132     bool getTrackOptFlow();
 
  133     void setTrackOptFlow(
bool flag);
 
  138     void requestStateIdle();
 
  143     void setVocabulary(std::string orbVocFile);
 
  147     bool doMarkerMapPreprocessing(std::string markerFile, cv::Mat& nodeTransform, 
float markerWidthInM);
 
  148     void decorateVideoWithKeyPoints(cv::Mat& image);
 
  149     void decorateVideoWithKeyPointMatches(cv::Mat& image);
 
  152     WAIFrame createMarkerFrame(std::string  markerFile,
 
  153                                KPextractor* markerExtractor);
 
  164     void initialize(cv::Mat& imageGray, cv::Mat& imageRGB);
 
  165     bool createInitialMapMonocular(
int mapPointsNeeded);
 
  166     void track3DPts(cv::Mat& imageGray, cv::Mat& imageRGB);
 
  169     bool trackReferenceKeyFrame();
 
  170     bool trackWithMotionModel();
 
  171     bool trackLocalMap();
 
  172     bool trackWithOptFlow();
 
  174     bool needNewKeyFrame();
 
  175     void createNewKeyFrame();
 
  177     bool posInGrid(
const cv::KeyPoint& kp, 
int& posX, 
int& posY, 
int minX, 
int minY);
 
  178     void checkReplacedInLastFrame();
 
  179     void updateLocalMap();
 
  180     void updateLocalKeyFrames();
 
  181     void updateLocalPoints();
 
  182     void searchLocalPoints();
 
  183     void updateLastFrame();
 
  191     bool   _poseSet = 
false;
 
  203     ORB_SLAM2::ORBVocabulary* mpVocabulary   = 
nullptr;
 
  204     ORB_SLAM2::KPextractor*   mpExtractor    = 
nullptr;
 
  205     ORB_SLAM2::KPextractor*   mpIniExtractor = 
nullptr;
 
  207     ORB_SLAM2::LocalMapping* mpLocalMapper = 
nullptr;
 
  208     ORB_SLAM2::LoopClosing*  mpLoopCloser  = 
nullptr;
 
  209     ORB_SLAM2::Initializer*  mpInitializer = 
nullptr;
 
  211     std::thread* mptLocalMapping = 
nullptr;
 
  212     std::thread* mptLoopClosing  = 
nullptr;
 
  227     bool                     _mapHasChanged = 
false;
 
  243     int mnMatchesInliers = 0;
 
  247     unsigned int mnLastRelocFrameId = 0;
 
  260     bool                 _optFlowOK = 
false;
 
  268     void stateTransition();
 
  269     void resetRequests();
 
  270     void requestResume();
 
  272     bool       _idleRequested   = 
false;
 
  273     bool       _resumeRequested = 
false;
 
  277     void decorate(cv::Mat& image);
 
  278     void calculateMeanReprojectionError();
 
  279     void calculatePoseDifference();
 
  281     double _meanReprojectionError = -1.0;
 
  282     double _poseDifference        = -1.0;
 
  283     bool   _showMapPC             = 
true;
 
  284     bool   _showMatchesPC         = 
true;
 
  285     bool   _showLocalMapPC        = 
false;
 
  286     bool   _showKeyFrames         = 
true;
 
  287     bool   _showCovisibilityGraph = 
false;
 
  288     bool   _showSpanningTree      = 
true;
 
  289     bool   _showLoopEdges         = 
true;
 
  290     bool   _renderKfBackground    = 
false;
 
  291     bool   _allowKfsAsActiveCam   = 
false;
 
  294     bool findMarkerHomography(
WAIFrame&    markerFrame,
 
  304     ORB_SLAM2::KPextractor* _markerExtractor = 
nullptr;
 
std::vector< cv::Point3f > mvIniP3D
 
unsigned int mnLastKeyFrameId
 
TrackingState getTrackingState()
 
float _optFlowGridElementHeightInv
 
void setInitialized(bool initialized)
 
std::vector< cv::Point2f > mvbPrevMatched
 
std::vector< int > mvIniMatches
 
vector< cv::KeyPoint > _optFlowKeyPtsLastFrame
 
std::mutex _meanProjErrorLock
 
list< WAIKeyFrame * > mlpReferences
 
float _optFlowGridElementWidthInv
 
std::vector< WAIMapPoint * > mvpLocalMapPoints
 
std::vector< WAIKeyFrame * > mvpLocalKeyFrames
 
std::mutex _nMapMatchesLock
 
KPextractor * getKPextractor()
 
list< double > mlFrameTimes
 
vector< WAIMapPoint * > _optFlowMapPtsLastFrame
 
bool _applyMinAccScoreFilter
 
list< cv::Mat > mlRelativeFramePoses
 
WAIKeyFrameDB * getKfDB()
 
@ TrackingType_MotionModel
 
AR Keyframe database class.
 
WAI : Where Am I: Collection of duplicate structs for vectors.
 
@ TrackingState_Initializing
 
@ TrackingState_TrackingOK
 
@ TrackingState_TrackingLost