AlejandroSilvestri / osmap

Save and load orb-slam2 maps
82 stars 17 forks source link

MapPoint will be erased if I load a map and switch to DeactivateLocalizationMode. #16

Closed JLDDER closed 3 years ago

JLDDER commented 3 years ago

Thanks for your share, osmap is very useful to me. However, I got a problem. When I loaded a map which saved by osmap, it works and tracking is successfully. Then, I wanna continue to scan and save in the same map file. Thus, I pushed Localization mode button on ORB-SLAM2 viewer then all mappoints be erased in LocalBundleAdjustment.

        // Check inlier observations
        for (size_t i = 0, iend = vpEdgesMono.size(); i < iend; i++)
        {
            g2o::EdgeSE3ProjectXYZ* e = vpEdgesMono[i];
            MapPoint* pMP = vpMapPointEdgeMono[i];

            if (pMP->isBad())
                continue;

            if (e->chi2() > 5.991 || !e->isDepthPositive())
            {
                KeyFrame* pKFi = vpEdgeKFMono[i];
                vToErase.push_back(make_pair(pKFi, pMP));
            }
        }
.
.
.
        if (!vToErase.empty())
        {
            for (size_t i = 0; i < vToErase.size(); i++)
            {
                KeyFrame* pKFi = vToErase[i].first;
                MapPoint* pMPi = vToErase[i].second;
                pKFi->EraseMapPointMatch(pMPi);
                pMPi->EraseObservation(pKFi);
            }
        }

e->chi2() would get a large value and pMPi->EraseObservation(pKFi) In EraseObservation, bBad would get true and call SetBadFlag. In SetBadFlag, mpMap->EraseMapPoint(this);

Is there anything that needs to add in the Options? If I want to load a map and would continue scan and save map again.

JLDDER commented 3 years ago

I found the solve of the problem. When loading a map, calibration parameters is not be setted in keyframes. That’s why "e->chi2()" would return a large value. Maybe I ignore some settings. Anyway, thanks again.