├── README.md
├── include
├── ORBVocabulary.h
├── Converter.h
├── MapDrawer.h
├── Viewer.h
├── FrameDrawer.h
├── KeyFrameDatabase.h
├── ORBextractor.h
├── Sim3Solver.h
├── TwoViewReconstruction.h
├── Initializer.h
├── CameraModels
│ ├── GeometricCamera.h
│ ├── Pinhole.h
│ └── KannalaBrandt8.h
├── LocalMapping.h
├── Atlas.h
├── ORBmatcher.h
├── Map.h
├── LoopClosing.h
├── PnPsolver.h
├── Optimizer.h
├── OptimizableTypes.h
├── System.h
├── MapPoint.h
├── ImuTypes.h
├── MLPnPsolver.h
├── Tracking.h
└── Frame.h
└── src
├── Converter.cc
├── CameraModels
└── Pinhole.cpp
├── Atlas.cc
├── OptimizableTypes.cpp
├── Viewer.cc
└── Sim3Solver.cc
/README.md:
--------------------------------------------------------------------------------
1 | # ORB-SLAM3-Note
2 | ORB-SLAM3源码注释,注释了大部分代码。
3 |
4 | 结合代码整理总结了视觉SLAM中的一些重要知识点,给出理论推导。如果有理解上的错误,请您指正。
5 |
6 | :) 如果对您有帮助,帮我点个star呦~
7 |
8 | ## 目录
9 | - [ORB-SLAM3知识点(一):词袋模型BoW](https://zhuanlan.zhihu.com/p/354616831)
10 | - [ORB-SLAM3知识点(二):ORB提取](https://zhuanlan.zhihu.com/p/355441452)
11 | - [ORB-SLAM3知识点(三):2d-2d匹配](https://zhuanlan.zhihu.com/p/355445588)
12 | - [ORB-SLAM3知识点(四):3d-2d匹配](https://zhuanlan.zhihu.com/p/355848913)
13 | - [ORB-SLAM3知识点(五):3d-3d匹配](https://zhuanlan.zhihu.com/p/356147588)
14 | - ORB-SLAM3知识点(六):BA优化、Jacobian
15 | - ORB-SLAM3知识点(七):...
16 |
17 | 可以到知乎上查看详细内容~
18 |
--------------------------------------------------------------------------------
/include/ORBVocabulary.h:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of ORB-SLAM3
3 | *
4 | * Copyright (C) 2017-2020 Carlos Campos, Richard Elvira, Juan J. Gómez Rodríguez, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
5 | * Copyright (C) 2014-2016 Raúl Mur-Artal, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
6 | *
7 | * ORB-SLAM3 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
8 | * License as published by the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * ORB-SLAM3 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
12 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License along with ORB-SLAM3.
16 | * If not, see .
17 | */
18 |
19 |
20 | #ifndef ORBVOCABULARY_H
21 | #define ORBVOCABULARY_H
22 |
23 | #include"Thirdparty/DBoW2/DBoW2/FORB.h"
24 | #include"Thirdparty/DBoW2/DBoW2/TemplatedVocabulary.h"
25 |
26 | namespace ORB_SLAM3
27 | {
28 |
29 | typedef DBoW2::TemplatedVocabulary
30 | ORBVocabulary;
31 |
32 | } //namespace ORB_SLAM
33 |
34 | #endif // ORBVOCABULARY_H
35 |
--------------------------------------------------------------------------------
/include/Converter.h:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of ORB-SLAM3
3 | *
4 | * Copyright (C) 2017-2020 Carlos Campos, Richard Elvira, Juan J. Gómez Rodríguez, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
5 | * Copyright (C) 2014-2016 Raúl Mur-Artal, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
6 | *
7 | * ORB-SLAM3 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
8 | * License as published by the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * ORB-SLAM3 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
12 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License along with ORB-SLAM3.
16 | * If not, see .
17 | */
18 |
19 |
20 | #ifndef CONVERTER_H
21 | #define CONVERTER_H
22 |
23 | #include
24 |
25 | #include
26 | #include"Thirdparty/g2o/g2o/types/types_six_dof_expmap.h"
27 | #include"Thirdparty/g2o/g2o/types/types_seven_dof_expmap.h"
28 |
29 | namespace ORB_SLAM3
30 | {
31 |
32 | class Converter
33 | {
34 | public:
35 | static std::vector toDescriptorVector(const cv::Mat &Descriptors);
36 |
37 | static g2o::SE3Quat toSE3Quat(const cv::Mat &cvT);
38 | static g2o::SE3Quat toSE3Quat(const g2o::Sim3 &gSim3);
39 |
40 | static cv::Mat toCvMat(const g2o::SE3Quat &SE3);
41 | static cv::Mat toCvMat(const g2o::Sim3 &Sim3);
42 | static cv::Mat toCvMat(const Eigen::Matrix &m);
43 | static cv::Mat toCvMat(const Eigen::Matrix3d &m);
44 | static cv::Mat toCvMat(const Eigen::Matrix &m);
45 | static cv::Mat toCvMat(const Eigen::MatrixXd &m);
46 |
47 | static cv::Mat toCvSE3(const Eigen::Matrix &R, const Eigen::Matrix &t);
48 | static cv::Mat tocvSkewMatrix(const cv::Mat &v);
49 |
50 | static Eigen::Matrix toVector3d(const cv::Mat &cvVector);
51 | static Eigen::Matrix toVector3d(const cv::Point3f &cvPoint);
52 | static Eigen::Matrix toMatrix3d(const cv::Mat &cvMat3);
53 | static Eigen::Matrix toMatrix4d(const cv::Mat &cvMat4);
54 | static std::vector toQuaternion(const cv::Mat &M);
55 |
56 | static bool isRotationMatrix(const cv::Mat &R);
57 | static std::vector toEuler(const cv::Mat &R);
58 |
59 | };
60 |
61 | }// namespace ORB_SLAM
62 |
63 | #endif // CONVERTER_H
64 |
--------------------------------------------------------------------------------
/include/MapDrawer.h:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of ORB-SLAM3
3 | *
4 | * Copyright (C) 2017-2020 Carlos Campos, Richard Elvira, Juan J. Gómez Rodríguez, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
5 | * Copyright (C) 2014-2016 Raúl Mur-Artal, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
6 | *
7 | * ORB-SLAM3 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
8 | * License as published by the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * ORB-SLAM3 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
12 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License along with ORB-SLAM3.
16 | * If not, see .
17 | */
18 |
19 |
20 | #ifndef MAPDRAWER_H
21 | #define MAPDRAWER_H
22 |
23 | #include"Atlas.h"
24 | #include"MapPoint.h"
25 | #include"KeyFrame.h"
26 | #include
27 |
28 | #include
29 |
30 | namespace ORB_SLAM3
31 | {
32 |
33 | class MapDrawer
34 | {
35 | public:
36 | MapDrawer(Atlas* pAtlas, const string &strSettingPath);
37 |
38 | Atlas* mpAtlas;
39 |
40 | void DrawMapPoints();
41 | void DrawKeyFrames(const bool bDrawKF, const bool bDrawGraph, const bool bDrawInertialGraph);
42 | void DrawCurrentCamera(pangolin::OpenGlMatrix &Twc);
43 | void SetCurrentCameraPose(const cv::Mat &Tcw);
44 | void SetReferenceKeyFrame(KeyFrame *pKF);
45 | void GetCurrentOpenGLCameraMatrix(pangolin::OpenGlMatrix &M, pangolin::OpenGlMatrix &MOw);
46 | void GetCurrentOpenGLCameraMatrix(pangolin::OpenGlMatrix &M, pangolin::OpenGlMatrix &MOw, pangolin::OpenGlMatrix &MTwwp);
47 |
48 | private:
49 |
50 | bool ParseViewerParamFile(cv::FileStorage &fSettings);
51 |
52 | float mKeyFrameSize;
53 | float mKeyFrameLineWidth;
54 | float mGraphLineWidth;
55 | float mPointSize;
56 | float mCameraSize;
57 | float mCameraLineWidth;
58 |
59 | cv::Mat mCameraPose;
60 |
61 | std::mutex mMutexCamera;
62 |
63 | float mfFrameColors[6][3] = {{0.0f, 0.0f, 1.0f},
64 | {0.8f, 0.4f, 1.0f},
65 | {1.0f, 0.2f, 0.4f},
66 | {0.6f, 0.0f, 1.0f},
67 | {1.0f, 1.0f, 0.0f},
68 | {0.0f, 1.0f, 1.0f}};
69 | };
70 |
71 | } //namespace ORB_SLAM
72 |
73 | #endif // MAPDRAWER_H
74 |
--------------------------------------------------------------------------------
/include/Viewer.h:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of ORB-SLAM3
3 | *
4 | * Copyright (C) 2017-2020 Carlos Campos, Richard Elvira, Juan J. Gómez Rodríguez, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
5 | * Copyright (C) 2014-2016 Raúl Mur-Artal, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
6 | *
7 | * ORB-SLAM3 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
8 | * License as published by the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * ORB-SLAM3 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
12 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License along with ORB-SLAM3.
16 | * If not, see .
17 | */
18 |
19 |
20 | #ifndef VIEWER_H
21 | #define VIEWER_H
22 |
23 | #include "FrameDrawer.h"
24 | #include "MapDrawer.h"
25 | #include "Tracking.h"
26 | #include "System.h"
27 |
28 | #include
29 |
30 | namespace ORB_SLAM3
31 | {
32 |
33 | class Tracking;
34 | class FrameDrawer;
35 | class MapDrawer;
36 | class System;
37 |
38 | class Viewer
39 | {
40 | public:
41 | Viewer(System* pSystem, FrameDrawer* pFrameDrawer, MapDrawer* pMapDrawer, Tracking *pTracking, const string &strSettingPath);
42 |
43 | // Main thread function. Draw points, keyframes, the current camera pose and the last processed
44 | // frame. Drawing is refreshed according to the camera fps. We use Pangolin.
45 | void Run();
46 |
47 | void RequestFinish();
48 |
49 | void RequestStop();
50 |
51 | bool isFinished();
52 |
53 | bool isStopped();
54 |
55 | bool isStepByStep();
56 |
57 | void Release();
58 |
59 | void SetTrackingPause();
60 |
61 | bool both;
62 | private:
63 |
64 | bool ParseViewerParamFile(cv::FileStorage &fSettings);
65 |
66 | bool Stop();
67 |
68 | System* mpSystem;
69 | FrameDrawer* mpFrameDrawer;
70 | MapDrawer* mpMapDrawer;
71 | Tracking* mpTracker;
72 |
73 | // 1/fps in ms
74 | double mT;
75 | float mImageWidth, mImageHeight;
76 |
77 | float mViewpointX, mViewpointY, mViewpointZ, mViewpointF;
78 |
79 | bool CheckFinish();
80 | void SetFinish();
81 | bool mbFinishRequested;
82 | bool mbFinished;
83 | std::mutex mMutexFinish;
84 |
85 | bool mbStopped;
86 | bool mbStopRequested;
87 | std::mutex mMutexStop;
88 |
89 | bool mbStopTrack;
90 |
91 | };
92 |
93 | }
94 |
95 |
96 | #endif // VIEWER_H
97 |
98 |
99 |
--------------------------------------------------------------------------------
/include/FrameDrawer.h:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of ORB-SLAM3
3 | *
4 | * Copyright (C) 2017-2020 Carlos Campos, Richard Elvira, Juan J. Gómez Rodríguez, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
5 | * Copyright (C) 2014-2016 Raúl Mur-Artal, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
6 | *
7 | * ORB-SLAM3 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
8 | * License as published by the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * ORB-SLAM3 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
12 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License along with ORB-SLAM3.
16 | * If not, see .
17 | */
18 |
19 |
20 | #ifndef FRAMEDRAWER_H
21 | #define FRAMEDRAWER_H
22 |
23 | #include "Tracking.h"
24 | #include "MapPoint.h"
25 | #include "Atlas.h"
26 |
27 | #include
28 | #include
29 |
30 | #include
31 | #include
32 |
33 |
34 | namespace ORB_SLAM3
35 | {
36 |
37 | class Tracking;
38 | class Viewer;
39 |
40 | class FrameDrawer
41 | {
42 | public:
43 | FrameDrawer(Atlas* pAtlas);
44 |
45 | // Update info from the last processed frame.
46 | void Update(Tracking *pTracker);
47 |
48 | // Draw last processed frame.
49 | cv::Mat DrawFrame(bool bOldFeatures=true);
50 | cv::Mat DrawRightFrame();
51 |
52 | bool both;
53 |
54 | protected:
55 |
56 | void DrawTextInfo(cv::Mat &im, int nState, cv::Mat &imText);
57 |
58 | // Info of the frame to be drawn
59 | cv::Mat mIm, mImRight;
60 | int N;
61 | vector mvCurrentKeys,mvCurrentKeysRight;
62 | vector mvbMap, mvbVO;
63 | bool mbOnlyTracking;
64 | int mnTracked, mnTrackedVO;
65 | vector mvIniKeys;
66 | vector mvIniMatches;
67 | int mState;
68 |
69 | Atlas* mpAtlas;
70 |
71 | std::mutex mMutex;
72 | vector > mvTracks;
73 |
74 | Frame mCurrentFrame;
75 | vector mvpLocalMap;
76 | vector mvMatchedKeys;
77 | vector mvpMatchedMPs;
78 | vector mvOutlierKeys;
79 | vector mvpOutlierMPs;
80 |
81 | map mmProjectPoints;
82 | map mmMatchedInImage;
83 |
84 | };
85 |
86 | } //namespace ORB_SLAM
87 |
88 | #endif // FRAMEDRAWER_H
89 |
--------------------------------------------------------------------------------
/include/KeyFrameDatabase.h:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of ORB-SLAM3
3 | *
4 | * Copyright (C) 2017-2020 Carlos Campos, Richard Elvira, Juan J. Gómez Rodríguez, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
5 | * Copyright (C) 2014-2016 Raúl Mur-Artal, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
6 | *
7 | * ORB-SLAM3 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
8 | * License as published by the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * ORB-SLAM3 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
12 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License along with ORB-SLAM3.
16 | * If not, see .
17 | */
18 |
19 |
20 | #ifndef KEYFRAMEDATABASE_H
21 | #define KEYFRAMEDATABASE_H
22 |
23 | #include
24 | #include
25 | #include
26 |
27 | #include "KeyFrame.h"
28 | #include "Frame.h"
29 | #include "ORBVocabulary.h"
30 | #include "Map.h"
31 |
32 | #include
33 | #include
34 | #include
35 |
36 | #include
37 |
38 |
39 | namespace ORB_SLAM3
40 | {
41 |
42 | class KeyFrame;
43 | class Frame;
44 | class Map;
45 |
46 |
47 | class KeyFrameDatabase
48 | {
49 | friend class boost::serialization::access;
50 |
51 | template
52 | void serialize(Archive& ar, const unsigned int version)
53 | {
54 | ar & mvBackupInvertedFileId;
55 | }
56 |
57 | public:
58 |
59 | KeyFrameDatabase(const ORBVocabulary &voc);
60 |
61 | void add(KeyFrame* pKF);
62 |
63 | void erase(KeyFrame* pKF);
64 |
65 | void clear();
66 | void clearMap(Map* pMap);
67 |
68 | // Loop Detection(DEPRECATED)
69 | std::vector DetectLoopCandidates(KeyFrame* pKF, float minScore);
70 |
71 | // Loop and Merge Detection
72 | void DetectCandidates(KeyFrame* pKF, float minScore,vector& vpLoopCand, vector& vpMergeCand);
73 | void DetectBestCandidates(KeyFrame *pKF, vector &vpLoopCand, vector &vpMergeCand, int nMinWords);
74 | void DetectNBestCandidates(KeyFrame *pKF, vector &vpLoopCand, vector &vpMergeCand, int nNumCandidates);
75 |
76 | // Relocalization
77 | std::vector DetectRelocalizationCandidates(Frame* F, Map* pMap);
78 |
79 | void PreSave();
80 | void PostLoad(map mpKFid);
81 | void SetORBVocabulary(ORBVocabulary* pORBVoc);
82 |
83 | protected:
84 |
85 | // Associated vocabulary
86 | const ORBVocabulary* mpVoc;
87 |
88 | // Inverted file
89 | // 每一个worldId下面对应kf集合
90 | std::vector > mvInvertedFile;
91 |
92 | // For save relation without pointer, this is necessary for save/load function
93 | std::vector > mvBackupInvertedFileId;
94 |
95 | // Mutex
96 | std::mutex mMutex;
97 | };
98 |
99 | } //namespace ORB_SLAM
100 |
101 | #endif
102 |
--------------------------------------------------------------------------------
/include/ORBextractor.h:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of ORB-SLAM3
3 | *
4 | * Copyright (C) 2017-2020 Carlos Campos, Richard Elvira, Juan J. Gómez Rodríguez, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
5 | * Copyright (C) 2014-2016 Raúl Mur-Artal, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
6 | *
7 | * ORB-SLAM3 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
8 | * License as published by the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * ORB-SLAM3 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
12 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License along with ORB-SLAM3.
16 | * If not, see .
17 | */
18 |
19 | #ifndef ORBEXTRACTOR_H
20 | #define ORBEXTRACTOR_H
21 |
22 | #include
23 | #include
24 | #include
25 |
26 |
27 | namespace ORB_SLAM3
28 | {
29 |
30 | class ExtractorNode
31 | {
32 | public:
33 | ExtractorNode():bNoMore(false){}
34 |
35 | void DivideNode(ExtractorNode &n1, ExtractorNode &n2, ExtractorNode &n3, ExtractorNode &n4);
36 |
37 | std::vector vKeys;
38 | cv::Point2i UL, UR, BL, BR;
39 | std::list::iterator lit;
40 | bool bNoMore;
41 | };
42 |
43 | class ORBextractor
44 | {
45 | public:
46 |
47 | enum {HARRIS_SCORE=0, FAST_SCORE=1 };
48 |
49 | ORBextractor(int nfeatures, float scaleFactor, int nlevels,
50 | int iniThFAST, int minThFAST);
51 |
52 | ~ORBextractor(){}
53 |
54 | // Compute the ORB features and descriptors on an image.
55 | // ORB are dispersed on the image using an octree.
56 | // Mask is ignored in the current implementation.
57 | int operator()( cv::InputArray _image, cv::InputArray _mask,
58 | std::vector& _keypoints,
59 | cv::OutputArray _descriptors, std::vector &vLappingArea);
60 |
61 | int inline GetLevels(){
62 | return nlevels;}
63 |
64 | float inline GetScaleFactor(){
65 | return scaleFactor;}
66 |
67 | std::vector inline GetScaleFactors(){
68 | return mvScaleFactor;
69 | }
70 |
71 | std::vector inline GetInverseScaleFactors(){
72 | return mvInvScaleFactor;
73 | }
74 |
75 | std::vector inline GetScaleSigmaSquares(){
76 | return mvLevelSigma2;
77 | }
78 |
79 | std::vector inline GetInverseScaleSigmaSquares(){
80 | return mvInvLevelSigma2;
81 | }
82 |
83 | std::vector mvImagePyramid;
84 |
85 | protected:
86 |
87 | void ComputePyramid(cv::Mat image);
88 | void ComputeKeyPointsOctTree(std::vector >& allKeypoints);
89 | std::vector DistributeOctTree(const std::vector& vToDistributeKeys, const int &minX,
90 | const int &maxX, const int &minY, const int &maxY, const int &nFeatures, const int &level);
91 |
92 | void ComputeKeyPointsOld(std::vector >& allKeypoints);
93 | std::vector pattern;
94 |
95 | int nfeatures;
96 | double scaleFactor;
97 | int nlevels;
98 | int iniThFAST;
99 | int minThFAST;
100 |
101 | std::vector mnFeaturesPerLevel;
102 |
103 | std::vector umax;
104 |
105 | std::vector mvScaleFactor;
106 | std::vector mvInvScaleFactor;
107 | std::vector mvLevelSigma2;
108 | std::vector mvInvLevelSigma2;
109 | };
110 |
111 | } //namespace ORB_SLAM
112 |
113 | #endif
114 |
115 |
--------------------------------------------------------------------------------
/include/Sim3Solver.h:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of ORB-SLAM3
3 | *
4 | * Copyright (C) 2017-2020 Carlos Campos, Richard Elvira, Juan J. Gómez Rodríguez, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
5 | * Copyright (C) 2014-2016 Raúl Mur-Artal, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
6 | *
7 | * ORB-SLAM3 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
8 | * License as published by the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * ORB-SLAM3 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
12 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License along with ORB-SLAM3.
16 | * If not, see .
17 | */
18 |
19 |
20 | #ifndef SIM3SOLVER_H
21 | #define SIM3SOLVER_H
22 |
23 | #include
24 | #include
25 |
26 | #include "KeyFrame.h"
27 |
28 |
29 |
30 | namespace ORB_SLAM3
31 | {
32 |
33 | class Sim3Solver
34 | {
35 | public:
36 |
37 | Sim3Solver(KeyFrame* pKF1, KeyFrame* pKF2, const std::vector &vpMatched12, const bool bFixScale = true,
38 | const vector vpKeyFrameMatchedMP = vector());
39 |
40 | void SetRansacParameters(double probability = 0.99, int minInliers = 6 , int maxIterations = 300);
41 |
42 | cv::Mat find(std::vector &vbInliers12, int &nInliers);
43 |
44 | cv::Mat iterate(int nIterations, bool &bNoMore, std::vector &vbInliers, int &nInliers);
45 | cv::Mat iterate(int nIterations, bool &bNoMore, vector &vbInliers, int &nInliers, bool &bConverge);
46 |
47 | cv::Mat GetEstimatedRotation();
48 | cv::Mat GetEstimatedTranslation();
49 | float GetEstimatedScale();
50 |
51 |
52 | protected:
53 |
54 | void ComputeCentroid(cv::Mat &P, cv::Mat &Pr, cv::Mat &C);
55 |
56 | void ComputeSim3(cv::Mat &P1, cv::Mat &P2);
57 |
58 | void CheckInliers();
59 |
60 | void Project(const std::vector &vP3Dw, std::vector &vP2D, cv::Mat Tcw, GeometricCamera* pCamera);
61 | void FromCameraToImage(const std::vector &vP3Dc, std::vector &vP2D, GeometricCamera* pCamera);
62 |
63 |
64 | protected:
65 |
66 | // KeyFrames and matches
67 | KeyFrame* mpKF1;
68 | KeyFrame* mpKF2;
69 |
70 | std::vector mvX3Dc1;
71 | std::vector mvX3Dc2;
72 | std::vector mvpMapPoints1;
73 | std::vector mvpMapPoints2;
74 | std::vector mvpMatches12;
75 | std::vector mvnIndices1;
76 | std::vector mvSigmaSquare1;
77 | std::vector mvSigmaSquare2;
78 | std::vector mvnMaxError1;
79 | std::vector mvnMaxError2;
80 |
81 | int N;
82 | int mN1;
83 |
84 | // Current Estimation
85 | cv::Mat mR12i;
86 | cv::Mat mt12i;
87 | float ms12i;
88 | cv::Mat mT12i;
89 | cv::Mat mT21i;
90 | std::vector mvbInliersi;
91 | int mnInliersi;
92 |
93 | // Current Ransac State
94 | int mnIterations;
95 | std::vector mvbBestInliers;
96 | int mnBestInliers;
97 | cv::Mat mBestT12;
98 | cv::Mat mBestRotation;
99 | cv::Mat mBestTranslation;
100 | float mBestScale;
101 |
102 | // Scale is fixed to 1 in the stereo/RGBD case
103 | bool mbFixScale;
104 |
105 | // Indices for random selection
106 | std::vector mvAllIndices;
107 |
108 | // Projections
109 | std::vector mvP1im1;
110 | std::vector mvP2im2;
111 |
112 | // RANSAC probability
113 | double mRansacProb;
114 |
115 | // RANSAC min inliers
116 | int mRansacMinInliers;
117 |
118 | // RANSAC max iterations
119 | int mRansacMaxIts;
120 |
121 | // Threshold inlier/outlier. e = dist(Pi,T_ij*Pj)^2 < 5.991*mSigma2
122 | float mTh;
123 | float mSigma2;
124 |
125 | // Calibration
126 | cv::Mat mK1;
127 | cv::Mat mK2;
128 |
129 | GeometricCamera* pCamera1, *pCamera2;
130 | };
131 |
132 | } //namespace ORB_SLAM
133 |
134 | #endif // SIM3SOLVER_H
135 |
--------------------------------------------------------------------------------
/include/TwoViewReconstruction.h:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of ORB-SLAM3
3 | *
4 | * Copyright (C) 2017-2020 Carlos Campos, Richard Elvira, Juan J. Gómez Rodríguez, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
5 | * Copyright (C) 2014-2016 Raúl Mur-Artal, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
6 | *
7 | * ORB-SLAM3 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
8 | * License as published by the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * ORB-SLAM3 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
12 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License along with ORB-SLAM3.
16 | * If not, see .
17 | */
18 |
19 | #ifndef TwoViewReconstruction_H
20 | #define TwoViewReconstruction_H
21 |
22 | #include
23 |
24 | #include
25 |
26 | namespace ORB_SLAM3
27 | {
28 |
29 | class TwoViewReconstruction
30 | {
31 | typedef std::pair Match;
32 |
33 | public:
34 |
35 | // Fix the reference frame
36 | TwoViewReconstruction(cv::Mat& k, float sigma = 1.0, int iterations = 200);
37 |
38 | // Computes in parallel a fundamental matrix and a homography
39 | // Selects a model and tries to recover the motion and the structure from motion
40 | bool Reconstruct(const std::vector& vKeys1, const std::vector& vKeys2, const std::vector &vMatches12,
41 | cv::Mat &R21, cv::Mat &t21, std::vector &vP3D, std::vector &vbTriangulated);
42 |
43 | private:
44 |
45 | void FindHomography(std::vector &vbMatchesInliers, float &score, cv::Mat &H21);
46 | void FindFundamental(std::vector &vbInliers, float &score, cv::Mat &F21);
47 |
48 | cv::Mat ComputeH21(const std::vector &vP1, const std::vector &vP2);
49 | cv::Mat ComputeF21(const std::vector &vP1, const std::vector &vP2);
50 |
51 | float CheckHomography(const cv::Mat &H21, const cv::Mat &H12, std::vector &vbMatchesInliers, float sigma);
52 |
53 | float CheckFundamental(const cv::Mat &F21, std::vector &vbMatchesInliers, float sigma);
54 |
55 | bool ReconstructF(std::vector &vbMatchesInliers, cv::Mat &F21, cv::Mat &K,
56 | cv::Mat &R21, cv::Mat &t21, std::vector &vP3D, std::vector &vbTriangulated, float minParallax, int minTriangulated);
57 |
58 | bool ReconstructH(std::vector &vbMatchesInliers, cv::Mat &H21, cv::Mat &K,
59 | cv::Mat &R21, cv::Mat &t21, std::vector &vP3D,std:: vector &vbTriangulated, float minParallax, int minTriangulated);
60 |
61 | void Triangulate(const cv::KeyPoint &kp1, const cv::KeyPoint &kp2, const cv::Mat &P1, const cv::Mat &P2, cv::Mat &x3D);
62 |
63 | void Normalize(const std::vector &vKeys, std::vector &vNormalizedPoints, cv::Mat &T);
64 |
65 |
66 | int CheckRT(const cv::Mat &R, const cv::Mat &t, const std::vector &vKeys1, const std::vector &vKeys2,
67 | const std::vector &vMatches12, std::vector &vbInliers,
68 | const cv::Mat &K, std::vector &vP3D, float th2, std::vector &vbGood, float ¶llax);
69 |
70 | void DecomposeE(const cv::Mat &E, cv::Mat &R1, cv::Mat &R2, cv::Mat &t);
71 |
72 |
73 | // Keypoints from Reference Frame (Frame 1)
74 | std::vector mvKeys1;
75 |
76 | // Keypoints from Current Frame (Frame 2)
77 | std::vector mvKeys2;
78 |
79 | // Current Matches from Reference to Current
80 | std::vector mvMatches12;
81 | std::vector mvbMatched1;
82 |
83 | // Calibration
84 | cv::Mat mK;
85 |
86 | // Standard Deviation and Variance
87 | float mSigma, mSigma2;
88 |
89 | // Ransac max iterations
90 | int mMaxIterations;
91 |
92 | // Ransac sets
93 | std::vector > mvSets;
94 |
95 | };
96 |
97 | } //namespace ORB_SLAM
98 |
99 | #endif // TwoViewReconstruction_H
100 |
--------------------------------------------------------------------------------
/include/Initializer.h:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of ORB-SLAM3
3 | *
4 | * Copyright (C) 2017-2020 Carlos Campos, Richard Elvira, Juan J. Gómez Rodríguez, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
5 | * Copyright (C) 2014-2016 Raúl Mur-Artal, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
6 | *
7 | * ORB-SLAM3 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
8 | * License as published by the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * ORB-SLAM3 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
12 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License along with ORB-SLAM3.
16 | * If not, see .
17 | */
18 |
19 |
20 | #ifndef INITIALIZER_H
21 | #define INITIALIZER_H
22 |
23 | #include
24 | #include "Frame.h"
25 |
26 | #include
27 |
28 | namespace ORB_SLAM3
29 | {
30 |
31 | class Map;
32 |
33 | // THIS IS THE INITIALIZER FOR MONOCULAR SLAM. NOT USED IN THE STEREO OR RGBD CASE.
34 | class Initializer
35 | {
36 | typedef pair Match;
37 |
38 | public:
39 |
40 | // Fix the reference frame
41 | Initializer(const Frame &ReferenceFrame, float sigma = 1.0, int iterations = 200);
42 |
43 | // Computes in parallel a fundamental matrix and a homography
44 | // Selects a model and tries to recover the motion and the structure from motion
45 | bool Initialize(const Frame &CurrentFrame, const vector &vMatches12, cv::Mat &R21,
46 | cv::Mat &t21, vector &vP3D, vector &vbTriangulated);
47 |
48 | private:
49 |
50 | void FindHomography(vector &vbMatchesInliers, float &score, cv::Mat &H21);
51 | void FindFundamental(vector &vbInliers, float &score, cv::Mat &F21);
52 |
53 | cv::Mat ComputeH21(const vector &vP1, const vector &vP2);
54 | cv::Mat ComputeF21(const vector &vP1, const vector &vP2);
55 |
56 | float CheckHomography(const cv::Mat &H21, const cv::Mat &H12, vector &vbMatchesInliers, float sigma);
57 |
58 | float CheckFundamental(const cv::Mat &F21, vector &vbMatchesInliers, float sigma);
59 |
60 | bool ReconstructF(vector &vbMatchesInliers, cv::Mat &F21, cv::Mat &K,
61 | cv::Mat &R21, cv::Mat &t21, vector &vP3D, vector &vbTriangulated, float minParallax, int minTriangulated);
62 |
63 | bool ReconstructH(vector &vbMatchesInliers, cv::Mat &H21, cv::Mat &K,
64 | cv::Mat &R21, cv::Mat &t21, vector &vP3D, vector &vbTriangulated, float minParallax, int minTriangulated);
65 |
66 | void Triangulate(const cv::KeyPoint &kp1, const cv::KeyPoint &kp2, const cv::Mat &P1, const cv::Mat &P2, cv::Mat &x3D);
67 |
68 | void Normalize(const vector &vKeys, vector &vNormalizedPoints, cv::Mat &T);
69 | // void Normalize(const vector &vKeys, vector &vNormalizedPoints, cv::Mat &T);
70 |
71 | int CheckRT(const cv::Mat &R, const cv::Mat &t, const vector &vKeys1, const vector &vKeys2,
72 | const vector &vMatches12, vector &vbInliers,
73 | const cv::Mat &K, vector &vP3D, float th2, vector &vbGood, float ¶llax);
74 |
75 | void DecomposeE(const cv::Mat &E, cv::Mat &R1, cv::Mat &R2, cv::Mat &t);
76 |
77 |
78 | // Keypoints from Reference Frame (Frame 1)
79 | vector mvKeys1;
80 |
81 | // Keypoints from Current Frame (Frame 2)
82 | vector mvKeys2;
83 |
84 | // Current Matches from Reference to Current
85 | vector mvMatches12;
86 | vector mvbMatched1;
87 |
88 | // Calibration
89 | cv::Mat mK;
90 |
91 | // Standard Deviation and Variance
92 | float mSigma, mSigma2;
93 |
94 | // Ransac max iterations
95 | int mMaxIterations;
96 |
97 | // Ransac sets
98 | vector > mvSets;
99 |
100 | GeometricCamera* mpCamera;
101 |
102 | };
103 |
104 | } //namespace ORB_SLAM
105 |
106 | #endif // INITIALIZER_H
107 |
--------------------------------------------------------------------------------
/include/CameraModels/GeometricCamera.h:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of ORB-SLAM3
3 | *
4 | * Copyright (C) 2017-2020 Carlos Campos, Richard Elvira, Juan J. Gómez Rodríguez, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
5 | * Copyright (C) 2014-2016 Raúl Mur-Artal, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
6 | *
7 | * ORB-SLAM3 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
8 | * License as published by the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * ORB-SLAM3 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
12 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License along with ORB-SLAM3.
16 | * If not, see .
17 | */
18 |
19 | #ifndef CAMERAMODELS_GEOMETRICCAMERA_H
20 | #define CAMERAMODELS_GEOMETRICCAMERA_H
21 |
22 | #include
23 |
24 | #include
25 | #include
26 |
27 | #include
28 | #include
29 | #include
30 | #include
31 | #include
32 | #include
33 |
34 | #include
35 |
36 | namespace ORB_SLAM3 {
37 | class GeometricCamera {
38 |
39 | friend class boost::serialization::access;
40 |
41 | template
42 | void serialize(Archive& ar, const unsigned int version)
43 | {
44 | ar & mnId;
45 | ar & mnType;
46 | ar & mvParameters;
47 | }
48 |
49 |
50 | public:
51 | GeometricCamera() {}
52 | GeometricCamera(const std::vector &_vParameters) : mvParameters(_vParameters) {}
53 | ~GeometricCamera() {}
54 |
55 | virtual cv::Point2f project(const cv::Point3f &p3D) = 0;
56 | virtual cv::Point2f project(const cv::Mat& m3D) = 0;
57 | virtual Eigen::Vector2d project(const Eigen::Vector3d & v3D) = 0;
58 | virtual cv::Mat projectMat(const cv::Point3f& p3D) = 0;
59 |
60 | virtual float uncertainty2(const Eigen::Matrix &p2D) = 0;
61 |
62 | virtual cv::Point3f unproject(const cv::Point2f &p2D) = 0;
63 | virtual cv::Mat unprojectMat(const cv::Point2f &p2D) = 0;
64 |
65 | virtual cv::Mat projectJac(const cv::Point3f &p3D) = 0;
66 | virtual Eigen::Matrix projectJac(const Eigen::Vector3d& v3D) = 0;
67 |
68 | virtual cv::Mat unprojectJac(const cv::Point2f &p2D) = 0;
69 |
70 | virtual bool ReconstructWithTwoViews(const std::vector& vKeys1, const std::vector& vKeys2, const std::vector &vMatches12,
71 | cv::Mat &R21, cv::Mat &t21, std::vector &vP3D, std::vector &vbTriangulated) = 0;
72 |
73 | virtual cv::Mat toK() = 0;
74 |
75 | virtual bool epipolarConstrain(GeometricCamera* otherCamera, const cv::KeyPoint& kp1, const cv::KeyPoint& kp2, const cv::Mat& R12, const cv::Mat& t12, const float sigmaLevel, const float unc) = 0;
76 |
77 | float getParameter(const int i){return mvParameters[i];}
78 | void setParameter(const float p, const size_t i){mvParameters[i] = p;}
79 |
80 | size_t size(){return mvParameters.size();}
81 |
82 | virtual bool matchAndtriangulate(const cv::KeyPoint& kp1, const cv::KeyPoint& kp2, GeometricCamera* pOther,
83 | cv::Mat& Tcw1, cv::Mat& Tcw2,
84 | const float sigmaLevel1, const float sigmaLevel2,
85 | cv::Mat& x3Dtriangulated) = 0;
86 |
87 | unsigned int GetId() { return mnId; }
88 |
89 | unsigned int GetType() { return mnType; }
90 |
91 | const unsigned int CAM_PINHOLE = 0;
92 | const unsigned int CAM_FISHEYE = 1;
93 |
94 | static long unsigned int nNextId;
95 |
96 | protected:
97 | std::vector mvParameters;
98 |
99 | unsigned int mnId;
100 |
101 | unsigned int mnType;
102 | };
103 | }
104 |
105 |
106 | #endif //CAMERAMODELS_GEOMETRICCAMERA_H
107 |
--------------------------------------------------------------------------------
/include/CameraModels/Pinhole.h:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of ORB-SLAM3
3 | *
4 | * Copyright (C) 2017-2020 Carlos Campos, Richard Elvira, Juan J. Gómez Rodríguez, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
5 | * Copyright (C) 2014-2016 Raúl Mur-Artal, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
6 | *
7 | * ORB-SLAM3 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
8 | * License as published by the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * ORB-SLAM3 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
12 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License along with ORB-SLAM3.
16 | * If not, see .
17 | */
18 |
19 | #ifndef CAMERAMODELS_PINHOLE_H
20 | #define CAMERAMODELS_PINHOLE_H
21 |
22 | #include
23 | #include
24 | #include
25 |
26 | #include
27 | #include
28 | #include
29 | #include
30 |
31 | #include "GeometricCamera.h"
32 |
33 | #include "TwoViewReconstruction.h"
34 |
35 | namespace ORB_SLAM3 {
36 | class Pinhole : public GeometricCamera {
37 |
38 | friend class boost::serialization::access;
39 |
40 | template
41 | void serialize(Archive& ar, const unsigned int version)
42 | {
43 | ar & boost::serialization::base_object(*this);
44 | }
45 |
46 | public:
47 | Pinhole() {
48 | mvParameters.resize(4);
49 | mnId=nNextId++;
50 | mnType = CAM_PINHOLE;
51 | }
52 | Pinhole(const std::vector _vParameters) : GeometricCamera(_vParameters), tvr(nullptr) {
53 | assert(mvParameters.size() == 4);
54 | mnId=nNextId++;
55 | mnType = CAM_PINHOLE;
56 | }
57 |
58 | Pinhole(Pinhole* pPinhole) : GeometricCamera(pPinhole->mvParameters), tvr(nullptr) {
59 | assert(mvParameters.size() == 4);
60 | mnId=nNextId++;
61 | mnType = CAM_PINHOLE;
62 | }
63 |
64 |
65 | ~Pinhole(){
66 | if(tvr) delete tvr;
67 | }
68 |
69 | cv::Point2f project(const cv::Point3f &p3D);
70 | cv::Point2f project(const cv::Mat &m3D);
71 | Eigen::Vector2d project(const Eigen::Vector3d & v3D);
72 | cv::Mat projectMat(const cv::Point3f& p3D);
73 |
74 | float uncertainty2(const Eigen::Matrix &p2D);
75 |
76 | cv::Point3f unproject(const cv::Point2f &p2D);
77 | cv::Mat unprojectMat(const cv::Point2f &p2D);
78 |
79 | cv::Mat projectJac(const cv::Point3f &p3D);
80 | Eigen::Matrix projectJac(const Eigen::Vector3d& v3D);
81 |
82 | cv::Mat unprojectJac(const cv::Point2f &p2D);
83 |
84 | bool ReconstructWithTwoViews(const std::vector& vKeys1, const std::vector& vKeys2, const std::vector &vMatches12,
85 | cv::Mat &R21, cv::Mat &t21, std::vector &vP3D, std::vector &vbTriangulated);
86 |
87 | cv::Mat toK();
88 |
89 | bool epipolarConstrain(GeometricCamera* pCamera2, const cv::KeyPoint& kp1, const cv::KeyPoint& kp2, const cv::Mat& R12, const cv::Mat& t12, const float sigmaLevel, const float unc);
90 |
91 | bool matchAndtriangulate(const cv::KeyPoint& kp1, const cv::KeyPoint& kp2, GeometricCamera* pOther,
92 | cv::Mat& Tcw1, cv::Mat& Tcw2,
93 | const float sigmaLevel1, const float sigmaLevel2,
94 | cv::Mat& x3Dtriangulated) { return false;}
95 |
96 | friend std::ostream& operator<<(std::ostream& os, const Pinhole& ph);
97 | friend std::istream& operator>>(std::istream& os, Pinhole& ph);
98 | private:
99 | cv::Mat SkewSymmetricMatrix(const cv::Mat &v);
100 |
101 | //Parameters vector corresponds to
102 | // [fx, fy, cx, cy]
103 |
104 | TwoViewReconstruction* tvr;
105 | };
106 | }
107 |
108 | //BOOST_CLASS_EXPORT_KEY(ORBSLAM2::Pinhole)
109 |
110 | #endif //CAMERAMODELS_PINHOLE_H
111 |
--------------------------------------------------------------------------------
/include/LocalMapping.h:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of ORB-SLAM3
3 | *
4 | * Copyright (C) 2017-2020 Carlos Campos, Richard Elvira, Juan J. Gómez Rodríguez, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
5 | * Copyright (C) 2014-2016 Raúl Mur-Artal, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
6 | *
7 | * ORB-SLAM3 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
8 | * License as published by the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * ORB-SLAM3 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
12 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License along with ORB-SLAM3.
16 | * If not, see .
17 | */
18 |
19 |
20 | #ifndef LOCALMAPPING_H
21 | #define LOCALMAPPING_H
22 |
23 | #include "KeyFrame.h"
24 | #include "Atlas.h"
25 | #include "LoopClosing.h"
26 | #include "Tracking.h"
27 | #include "KeyFrameDatabase.h"
28 | #include "Initializer.h"
29 |
30 | #include
31 |
32 |
33 | namespace ORB_SLAM3
34 | {
35 |
36 | class System;
37 | class Tracking;
38 | class LoopClosing;
39 | class Atlas;
40 |
41 | class LocalMapping
42 | {
43 | public:
44 | LocalMapping(System* pSys, Atlas* pAtlas, const float bMonocular, bool bInertial, const string &_strSeqName=std::string());
45 |
46 | void SetLoopCloser(LoopClosing* pLoopCloser);
47 |
48 | void SetTracker(Tracking* pTracker);
49 |
50 | // Main function
51 | void Run();
52 |
53 | void InsertKeyFrame(KeyFrame* pKF);
54 | void EmptyQueue();
55 |
56 | // Thread Synch
57 | void RequestStop();
58 | void RequestReset();
59 | void RequestResetActiveMap(Map* pMap);
60 | bool Stop();
61 | void Release();
62 | bool isStopped();
63 | bool stopRequested();
64 | bool AcceptKeyFrames();
65 | void SetAcceptKeyFrames(bool flag);
66 | bool SetNotStop(bool flag);
67 |
68 | void InterruptBA();
69 |
70 | void RequestFinish();
71 | bool isFinished();
72 |
73 | int KeyframesInQueue(){
74 | unique_lock lock(mMutexNewKFs);
75 | return mlNewKeyFrames.size();
76 | }
77 |
78 | bool IsInitializing();
79 | double GetCurrKFTime();
80 | KeyFrame* GetCurrKF();
81 |
82 | std::mutex mMutexImuInit;
83 |
84 | Eigen::MatrixXd mcovInertial;
85 | Eigen::Matrix3d mRwg;
86 | Eigen::Vector3d mbg;
87 | Eigen::Vector3d mba;
88 | double mScale;
89 | double mInitTime;
90 | double mCostTime;
91 | bool mbNewInit;
92 | unsigned int mInitSect;
93 | unsigned int mIdxInit;
94 | unsigned int mnKFs;
95 | double mFirstTs;
96 | int mnMatchesInliers;
97 |
98 | // For debugging (erase in normal mode)
99 | int mInitFr;
100 | int mIdxIteration;
101 | string strSequence;
102 |
103 | bool mbNotBA1;
104 | bool mbNotBA2;
105 | bool mbBadImu;
106 |
107 | bool mbWriteStats;
108 |
109 | // not consider far points (clouds)
110 | bool mbFarPoints;
111 | float mThFarPoints;
112 | protected:
113 |
114 | bool CheckNewKeyFrames();
115 | void ProcessNewKeyFrame();
116 | void CreateNewMapPoints();
117 |
118 | void MapPointCulling();
119 | void SearchInNeighbors();
120 | void KeyFrameCulling();
121 |
122 | cv::Mat ComputeF12(KeyFrame* &pKF1, KeyFrame* &pKF2);
123 |
124 | cv::Mat SkewSymmetricMatrix(const cv::Mat &v);
125 |
126 | System *mpSystem;
127 |
128 | bool mbMonocular;
129 | bool mbInertial;
130 |
131 | void ResetIfRequested();
132 | bool mbResetRequested;
133 | bool mbResetRequestedActiveMap;
134 | Map* mpMapToReset;
135 | std::mutex mMutexReset;
136 |
137 | bool CheckFinish();
138 | void SetFinish();
139 | bool mbFinishRequested;
140 | bool mbFinished;
141 | std::mutex mMutexFinish;
142 |
143 | Atlas* mpAtlas;
144 |
145 | LoopClosing* mpLoopCloser;
146 | Tracking* mpTracker;
147 |
148 | std::list mlNewKeyFrames;
149 |
150 | KeyFrame* mpCurrentKeyFrame;
151 |
152 | std::list mlpRecentAddedMapPoints;
153 |
154 | std::mutex mMutexNewKFs;
155 |
156 | bool mbAbortBA;
157 |
158 | bool mbStopped;
159 | bool mbStopRequested;
160 | bool mbNotStop;
161 | std::mutex mMutexStop;
162 |
163 | bool mbAcceptKeyFrames;
164 | std::mutex mMutexAccept;
165 |
166 | void InitializeIMU(float priorG = 1e2, float priorA = 1e6, bool bFirst = false);
167 | void ScaleRefinement();
168 |
169 | bool bInitializing;
170 |
171 | Eigen::MatrixXd infoInertial;
172 | int mNumLM;
173 | int mNumKFCulling;
174 |
175 | float mTinit;
176 |
177 | int countRefinement;
178 |
179 | //DEBUG
180 | ofstream f_lm;
181 | };
182 |
183 | } //namespace ORB_SLAM
184 |
185 | #endif // LOCALMAPPING_H
186 |
--------------------------------------------------------------------------------
/include/Atlas.h:
--------------------------------------------------------------------------------
1 | /**
2 | * This file is part of ORB-SLAM3
3 | *
4 | * Copyright (C) 2017-2020 Carlos Campos, Richard Elvira, Juan J. Gómez Rodríguez, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
5 | * Copyright (C) 2014-2016 Raúl Mur-Artal, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
6 | *
7 | * ORB-SLAM3 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
8 | * License as published by the Free Software Foundation, either version 3 of the License, or
9 | * (at your option) any later version.
10 | *
11 | * ORB-SLAM3 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
12 | * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License along with ORB-SLAM3.
16 | * If not, see .
17 | */
18 |
19 | #ifndef ATLAS_H
20 | #define ATLAS_H
21 |
22 | #include "Map.h"
23 | #include "MapPoint.h"
24 | #include "KeyFrame.h"
25 | #include "GeometricCamera.h"
26 | #include "Pinhole.h"
27 | #include "KannalaBrandt8.h"
28 |
29 | #include
30 | #include
31 | #include
32 | #include
33 |
34 |
35 | namespace ORB_SLAM3
36 | {
37 | class Viewer;
38 | class Map;
39 | class MapPoint;
40 | class KeyFrame;
41 | class KeyFrameDatabase;
42 | class Frame;
43 | class KannalaBrandt8;
44 | class Pinhole;
45 |
46 | //BOOST_CLASS_EXPORT_GUID(Pinhole, "Pinhole")
47 | //BOOST_CLASS_EXPORT_GUID(KannalaBrandt8, "KannalaBrandt8")
48 |
49 | class Atlas
50 | {
51 | friend class boost::serialization::access;
52 |
53 | template
54 | void serialize(Archive &ar, const unsigned int version)
55 | {
56 | //ar.template register_type();
57 | //ar.template register_type();
58 |
59 | // Save/load the set of maps, the set is broken in libboost 1.58 for ubuntu 16.04
60 | //ar & mspMaps;
61 | ar & mvpBackupMaps;
62 | ar & mvpCameras;
63 | //ar & mvpBackupCamPin;
64 | //ar & mvpBackupCamKan;
65 | // Need to save/load the static Id from Frame, KeyFrame, MapPoint and Map
66 | ar & Map::nNextId;
67 | ar & Frame::nNextId;
68 | ar & KeyFrame::nNextId;
69 | ar & MapPoint::nNextId;
70 | ar & GeometricCamera::nNextId;
71 | ar & mnLastInitKFidMap;
72 | }
73 |
74 | public:
75 | Atlas();
76 | Atlas(int initKFid); // When its initialization the first map is created
77 | ~Atlas();
78 |
79 | void CreateNewMap();
80 | void ChangeMap(Map* pMap);
81 |
82 | unsigned long int GetLastInitKFid();
83 |
84 | void SetViewer(Viewer* pViewer);
85 |
86 | // Method for change components in the current map
87 | void AddKeyFrame(KeyFrame* pKF);
88 | void AddMapPoint(MapPoint* pMP);
89 | //void EraseMapPoint(MapPoint* pMP);
90 | //void EraseKeyFrame(KeyFrame* pKF);
91 |
92 | void AddCamera(GeometricCamera* pCam);
93 |
94 | /* All methods without Map pointer work on current map */
95 | void SetReferenceMapPoints(const std::vector &vpMPs);
96 | void InformNewBigChange();
97 | int GetLastBigChangeIdx();
98 |
99 | long unsigned int MapPointsInMap();
100 | long unsigned KeyFramesInMap();
101 |
102 | // Method for get data in current map
103 | std::vector GetAllKeyFrames();
104 | std::vector GetAllMapPoints();
105 | std::vector GetReferenceMapPoints();
106 |
107 | vector