ORB-SLAM2 Study 3 MapPoint.h Map.h KeyFrame.h

Source: Internet
Author: User
Tags map class

1.mappoint.h

There is a class MapPoint, which has two constructors. For each, the reference frame is the case where keyframes and parameters are normal frames.

   1 MapPoint (const Cv::mat &pos, keyframe* prefkf, map* pMap);     MapPoint (const cv::mat &pos,  constint &idxf);

[Email protected] Pos, which refers to the 3D position of the point. 2 @pRefKF, refer to keyframes. 3 @ PMAP, map point. 4 @ pframe normal frame.
5 @idxF The numbered index of the map point inside the normal frame.

When the reference frame is a keyframe, inside the constructor is simply the 3D coordinate of the map point. Set the number of this map to initialize the mnormalvector. When passed to normal frame, set the 3D coordinates of this point, Mnormalvector Initialize, and set the descriptor of this map point.

2    // set 3-dimensional coordinates for this point in space    void setworldpos (const Cv::mat &Pos);    Cv::mat Getworldpos ();        // gets the normalized value of the vector at the center of the camera to that point.      Cv::mat getnormal ();    Keyframe* getreferencekeyframe ();     // get all the keyframes that can see this point, and the number    of points in this keyframe Std::map<keyframe*,size_t> getobservations ();         // returns the number of times the point has been observed.     int observations ();

All of these functions return common variables.

3  // the input is the key frame to see this point, and the number of the point in the keyframe, the function increases the value of observation.     void addobservation (keyframe* pkf,size_t idx);     // Delete observations inside, corresponding to the PKF    void Eraseobservation (keyframe* PKF);

Both functions change mobservations, Std::map<keyframe*,size_t> mobservations, and first indicates which Keyframe is observed, Second indicates how much the map point is numbered in this keyframe.

 4  //the input is the key frame to see this point, and the number of the point in the keyframe, the function increases the value of observation.     voidAddobservation (keyframe*pkf,size_t idx); //Delete observations inside, corresponding to the PKF    voidEraseobservation (keyframe*PKF); //get the number of the map point inside the given keyframe    intGetindexinkeyframe (keyframe*PKF); //the point is not inside this keyframe    BOOLIsinkeyframe (keyframe*PKF); //this point is not good, we want to delete that point in all keyframes. This point in the map also needs to be deleted.     voidSetbadflag (); BOOLIsbad (); //the map point inside the replacement keyframe is PMP;    voidReplace (mappoint*PMP); MapPoint*getreplaced (); voidIncreasevisible (intn=1); voidIncreasefound (intn=1);

These functions are simple to implement, look at the source code, here the Setbadflag function, is to tell the bad point from these can see this point in the key frame delete. The void Replace (mappoint* PMP) function converts all the points in the frame that you see pity Dorado to a PMP point.

   void Computedistinctivedescriptors ();

Calculate the best descriptors and change the common variable mdescriptor .

Implementation: Find out all the key points in this key frame to see the description of this key point, put into a container vdescriptors inside. It then calculates the distance between the vdescriptors of the different lines, and the result is placed inside the distances.

Then, each line of distances is ordered from small to large to find the median value of each row median. All Meadian are the least Bestmedian, and the index of the row is recorded as the best index bestidx=i; and then we get the best description we're looking for.

6  void updatenormalanddepth ();

We can get in this function, the maximum, minimum scale invariant distance of this function, and a very important concept Mnormalvector: Refers to the average of all vectors that can see the reference frame of this point in the center of the camera to the map point.

7    float  getmindistanceinvariance ();      float Getmaxdistanceinvariance ();

Returns the global amount, nothing to say.

8     int predictscale (constfloat &currentdist, keyframe*PKF);     int Predictscale (constfloat &currentdist, frame* PF);

All two parameters are input, and the function returns the number of layers that appear in the frame (keyframe) pyramid for that map point.

2 Map.h

There is a map class, mainly provide some functions to maintain the map, functions are very simple, self-view source code.

3.keyframdatabase.h

The main function of class keyframedatabase is to save the key frame, which is useful for the closed loop detection and relocation. There is a std::vector<list<keyframe*> > Mvinvertedfile; so-called reverse index, each leaf node is a "word", Every word has a reverse index inside this database, there are all the keyframes for this "word".

  1 keyframedatabase (const orbvocabulary &VOC);    void Add (keyframe* pKF);    void Erase (keyframe* PKF);    void Clear ();

Constructors, Add,erase,clear, are relatively simple. Note that when we join the deletion of keyframes, it is all done on the reverse index!!! mvinvertedfile.

2  //  Loop Detection   float  minscore);    // relocalization   Std::vector<keyframe*> detectrelocalizationcandidates (frame* F);

The two function implementations are almost identical, all of which are found in the database that are most similar to the given frames (keyframes).

Main implementations:

Step one: Find all the keyframes in the same word as the current database, and count the number of words in the same word, which is the score of no frames. Select the maximum score and customize the minimum score. Keep those keyframes that exceed the minimum points and match the score and keyframes to the Lscoreandmatch.push_back (Make_pair (SI,PKFI)); ...... I myself think the original code here has a bug ... I do not know which great God can explain.

Step two: Find the maximum number of 10 frames per keyframe in the L Scoreandmatch, and form a group. Get the cumulative score of each group in the groups, respectively, and The frame with the highest score is placed in the Laccscoreandmatch. Find the maximum values for these cumulative scores, and customize the minimum values. O.75*bestaccscore .... Only the Accscore inside the laccacoreandmactch exceeds the minimum value of this definition, and the frame PBESTKF is loaded into vploopcandidates as a candidate closed-loop frame.

Explanation of the problem:

/here to check the candidates for the closed loop. There are a lot of ideas, the paper is not written out, here we can read it out. Vector<KeyFrame*> keyframedatabase::D etectloopcandidates (keyframe* PKF,floatMinscore) {    Set<KeyFrame*> spconnectedkeyframes = pkf->Getconnectedkeyframes (); List<KeyFrame*> lkfssharingwords;//A collection of keyframes that have a common word with the key frame//Search All keyframes this share a word with the current keyframes//the place where the closed loop exists is that the frames with the current frame have common word//Discard keyframes connected to the query Keyframe//with the current frame there is a common view, we will not choose this, too close ... Closed-loop use is not particularly large. {Unique_lock<mutex>Lock(Mmutex);  for(Dbow2::bowvector::const_iterator vit=pkf->mbowvec.begin (), Vend=pkf->mbowvec.end (); Vit! = Vend; vit++) {List<KeyFrame*> &AMP;LKFS = mvinvertedfile[vit->first];//Each word, list is loaded with a key frame with word in common             for(List<keyframe*>::iterator lit=lkfs.begin (), lend= lkfs.end (); lit!=lend; lit++)            {          //tell a key frame to take out. keyframe* pkfi=*lit; if(pkfi->mnloopquery!=pkf->Mnid) {PKFI->mnloopwords=0;//The number of Word with the keyframe that is common to the current keyframe. //What's wrong with the judgment here??? So we can't detect the closed loop, it's a closed loop. There must be a common vision.!!!!!!!                     if(!Spconnectedkeyframes.count (PKFI)) {PKFI->mnloopquery=pkf->Mnid;                    Lkfssharingwords.push_back (PKFI); }} PKFI->mnloopwords++; }        }    }    if(Lkfssharingwords.empty ())returnVector<keyframe*>(); List<pair<float,keyframe*> >Lscoreandmatch; //Only compare against those keyframes that share enough words    intmaxcommonwords=0; //Find out the maximum number of Word with the current frame.          for(List<keyframe*>::iterator lit=lkfssharingwords.begin (), lend= lkfssharingwords.end (); lit!=lend; lit++)    {        if((*lit)->mnloopwords>maxcommonwords) Maxcommonwords= (*lit)mnloopwords; }    intMincommonwords = maxcommonwords*0.8f; intnscores=0; //Compute similarity score. Retain the matches whose score is higher than Minscore     for(List<keyframe*>::iterator lit=lkfssharingwords.begin (), lend= lkfssharingwords.end (); lit!=lend; lit++) {Keyframe* PKFI = *lit; if(pkfi->mnloopwords>mincommonwords) {Nscores++; floatSi = Mpvoc->score (Pkf->mbowvec,pkfi->mbowvec);//score for current keyframes and PKFIPKFI->mloopscore = si;//score. //score, and the corresponding keyframes are put into this.             if(si>=minscore) Lscoreandmatch.push_back (Make_pair (SI,PKFI)); }    }    if(Lscoreandmatch.empty ())returnVector<keyframe*>(); List<pair<float,keyframe*> >Laccscoreandmatch; floatBestaccscore =Minscore; //Lets now accumulate score by covisibility     for(list<pair<float,keyframe*> >::iterator It=lscoreandmatch.begin (), Itend=lscoreandmatch.end (); It!=itend; it++) {Keyframe* PKFI = it->second; //a group of keyframes and then even the cumulative score//get the 10 keyframes that have the most common view with this keyframe. vector<keyframe*> vpneighs = Pkfi->getbestcovisibilitykeyframes (Ten); floatBestscore = it->First ; floatAccscore = it->first;//Cumulative Score///the best key frame. keyframe* PBESTKF =PKFI;  for(Vector<keyframe*>::iterator vit=vpneighs.begin (), Vend=vpneighs.end (); vit!=vend; vit++) {Keyframe* pKF2 = *Vit; if(Pkf2->mnloopquery==pkf->mnid && pkf2->mnloopwords>mincommonwords) {Accscore+=pkf2->mloopscore;//cumulative score.                 if(pkf2->mloopscore>Bestscore) {PBESTKF=PKF2;//The best key frame has changed, and the Common View Group (10) has the highest score. Bestscore = pkf2->Mloopscore; }            }        }        //get the highest score in the consensus group (10). (cumulative score, best frame)Laccscoreandmatch.push_back (Make_pair (ACCSCORE,PBESTKF)); if(accscore>bestaccscore) Bestaccscore=Accscore; }    //Return All those keyframes with a score higher than 0.75*bestscore    floatMinscoretoretain =0.75f*Bestaccscore; Set<KeyFrame*>SPALREADYADDEDKF; Vector<KeyFrame*>vploopcandidates;    Vploopcandidates.reserve (Laccscoreandmatch.size ());  for(list<pair<float,keyframe*> >::iterator It=laccscoreandmatch.begin (), Itend=laccscoreandmatch.end (); It!=itend; it++)    {        if(it->first>Minscoretoretain) {Keyframe* PKFI = it->second; if(!Spalreadyaddedkf.count (PKFI)) {          //is there any extra feeling?Vploopcandidates.push_back (PKFI);            Spalreadyaddedkf.insert (PKFI); }        }    }//Here's the idea of a haircut. 1, find the key frame that has a common word with the current frame, take a felling value, must be more than the number of//together Word can be selected. 2, find out all the keyframes identified with 1, have up to 10 frames with the most common viewpoints, form a group,//then calculate the cumulative score, where you can find the key frame that makes the Bestscore the largest in the group, and change the keyframe to be the one with the same word keyframe//There are a lot of common-view keyframes. 3. Find the most important reference keyframes for the cumulative score. (There may be the same word keyframe, or there are many common-view keyframes)    returnvploopcandidates;}

ORB-SLAM2 Study 3 MapPoint.h Map.h KeyFrame.h

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.