KeyFrameDatabase.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /**
  2. * This file is part of ORB-SLAM3
  3. *
  4. * Copyright (C) 2017-2021 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 <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef KEYFRAMEDATABASE_H
  19. #define KEYFRAMEDATABASE_H
  20. #include <vector>
  21. #include <list>
  22. #include <set>
  23. #include "KeyFrame.h"
  24. #include "Frame.h"
  25. #include "ORBVocabulary.h"
  26. #include "Map.h"
  27. #include <boost/serialization/base_object.hpp>
  28. #include <boost/serialization/vector.hpp>
  29. #include <boost/serialization/list.hpp>
  30. #include<mutex>
  31. namespace ORB_SLAM3
  32. {
  33. class KeyFrame;
  34. class Frame;
  35. class Map;
  36. class KeyFrameDatabase
  37. {
  38. friend class boost::serialization::access;
  39. template<class Archive>
  40. void serialize(Archive& ar, const unsigned int version)
  41. {
  42. ar & mvBackupInvertedFileId;
  43. }
  44. public:
  45. EIGEN_MAKE_ALIGNED_OPERATOR_NEW
  46. KeyFrameDatabase(){}
  47. KeyFrameDatabase(const ORBVocabulary &voc);
  48. void add(KeyFrame* pKF);
  49. void erase(KeyFrame* pKF);
  50. void clear();
  51. void clearMap(Map* pMap);
  52. // Loop Detection(DEPRECATED)
  53. std::vector<KeyFrame *> DetectLoopCandidates(KeyFrame* pKF, float minScore);
  54. // Loop and Merge Detection
  55. void DetectCandidates(KeyFrame* pKF, float minScore,vector<KeyFrame*>& vpLoopCand, vector<KeyFrame*>& vpMergeCand);
  56. void DetectBestCandidates(KeyFrame *pKF, vector<KeyFrame*> &vpLoopCand, vector<KeyFrame*> &vpMergeCand, int nMinWords);
  57. void DetectNBestCandidates(KeyFrame *pKF, vector<KeyFrame*> &vpLoopCand, vector<KeyFrame*> &vpMergeCand, int nNumCandidates);
  58. // Relocalization
  59. std::vector<KeyFrame*> DetectRelocalizationCandidates(Frame* F, Map* pMap);
  60. void PreSave();
  61. void PostLoad(map<long unsigned int, KeyFrame*> mpKFid);
  62. void SetORBVocabulary(ORBVocabulary* pORBVoc);
  63. protected:
  64. // Associated vocabulary
  65. const ORBVocabulary* mpVoc;
  66. // Inverted file
  67. std::vector<list<KeyFrame*> > mvInvertedFile;
  68. // For save relation without pointer, this is necessary for save/load function
  69. std::vector<list<long unsigned int> > mvBackupInvertedFileId;
  70. // Mutex
  71. std::mutex mMutex;
  72. };
  73. } //namespace ORB_SLAM
  74. #endif