felixchenfy / Monocular-Visual-Odometry

A simple monocular visual odometry (part of vSLAM) by ORB keypoints with initialization, tracking, local map and bundle adjustment. (WARNING: Hi, I'm sorry that this project is tuned for course demo, not for real world applications !!!)
MIT License
398 stars 91 forks source link

Bundle adjustment bug #5

Closed fredO13 closed 5 years ago

fredO13 commented 5 years ago

Hey,

I think there's a bug in void VisualOdometry::callBundleAdjustment()

You're looping on the last 5 frames and there's a continue if the frame has less than 3 points in the map. Right below the continue are two _pushback on _v_pts_2d_ and _v_pts_to3d that are not done when continue happen, but the index is still _ithframe which may not exist in case continue was called before.

You may want to select the appropriate frames (the last 5 frames with enough points in the map) before calling the existing code, removing the continue.

ouyangandy commented 5 years ago

So how do you feel about fixing it? I am confused about what you said.

felixchenfy commented 5 years ago

@fredO13 Hi, really appreciate it for reading my code so carefully and pointing out the bugs.

I've changed:


            v_pts_2d[ith_frame].push_back(&(frame->keypoints_[kpt_idx].pt));
            v_pts_2d_to_3d_idx[ith_frame].push_back(mappt_idx);

To:

            v_pts_2d.back().push_back(&(frame->keypoints_[kpt_idx].pt));
            v_pts_2d_to_3d_idx.back().push_back(mappt_idx);

@ouyangandy