SVO - Feature alignment
主要计算集中在 Reprojector
中。
// map reprojection & feature alignment
SVO_START_TIMER("reproject");
reprojector_.reprojectMap(new_frame_, overlap_kfs_);
SVO_STOP_TIMER("reproject");
Reprojector::reprojectMap()
map_.getCloseKeyframes(frame, close_kfs);
[kf_loop]
frame->isVisible();
[kf_loop]
[fts_loop]
reprojectPoint(frame, (*it_ftr)->point);
frame->cam_->isInFrame(px.cast<int>(), 8)
---
[cell_loop]
reprojectCell(*grid_.cells.at(grid_.cell_order[i]), frame);
Map Reprojection
将
map
中的 3D 点投影到图片中,并找到对应的feature
。
每个grid
一个 3D 点。既保证均匀分布,又减小计算量。
// 通过 isVisible() 判断 map 点是否在视野内;找到与当前帧视场重叠的关键帧;
map_.getCloseKeyframes(frame, close_kfs);
//close_kfs < 关键帧,与 cur 距离>
// sort(); 按照 当前帧 与 关键帧 的**位移**,对找到的 关键帧 排序;
for(; options_.max_n_kfs ;){
//将 close_kfs 中前 max_n_kfs 个关键帧取出;
overlap_kfs.push_back(pair<FramePtr,size_t>(ref_frame,0));
...
//重投影到像素坐标系,判断其是否 isInFrame();
reprojectPoint(frame, (*it_ftr)->point)
}
// reproject candidates 略
Feature Align
reprojectPoint()
中,为cell
和pt
建立指针链接;
SVO_START_TIMER("feature_align");
for(size_t i=0; i<grid_.cells.size(); ++i)
{
if(reprojectCell(*grid_.cells.at(grid_.cell_order[i]), frame))
++n_matches_;
if(n_matches_ > (size_t) Config::maxFts())
break;
}
SVO_STOP_TIMER("feature_align");
reprojectCell();
found_match = matcher_.findMatchDirect(*it->pt, *frame, it->px);
//找到视角偏差最小的 kf, 返回对应的 &ftr; [closest observation angle]
pt.getCloseViewObs(cur_frame.pos(), ref_ftr_);
//判断 patch 是否在视野内;排除边缘点;
ref_ftr_->frame->cam_->isInFrame(像素坐标, halfpatch_size_+2, ref_ftr_->level)
// 计算放射矩阵
warp::getWarpMatrixAffine(...);
//找到 cur 与 ref 缩放比例一致的 level;
warp::getBestSearchLevel(A_cur_ref_, Config::nPyrLevels()-1);
//得到 ref 中平行四边形状的 patch 图像;
warp::warpAffine(...);
//双线性插值函数
vk::interpolateMat_8u(img_ref, px[0], px[1]);
feature_alignment::align2D();
Feature* new_feature = new Feature(frame.get(), it->px, matcher_.search_level_);
frame->addFeature(new_feature);
new_feature->point = it->pt;
warp::getWarpMatrixAffine();
将 ref
中特征点对应的 5x5
half_patch
经 T
转换到 cur
,通过 half_patch
上三点,计算 Affine
矩阵。
参考:https://blog.youkuaiyun.com/xbcreal/article/details/52549629
getBestSearchLevel()
找到 cur
与 ref
patch
缩放比例一致的 level
。
A=[cosθ−sinθsinθcosθ][s00s] A = \begin{bmatrix}cos\theta & -sin\theta\\ sin\theta & cos\theta \end{bmatrix} \begin{bmatrix}s & 0 \\ 0 & s \end{bmatrix} A=[cosθsinθ