Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting the last n keyframes in real time #885

Open
IslamAAli opened this issue Apr 23, 2024 · 0 comments
Open

Getting the last n keyframes in real time #885

IslamAAli opened this issue Apr 23, 2024 · 0 comments

Comments

@IslamAAli
Copy link

Hello,

I am running ORB-SLAM3 in mono-inertial mode on EuroC dataset. For each frame processed, I want to get the last 20 keyframes.

What I do is that, I get the active map from Atlas and then extract the keyframes in that active map. The problem is that when I do this, I get only a few keyframes compared to the total number of keyframes shown in the visualization window. For example, usually, it is only 2 keyframes up to 9 or so.

The following is the code I use in a function that is called inside the euroc mono_inertial main

allPoses.clear();

// current pose info
vector<double> curr_pose;
curr_pose.reserve(8);

// get the active map (current map, since we are working in real time)
Map* pActiveMap = mpAtlas->GetCurrentMap();

if (pActiveMap == NULL)
{
    cout << "TEST: active map is null" << endl;
}

// get all keyframes and sort them using their ID
vector<KeyFrame*> vpKFs = pActiveMap->GetAllKeyFrames();
sort(vpKFs.begin(),vpKFs.end(),KeyFrame::lId);

// Transform all keyframes so that the first keyframe is at the origin.
// After a loop closure the first keyframe might not be at the origin.
for(size_t i=0; i<vpKFs.size(); i++)
{
    curr_pose.clear();
    curr_pose.reserve(8);

    KeyFrame* pKF = vpKFs[i];

    // if keyframe is culled , go to the next one
    if(!pKF || pKF->isBad())
        continue;

    // else, get info of the current transform of the pose
    Sophus::SE3f T_base;
    Eigen::Quaternionf q;
    Eigen::Vector3f t;

    if (mSensor == IMU_MONOCULAR || mSensor == IMU_STEREO || mSensor==IMU_RGBD)
    {
        T_base = pKF->GetImuPose();   
    }
    else
    {
        T_base = pKF->GetPoseInverse();
    }
    q = T_base.unit_quaternion();
    t = T_base.translation();

    std::vector<double> currPose;

    // push all pose transform data to vector
    currPose.push_back(1e9*pKF->mTimeStamp);
    currPose.push_back(t(0));
    currPose.push_back(t(1));
    currPose.push_back(t(2));
    currPose.push_back(q.x());
    currPose.push_back(q.y());
    currPose.push_back(q.z());
    currPose.push_back(q.w());

    // submit this pose to poses repository
    allPoses.push_back(currPose);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant