openMVG--IncrementalSFM(原理及代码解读)

0、pre

  1. SFM综述—对应4种方法
  2. incrementalSFM bacic pipeline:Photo Tourism: Exploring Photo Collections in 3D(阅读笔记)
    在这里插入图片描述
  3. openMVG对应两个IncrementalSFM的实现

1、V1

1.1、算法简介

  1. 论文参考:Adaptive Structure from Motion with a contrario model estimation(阅读笔记
  2. 在这里插入图片描述

1.2、具体步骤及实现

1.2.1、选择initial

1.2.1.1. 由用户自己选择

输入initial pair(官方解释)

1.2.1.2. default:选择baseline较大的pair
  1. baseline衡量指标:同名光线夹角(采用不同同名点间形成的射线夹角 中值 )
  2. 计算同名光线夹角:
  • 计算原理

将image point坐标从像素坐标(相平面坐标)转为像空间坐标(利用内参矩阵K),再转为世界坐标(利用相机R\T) 将camera position坐标由像空间坐标转为世界坐标(利用相机R\T) 生成ray,并计算三维空间向量夹角(示意图如下)

重点:涉及坐标转换、空间坐标系的统一
在这里插入图片描述

  • 计算步骤:{pose I, poseJ} — E -----relative Pose—计算同名光线夹角
  • 代码实现:
// x = (u, v, 1.0)  // image coordinates
  // X = R.t() * K.inv() * x + C // Camera world point
  // getting the ray:
  // ray = X - C = R.t() * K.inv() * x
由函数AngleBetweenRay()实现

1.2.2、Initial pair选择后的操作

  1. E—relative pose
  • Ac-ransac
  1. BA
  • intrinsic constant
  • 初值:
    landmarks:(P = K\R\T)Triangulate --3d landmarks(outlier + inlier)
  1. save inlier 3d landmarks to sfm_data
    inlier判断条件:同名光线夹角、手性(landmark 位于相机前方)、重投影误差
    在这里插入图片描述

1.2.3、Add remain images

1.2.3.1、priciple

M+ 0.75M(s)

Select the image I that share the most of correspondences. Then keep all the images that have at least: 0.75correspondences(I) common correspondences to the reconstruction.

实质:得到resectionGroupIndex,按组(含多张image)添加view

1.2.3.2、代码实现
  1. 接口函数:
bool SequentialSfMReconstructionEngine::FindImagesWithPossibleResection(
  std::vector<uint32_t> & vec_possible_indexes)

1.2.4、Add remain images后的计算

1.2.4.1、resection
  1. 具体内容:
  • compute pose
    采用三角化计算pose(localization)时,需check三角化的结果是否满足精度要求
    在这里插入图片描述

  • refine added poses : intrinsics constant

  • tracks 处理:
    已计算的tracks:该view作为此track新的observation;
    未计算的tracks:在满足三角化计算条件的前提下,计算初值
    Ps: 三角化计算条件:
    该track的observation views包含已添加到scene中的view id

  1. 代码实现
  • 接口函数:
bool SequentialSfMReconstructionEngine::Resection(const uint32_t viewIndex)
  • 核心代码:
    在这里插入图片描述
    Ps:resection method (dafult): resection::SolverType::DLT_6POINTS
1.2.4.2、 BA–每组resectionGroupIndexBA一次

BA前提:有效pose数据达到一定阈值(default: 100)

在这里插入图片描述

1.2.4.3、Reject bad tracks-remove pose、landmarks、observation
  1. 针对sfm_data中的所有tracks
  2. remove pose\observation
    Remove observation和 pose的指示条件:
  • observation:与其对应view的pose未解算(未加入到sfm_data)

伴随的另一个remove操作--landmarks:min_points_per_landmark(landmark至少需要的观察点数目,不满足则remove the landmark)

  • pose: pose对应view所产生的observation数目// If usage count is smaller than the threshold, remove the Pose
  1. 接口函数:在这里插入图片描述

1.2.5、循环1.2.3-1.2.4

得到新的vec_possible_indexes并计算

1.2.6、Reject bad tracks

循环1.2.3-1.2.4操作,add resectionGroupIndex后: 再次执行Reject bad tracks

2、V2

2.1、算法简介

参考链接

2.2、具体步骤及实现

2.2.1、Init the reconstruction with a seed

2.2.1.1、Seed选择的方法

在这里插入图片描述
default:
std::string sSfMInitializer_method = "STELLAR";
在这里插入图片描述

2.2.1.2、 STELLAR(default)的具体实现
  1. 接口函数:bool SfMSceneInitializerStellar::Process()
  2. 核心函数(使用两次):
find_largest_stellar_configuration(
        relative_pose_pairs,
        matches_provider_,
        selected_stellar_pod)
  • largest: the StellarPod has the most matches
  • stellar configuration :using StellarPods = Hash_Map<IndexT, Pair_Set>;
    //{index:view id, pair set:与该view相关的pair}
  1. 对largest _stellar_configuration(StellarPod)的进一步计算–是否solvable
  • 针对每一个2 nodes edge,是否可以构建理想的tiny scene
  • 融合每个edge三角化结果,得到尺度统一的tiny scene
    重点:relative scale计算:

1)Relative scale计算原理 ----采用所有common track计算得到的depth ration序列的中值 Median进行计算

2)depth ratio计算原理:
根据StellarPod 内部的2 edges(与common nodes相关),对应的两视图,进行三角化,计算common track在该局部坐标系(以center pose 为原点的相机坐标系,不同pair尺度不同)下的深度(深度的表示方式-Vector: center pose –common track )
对于该vector,其在在不同尺度坐标系下,不同长度,可根据比值计算坐标系的尺度ratio,即depth ratio,并进一步得到尺度统一的三角化结果

3)depth ratio代码实现
在这里插入图片描述

核心函数:见下,得到track 在局部空间坐标系下的三维坐标

bool TriangulateNViewAlgebraic
(
  const Mat3X & points,
  const std::vector<Mat34> &poses,
  Vec4 *X
)

4)//some 2-uplet cannot lead to a relative scale if they don’t share a sufficient track amount
原因:
// If there is insufficient 3-view track count,
// We reject this triplet, since the relative scale factor cannot be reliably computed.
代码:
if (tracksBuilder.NbTracks() < 15) { return false; }

4)进一步基于depth ration(scale) 调整StellarPod内部,使其统一(以center pose 为原点的统一三维空间相机坐标系)

/// Solve the relative scale to a common coordinate system
/// Since ratios of depth are used, the found solution is an approximation
/// Solving equation (4) from “Global Structure-from-Motion by Similarity Averaging"
/// Zhaopeng Cui and Ping Tan. (ICCV 2015).”
论文对应函数:Inline bool Solve_stellar_translation_scales_averaging()

核心: Tj = Rij * Ti + scale* t_ij

2.2.2、 localize some cameras in the reconstruction

2.2.2.1、Add pose -Triangulation
// Incrementally estimate the pose of the cameras based on a confidence score.
  // The confidence score is based on the track_inlier_ratio.
  // First the camera with the most of 2D-3D overlap are added then we add
  // ones with lower confidence.

Add pose的具体细节:

根据track_inlier_ratios = {0.2, 0.0} 设定的两个批次的阈值,在每个阈值下,循环添加满足条件的pose group,一个group BA一次,并保存ply结果,并检查是否则进入下一个阈值批次

进入下一个阈值批次的条件:

  • 满足条件的pose group不为空
  • resection后pose的计算结果 满足精度要求
  • location后的操作后,有效pose数目较先前增加:
    代码实现:
    // Stop if no cameras have been added
    // Note: some cameras could have been removed due to instable camera positions.(见2.2.2.2)
    const IndexT pose_after = sfm_data_.GetPoses().size(); if (pose_before >= pose_after) break;
2.2.2.2、Bundle Adjustment and cleaning

相关操作:
在这里插入图片描述

2.2.3、Final bundle Adjustment

  • 2
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
OpenMVG(多视图几何库)和OpenMVS(多视图表面重建库)是一对用于三维重建的开源工具库。 OpenMVG的三维重建原理是基于多视图几何的算法。它首先通过结构从运动(SfM)算法计算相机的位姿和三维特征点在多个图像中的位置。这个过程可以通过解决一系列视觉几何方程来实现,例如基础矩阵估计和光束法平差。然后,OpenMVG使用三角化算法将这些特征点转换成三维点云。最后,通过利用全局最优化技术,OpenMVG进行了相机内外参数的联合优化,从而进一步提高了三维重建的质量。 而OpenMVS的三维重建原理则是基于稠密点云的重建。它接受OpenMVG的输出结果,即相机的位姿和三维点云,然后使用逐像素的基于多视图的三角化算法,将这些稀疏点云转换为稠密点云。在这个过程中,OpenMVS还利用了光度一致性和相机位姿约束来提高点云的重建质量。接下来,OpenMVS使用基于代价体积的方法对稠密点云进行三角网格化,以生成具有几何形状的三维模型。最后,OpenMVS通过进行网格细化和纹理映射,进一步优化和完善三维模型的外观和细节。 总的来说,OpenMVG和OpenMVS组合使用,可以实现从多张图像到稠密三维模型的完整三维重建流程。OpenMVG通过基于多视图几何的算法,实现从图像到稀疏点云的转换;而OpenMVS则通过逐像素的三角化和基于代价体积的方法,将稀疏点云转换为稠密点云,并最终生成具有几何形状和纹理的三维模型。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值