33 #include <orb_slam/Converter.h>
48 const std::vector<cv::KeyPoint>& vKeysUn,
49 const cv::Mat& descriptors,
53 const std::vector<float>& vScaleFactors,
54 const std::vector<float>& vLevelSigma2,
55 const std::vector<float>& vInvLevelSigma2,
66 mfGridElementWidthInv(static_cast<float>(
FRAME_GRID_COLS) / (nMaxX - nMinX)),
67 mfGridElementHeightInv(static_cast<float>(
FRAME_GRID_ROWS) / (nMaxY - nMinY)),
81 mDescriptors(descriptors.clone()),
82 mnScaleLevels(nScaleLevels),
83 mfScaleFactor(fScaleFactor),
84 mfLogScaleFactor(
log(fScaleFactor)),
85 mvScaleFactors(vScaleFactors),
86 mvLevelSigma2(vLevelSigma2),
87 mvInvLevelSigma2(vInvLevelSigma2),
93 mbFirstConnection(true),
123 mTimeStamp(F.mTimeStamp),
126 mfGridElementWidthInv(F.mfGridElementWidthInv),
127 mfGridElementHeightInv(F.mfGridElementHeightInv),
140 mvKeysUn(F.mvKeysUn),
141 mDescriptors(F.mDescriptors.clone()),
143 mFeatVec(F.mFeatVec),
144 mnScaleLevels(F.mnScaleLevels),
145 mfScaleFactor(F.mfScaleFactor),
146 mfLogScaleFactor(F.mfLogScaleFactor),
147 mvScaleFactors(F.mvScaleFactors),
148 mvLevelSigma2(F.mvLevelSigma2),
149 mvInvLevelSigma2(F.mvInvLevelSigma2),
150 mnMinX((int)F.mnMinX),
151 mnMinY((int)F.mnMinY),
152 mnMaxX((int)F.mnMaxX),
153 mnMaxY((int)F.mnMaxY),
155 mvpMapPoints(F.mvpMapPoints),
156 mbFirstConnection(true),
185 if (retainImg && !F.
imgGray.empty())
222 cv::Mat Rcw =
_Tcw.rowRange(0, 3).colRange(0, 3);
223 cv::Mat tcw =
_Tcw.rowRange(0, 3).col(3);
224 cv::Mat Rwc = Rcw.t();
227 _Twc = cv::Mat::eye(4, 4, Tcw.type());
228 Rwc.copyTo(
_Twc.rowRange(0, 3).colRange(0, 3));
229 Ow.copyTo(
_Twc.rowRange(0, 3).col(3));
256 return _Tcw.rowRange(0, 3).colRange(0, 3).clone();
262 return _Tcw.rowRange(0, 3).col(3).clone();
283 vector<pair<int, WAIKeyFrame*>> vPairs;
286 vPairs.push_back(make_pair(mit->second, mit->first));
288 sort(vPairs.begin(), vPairs.end());
289 list<WAIKeyFrame*> lKFs;
291 for (
size_t i = 0, iend = vPairs.size(); i < iend; i++)
293 lKFs.push_front(vPairs[i].second);
294 lWs.push_front(vPairs[i].first);
306 s.insert(mit->first);
330 return vector<WAIKeyFrame*>();
334 return vector<WAIKeyFrame*>();
387 for (
size_t i = 0, iend =
mvpMapPoints.size(); i < iend; i++)
403 const bool bCheckObs = minObs > 0;
404 for (
int i = 0; i <
N; i++)
441 map<WAIKeyFrame*, int> KFcounter;
443 vector<WAIMapPoint*> vpMP;
452 for (vector<WAIMapPoint*>::iterator vit = vpMP.begin(), vend = vpMP.end(); vit != vend; vit++)
464 for (map<WAIKeyFrame*, size_t>::iterator mit = observations.begin(), mend = observations.end(); mit != mend; mit++)
466 if (mit->first->mnId ==
mnId)
468 KFcounter[mit->first]++;
478 if (KFcounter.empty())
487 vector<pair<int, WAIKeyFrame*>> vPairs;
488 vPairs.reserve(KFcounter.size());
489 for (map<WAIKeyFrame*, int>::iterator mit = KFcounter.begin(), mend = KFcounter.end(); mit != mend; mit++)
491 if (mit->second > nmax)
496 if (mit->second >= th)
498 vPairs.push_back(make_pair(mit->second, mit->first));
505 vPairs.push_back(make_pair(nmax, pKFmax));
509 sort(vPairs.begin(), vPairs.end());
510 list<WAIKeyFrame*> lKFs;
512 for (
size_t i = 0; i < vPairs.size(); i++)
514 lKFs.push_front(vPairs[i].second);
515 lWs.push_front(vPairs[i].first);
528 if (buildSpanningTree)
630 mit->first->EraseConnection(
this);
652 set<WAIKeyFrame*> sParentCandidates;
659 bool bContinue =
false;
676 for (
size_t i = 0, iend = vpConnected.size(); i < iend; i++)
678 if (vpConnected[i]->
mnId == this->
mnId || vpConnected[i]->
isBad()) {
continue; }
680 for (set<WAIKeyFrame*>::iterator spcit = sParentCandidates.begin(), spcend = sParentCandidates.end(); spcit != spcend; spcit++)
682 if (vpConnected[i]->
mnId == (*spcit)->mnId)
702 sParentCandidates.insert(pC);
736 return (*it)->findChildRecursive(kf);
740 std::cout <<
"findChildRecursive found among children of id: " << (*it)->mnId << std::endl;
756 bool bUpdate =
false;
772 vector<size_t> vIndices;
791 for (
int ix = nMinCellX; ix <= nMaxCellX; ix++)
793 for (
int iy = nMinCellY; iy <= nMaxCellY; iy++)
795 const vector<size_t> vCell =
mGrid[ix][iy];
796 for (
size_t j = 0, jend = vCell.size(); j < jend; j++)
798 const cv::KeyPoint& kpUn =
mvKeysUn[vCell[j]];
799 const float distx = kpUn.pt.x - x;
800 const float disty = kpUn.pt.y - y;
802 if (fabs(distx) < r && fabs(disty) < r)
803 vIndices.push_back(vCell[j]);
819 vector<WAIMapPoint*> vpMapPoints;
828 vector<float> vDepths;
830 cv::Mat Rcw2 = Tcw_.row(2).colRange(0, 3);
832 float zcw = Tcw_.at<
float>(2, 3);
833 for (
int i = 0; i <
N; i++)
839 float z = (float)Rcw2.dot(x3Dw) + zcw;
840 vDepths.push_back(z);
844 sort(vDepths.begin(), vDepths.end());
846 return vDepths[(vDepths.size() - 1) / q];
851 cv::Mat result =
_Twc.clone();
864 mGrid[i][j].reserve(nReserve);
866 for (
int i = 0; i <
N; i++)
868 const cv::KeyPoint& kp =
mvKeysUn[i];
870 int nGridPosX, nGridPosY;
872 mGrid[nGridPosX][nGridPosY].push_back(i);
892 if (mat.isContinuous())
893 size = mat.total() * mat.elemSize();
896 size = mat.step[0] * mat.rows;
906 size +=
sizeof(*this);
#define PROFILE_SCOPE(name)
The SLScene class represents the top level instance holding the scene structure.
std::vector< std::size_t > mGrid[64][36]
WAIKeyFrame(const cv::Mat &Tcw, unsigned long id, bool fixKF, float fx, float fy, float cx, float cy, size_t N, const std::vector< cv::KeyPoint > &vKeysUn, const cv::Mat &descriptors, WAIOrbVocabulary *vocabulary, int nScaleLevels, float fScaleFactor, const std::vector< float > &vScaleFactors, const std::vector< float > &vLevelSigma2, const std::vector< float > &vInvLevelSigma2, int nMinX, int nMinY, int nMaxX, int nMaxY, const cv::Mat &KB)
keyframe generation during map loading
std::vector< int > mvOrderedWeights
void SetBowVector(WAIBowVector &bow)
float ComputeSceneMedianDepth(const int q)
void AddLoopEdge(WAIKeyFrame *pKF)
std::mutex mMutexConnections
bool hasChild(WAIKeyFrame *pKF)
void SetPose(const cv::Mat &Tcw)
cv::Mat GetCameraCenter()
std::vector< WAIKeyFrame * > GetCovisiblesByWeight(const int &w)
void AddChild(WAIKeyFrame *pKF)
std::vector< WAIKeyFrame * > GetBestCovisibilityKeyFrames(const int &N)
bool IsInImage(const float &x, const float &y) const
void AddMapPoint(WAIMapPoint *pMP, size_t idx)
const float mfGridElementHeightInv
std::vector< WAIMapPoint * > mvpMapPoints
void ChangeParent(WAIKeyFrame *pKF)
WAIMapPoint * GetMapPoint(const size_t &idx)
std::set< WAIKeyFrame * > mspLoopEdges
static bool weightComp(int a, int b)
bool findChildRecursive(WAIKeyFrame *kf)
std::set< WAIMapPoint * > GetMapPoints()
void EraseConnection(WAIKeyFrame *pKF)
std::map< WAIKeyFrame *, int > mConnectedKeyFrameWeights
WAIKeyFrame * GetParent()
void FindAndUpdateConnections(bool buildSpanningTree=true)
std::set< WAIKeyFrame * > GetLoopEdges()
bool PosInGrid(const cv::KeyPoint &kp, int &posX, int &posY)
this is a function from Frame, but we need it here for map loading
std::vector< std::size_t > mGrid[FRAME_GRID_COLS][FRAME_GRID_ROWS]
void AddConnection(WAIKeyFrame *pKF, int weight)
int TrackedMapPoints(const int &minObs)
std::set< WAIKeyFrame * > GetChilds()
void UpdateBestCovisibles()
const std::vector< cv::KeyPoint > mvKeysUn
const float mfGridElementWidthInv
std::vector< size_t > GetFeaturesInArea(const float &x, const float &y, const float &r) const
size_t getSizeOfCvMat(const cv::Mat &mat)
std::mutex mMutexFeatures
const std::map< WAIKeyFrame *, int > & GetConnectedKfWeights()
cv::Mat getObjectMatrix()
get visual representation as SLPoints
std::set< WAIKeyFrame * > GetConnectedKeyFrames()
void AssignFeaturesToGrid()
this is a function from Frame, but we need it here for map loading
void EraseChild(WAIKeyFrame *pKF)
std::vector< WAIKeyFrame * > mvpOrderedConnectedKeyFrames
long unsigned int mnMarker[7]
void UpdateConnections(std::map< WAIKeyFrame *, int > KFcounter, bool buildSpanningTree)
std::vector< WAIKeyFrame * > GetVectorCovisibleKeyFrames()
void EraseMapPointMatch(WAIMapPoint *pMP)
std::vector< WAIMapPoint * > GetMapPointMatches()
void ComputeBoW(WAIOrbVocabulary *vocabulary)
std::set< WAIKeyFrame * > mspChildrens
const cv::Mat mDescriptors
bool hasMapPoint(WAIMapPoint *mp)
static long unsigned int nNextId
int GetWeight(WAIKeyFrame *pKF)
void ReplaceMapPointMatch(const size_t &idx, WAIMapPoint *pMP)
std::map< WAIKeyFrame *, size_t > GetObservations()
int GetIndexInKeyFrame(WAIKeyFrame *pKF)
void transform(const cv::Mat &descriptors, WAIBowVector &bow, WAIFeatVector &feat)
void log(const char *tag, const char *format,...)
logs a formatted string platform independently