123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389 |
- #ifndef KEYFRAME_H
- #define KEYFRAME_H
- #include "MapPoint.h"
- #include "Thirdparty/DBoW2/DBoW2/BowVector.h"
- #include "Thirdparty/DBoW2/DBoW2/FeatureVector.h"
- #include "ORBVocabulary.h"
- #include "ORBextractor.h"
- #include "Frame.h"
- #include "KeyFrameDatabase.h"
- #include "ImuTypes.h"
- #include "GeometricCamera.h"
- #include <mutex>
- #include <boost/serialization/base_object.hpp>
- #include <boost/serialization/vector.hpp>
- #include <boost/serialization/map.hpp>
- namespace ORB_SLAM3
- {
- class Map;
- class MapPoint;
- class Frame;
- class KeyFrameDatabase;
- class GeometricCamera;
- class KeyFrame
- {
- public:
- KeyFrame();
- KeyFrame(Frame &F, Map* pMap, KeyFrameDatabase* pKFDB);
-
- void SetPose(const cv::Mat &Tcw);
- void SetVelocity(const cv::Mat &Vw_);
- cv::Mat GetPose();
- cv::Mat GetPoseInverse();
- cv::Mat GetCameraCenter();
- cv::Mat GetImuPosition();
- cv::Mat GetImuRotation();
- cv::Mat GetImuPose();
- cv::Mat GetStereoCenter();
- cv::Mat GetRotation();
- cv::Mat GetTranslation();
- cv::Mat GetVelocity();
- cv::Matx33f GetRotation_();
- cv::Matx31f GetTranslation_();
- cv::Matx31f GetCameraCenter_();
- cv::Matx33f GetRightRotation_();
- cv::Matx31f GetRightTranslation_();
- cv::Matx44f GetRightPose_();
- cv::Matx31f GetRightCameraCenter_();
- cv::Matx44f GetPose_();
-
- void ComputeBoW();
-
- void AddConnection(KeyFrame* pKF, const int &weight);
- void EraseConnection(KeyFrame* pKF);
- void UpdateConnections(bool upParent=true);
- void UpdateBestCovisibles();
- std::set<KeyFrame *> GetConnectedKeyFrames();
- std::vector<KeyFrame* > GetVectorCovisibleKeyFrames();
- std::vector<KeyFrame*> GetBestCovisibilityKeyFrames(const int &N);
- std::vector<KeyFrame*> GetCovisiblesByWeight(const int &w);
- int GetWeight(KeyFrame* pKF);
-
- void AddChild(KeyFrame* pKF);
- void EraseChild(KeyFrame* pKF);
- void ChangeParent(KeyFrame* pKF);
- std::set<KeyFrame*> GetChilds();
- KeyFrame* GetParent();
- bool hasChild(KeyFrame* pKF);
- void SetFirstConnection(bool bFirst);
-
- void AddLoopEdge(KeyFrame* pKF);
- std::set<KeyFrame*> GetLoopEdges();
-
- void AddMergeEdge(KeyFrame* pKF);
- set<KeyFrame*> GetMergeEdges();
-
- int GetNumberMPs();
- void AddMapPoint(MapPoint* pMP, const size_t &idx);
- void EraseMapPointMatch(const int &idx);
- void EraseMapPointMatch(MapPoint* pMP);
- void ReplaceMapPointMatch(const int &idx, MapPoint* pMP);
- std::set<MapPoint*> GetMapPoints();
- std::vector<MapPoint*> GetMapPointMatches();
- int TrackedMapPoints(const int &minObs);
- MapPoint* GetMapPoint(const size_t &idx);
-
- std::vector<size_t> GetFeaturesInArea(const float &x, const float &y, const float &r, const bool bRight = false) const;
- cv::Mat UnprojectStereo(int i);
- cv::Matx31f UnprojectStereo_(int i);
-
- bool IsInImage(const float &x, const float &y) const;
-
- void SetNotErase();
- void SetErase();
-
- void SetBadFlag();
- bool isBad();
-
- float ComputeSceneMedianDepth(const int q);
- static bool weightComp( int a, int b){
- return a>b;
- }
- static bool lId(KeyFrame* pKF1, KeyFrame* pKF2){
- return pKF1->mnId<pKF2->mnId;
- }
- Map* GetMap();
- void UpdateMap(Map* pMap);
- void SetNewBias(const IMU::Bias &b);
- cv::Mat GetGyroBias();
- cv::Mat GetAccBias();
- IMU::Bias GetImuBias();
- bool ProjectPointDistort(MapPoint* pMP, cv::Point2f &kp, float &u, float &v);
- bool ProjectPointUnDistort(MapPoint* pMP, cv::Point2f &kp, float &u, float &v);
- void SetORBVocabulary(ORBVocabulary* pORBVoc);
- void SetKeyFrameDatabase(KeyFrameDatabase* pKFDB);
- bool bImu;
-
- public:
- static long unsigned int nNextId;
- long unsigned int mnId;
- const long unsigned int mnFrameId;
- const double mTimeStamp;
-
- const int mnGridCols;
- const int mnGridRows;
- const float mfGridElementWidthInv;
- const float mfGridElementHeightInv;
-
- long unsigned int mnTrackReferenceForFrame;
- long unsigned int mnFuseTargetForKF;
-
- long unsigned int mnBALocalForKF;
- long unsigned int mnBAFixedForKF;
-
- long unsigned int mnNumberOfOpt;
-
- long unsigned int mnLoopQuery;
- int mnLoopWords;
- float mLoopScore;
- long unsigned int mnRelocQuery;
- int mnRelocWords;
- float mRelocScore;
- long unsigned int mnMergeQuery;
- int mnMergeWords;
- float mMergeScore;
- long unsigned int mnPlaceRecognitionQuery;
- int mnPlaceRecognitionWords;
- float mPlaceRecognitionScore;
- bool mbCurrentPlaceRecognition;
-
- cv::Mat mTcwGBA;
- cv::Mat mTcwBefGBA;
- cv::Mat mVwbGBA;
- cv::Mat mVwbBefGBA;
- IMU::Bias mBiasGBA;
- long unsigned int mnBAGlobalForKF;
-
- cv::Mat mTcwMerge;
- cv::Mat mTcwBefMerge;
- cv::Mat mTwcBefMerge;
- cv::Mat mVwbMerge;
- cv::Mat mVwbBefMerge;
- IMU::Bias mBiasMerge;
- long unsigned int mnMergeCorrectedForKF;
- long unsigned int mnMergeForKF;
- float mfScaleMerge;
- long unsigned int mnBALocalForMerge;
- float mfScale;
-
- const float fx, fy, cx, cy, invfx, invfy, mbf, mb, mThDepth;
- cv::Mat mDistCoef;
-
- const int N;
-
- const std::vector<cv::KeyPoint> mvKeys;
- const std::vector<cv::KeyPoint> mvKeysUn;
- const std::vector<float> mvuRight;
- const std::vector<float> mvDepth;
- const cv::Mat mDescriptors;
-
- DBoW2::BowVector mBowVec;
- DBoW2::FeatureVector mFeatVec;
-
- cv::Mat mTcp;
-
- const int mnScaleLevels;
- const float mfScaleFactor;
- const float mfLogScaleFactor;
- const std::vector<float> mvScaleFactors;
- const std::vector<float> mvLevelSigma2;
- const std::vector<float> mvInvLevelSigma2;
-
- const int mnMinX;
- const int mnMinY;
- const int mnMaxX;
- const int mnMaxY;
- const cv::Mat mK;
-
- KeyFrame* mPrevKF;
- KeyFrame* mNextKF;
- IMU::Preintegrated* mpImuPreintegrated;
- IMU::Calib mImuCalib;
- unsigned int mnOriginMapId;
- string mNameFile;
- int mnDataset;
- std::vector <KeyFrame*> mvpLoopCandKFs;
- std::vector <KeyFrame*> mvpMergeCandKFs;
- bool mbHasHessian;
- cv::Mat mHessianPose;
-
- protected:
-
- cv::Mat Tcw;
- cv::Mat Twc;
- cv::Mat Ow;
- cv::Mat Cw;
- cv::Matx44f Tcw_, Twc_, Tlr_;
- cv::Matx31f Ow_;
-
- cv::Mat Owb;
-
- cv::Mat Vw;
-
- IMU::Bias mImuBias;
-
- std::vector<MapPoint*> mvpMapPoints;
-
- KeyFrameDatabase* mpKeyFrameDB;
- ORBVocabulary* mpORBvocabulary;
-
- std::vector< std::vector <std::vector<size_t> > > mGrid;
- std::map<KeyFrame*,int> mConnectedKeyFrameWeights;
- std::vector<KeyFrame*> mvpOrderedConnectedKeyFrames;
- std::vector<int> mvOrderedWeights;
-
- bool mbFirstConnection;
- KeyFrame* mpParent;
- std::set<KeyFrame*> mspChildrens;
- std::set<KeyFrame*> mspLoopEdges;
- std::set<KeyFrame*> mspMergeEdges;
-
- bool mbNotErase;
- bool mbToBeErased;
- bool mbBad;
- float mHalfBaseline;
- Map* mpMap;
- std::mutex mMutexPose;
- std::mutex mMutexConnections;
- std::mutex mMutexFeatures;
- std::mutex mMutexMap;
- public:
- GeometricCamera* mpCamera, *mpCamera2;
-
- std::vector<int> mvLeftToRightMatch, mvRightToLeftMatch;
-
- cv::Mat mTlr;
- cv::Mat mTrl;
-
- const std::vector<cv::KeyPoint> mvKeysRight;
- const int NLeft, NRight;
- std::vector< std::vector <std::vector<size_t> > > mGridRight;
- cv::Mat GetRightPose();
- cv::Mat GetRightPoseInverse();
- cv::Mat GetRightPoseInverseH();
- cv::Mat GetRightCameraCenter();
- cv::Mat GetRightRotation();
- cv::Mat GetRightTranslation();
- cv::Mat imgLeft, imgRight;
- void PrintPointDistribution(){
- int left = 0, right = 0;
- int Nlim = (NLeft != -1) ? NLeft : N;
- for(int i = 0; i < N; i++){
- if(mvpMapPoints[i]){
- if(i < Nlim) left++;
- else right++;
- }
- }
- cout << "Point distribution in KeyFrame: left-> " << left << " --- right-> " << right << endl;
- }
- };
- }
- #endif
|