raulmur / ORB_SLAM2

Real-Time SLAM for Monocular, Stereo and RGB-D Cameras, with Loop Detection and Relocalization Capabilities
Other
9.47k stars 4.7k forks source link

How can I get the world positions of map points in System.cc? #1035

Open rakshith95 opened 2 years ago

rakshith95 commented 2 years ago

I want to save the Keyframes, poses, keypoints, and corresponding 3D map points positions from System.cc at the end of my mapping. I do the following:

    std::vector<KeyFrame*> vpKFs = mpMap->GetAllKeyFrames();
    sort(vpKFs.begin(),vpKFs.end(),KeyFrame::lId);

    std::cout<<"\n"<<vpKFs.size()<<"\n";
    // std::vector<MapPoint*> mps = mpMap->GetAllMapPoints();

    for(size_t i=0; i<vpKFs.size(); i++)
        {
        // long unsigned int kf_id = vpKFs[i]->mnId;

        std::vector<MapPoint*> threeD_mappoints = vpKFs[i]->GetMapPointMatches();

        const std::vector<cv::KeyPoint> twoD_keypoints = vpKFs[i]->mvKeysUn;

        for(size_t j=0; j<threeD_mappoints.size(); j++)
            cv::Mat worldPos = threeD_mappoints[j]->GetWorldPos();

However, the program crashes when it runs this part of the code; I assume this is due to some mutex locking, but I don't have any experience with it. Could someone tell me why this would cause a problem, or how to circumvent it?

thebirdgr commented 1 year ago

in rosrgbd.cc i get World to camera pose from `cv::Mat T, R, t ;`

T_ = mpSLAM->TrackRGBD(cv_ptrRGB->image,cv_ptrD->image,cv_ptrRGB->header.stamp.toSec());