vins-mono代码分析
vins-mono的关键帧选择策略
1 与前一帧的平均视差。如果跟踪特征的平均视差超过某个阈值,我们会将此图像视为关键帧。
2 另一个是跟踪质量。如果跟踪特征的数量低于一个阈值,我们把这一帧看做一个新的关键帧。
具体在bool FeatureManager::addFeatureCheckParallax()中实现。
bool FeatureManager::addFeatureCheckParallax(int frame_count, const map<int, vector<pair<int, Eigen::Matrix<double, 7, 1>>>> &image, double td) { ROS_DEBUG("input feature: %d", (int)image.size()); ROS_DEBUG("num of feature: %d", getFeatureCount()); double parallax_sum = 0; int parallax_num = 0; last_track_num = 0; for (auto &id_pts : image) { FeaturePerFrame f_per_fra(id_pts.second[0].second, td); int feature_id = id_pts.first; auto it = find_if(feature.begin(), feature.end(), [feature_id](const FeaturePerId &it) { return it.feature_id == feature_id; }); if (it == feature.end()) { feature.push_back(FeaturePerId(feature_id, frame_count)); feature.back().feature_per_frame.push_back(f_per_fra); } else if (it->feature_id == feature_id) { it->feature_per_frame.push_back(f_per_fra); last_track_num++; } } if (frame_count < 2 || last_track_num < 20) return true; for (auto &it_per_id : feature) { if (it_per_id.start_frame <= frame_count - 2 && it_per_id.start_frame + int(it_per_id.feature_per_frame.size()) - 1 >= frame_count - 1) { parallax_sum += compensatedParallax2(it_per_id, frame_count); parallax_num++; } } if (parallax_num == 0) { return true; } else { ROS_DEBUG("parallax_sum: %lf, parallax_num: %d", parallax_sum, parallax_num); ROS_DEBUG("current parallax: %lf", parallax_sum / parallax_num * FOCAL_LENGTH); return parallax_sum / parallax_num >= MIN_PARALLAX; } }
首先在feature_manager.cpp中定义了一个类FeaturePerFrame,
函数输入:
int frame_count,
const map<int, vector<pair<int, Eigen::Matrix<double, 7, 1>>>> &image,
double td
函数输出:
该帧是否为关键帧:ture or false