Cerea学习,包含示例代码

Ceres Learning

githut

0 参考资料

(1)Ceres Solver

(2)Ceres-Solver学习笔记(1)

(3)Ceres-Solver学习笔记(2)

(4)Ceres-Solver学习笔记(3)

(5)Ceres-Solver学习笔记(4)

(6)Ceres-Solver学习笔记(5)

(7)Ceres-Solver学习笔记(6)

(8)Ceres-Solver学习笔记(7)

(9)Ceres-Solver学习笔记(8)

(10)Ceres-Solver学习笔记(9)

1 练练手

1.1 非约束最优化问题

argminxf(x)=12(10x)2(1) (1) arg ⁡ min x f ( x ) = 1 2 ( 10 − x ) 2

步骤

​ (1)编写CostFunction结构体。必须重载运算符(),必须使用模板类型,所有输入参数和输出参数都使用模板类型。

​ (2)构造一个求解非线性最小二乘法的Problem来进行未知数求解。

1.2 曲线拟合

(1)魏尔斯特拉斯函数(Weierstrass function)

f(x)=n=0Nancos(bnπx)(2) (2) f ( x ) = ∑ n = 0 N a n c o s ( b n π x )

​ 其中 0<a<1 0 < a < 1 b b 为正奇数,且满足ab>1+32π

(2)Weierstrass图像绘制
Weierstrass图像

(3)步骤

​ (3.1)构造数据。设置参数 a=0.3,b=7,n=200 a = 0.3 , b = 7 , n = 200

​ (3.2)编写CostFunction结构体。

​ (3.3)构造一个求解非线性最小二乘法的Problem来进行未知数求解。

(4)总结

​ (4.1)利用ceres无法对非线性函数进行曲线拟合,如魏尔斯特拉斯函数。原因包括两点:函数无法进行微分求解和初始点难以选取。

​ (4.2)此处改为ceres对 y=eax2+b y = e a x 2 + b 函数进行曲线拟合,其中 a=0.3,b=0.1 a = 0.3 , b = 0.1 。该函数图如下所示:

Exp函数图

​ (4.3)可以采用三种方法对问题进行求解,即:在进行Problem构建时,采用AutoDiffCostFunction或NumericDiffCostFunction进行数值微分求解;当无法使用模板来创建costfunctor时,继承SizedCostFunction类来实现Problem。

1.3 单像空间后方交会问题

(1)共线方程

xx0=fa1(XXs)+b1(YYs)+c1(ZZs)a3(XXs)+b3(YYs)+c3(ZZs),yy0=fa2(XXs)+b2(YYs)+c2(ZZs)a3(XXs)+b3(YYs)+c3(ZZs)(3) (3) { x − x 0 = − f a 1 ( X − X s ) + b 1 ( Y − Y s ) + c 1 ( Z − Z s ) a 3 ( X − X s ) + b 3 ( Y − Y s ) + c 3 ( Z − Z s ) , y − y 0 = − f a 2 ( X − X s ) + b 2 ( Y − Y s ) + c 2 ( Z − Z s ) a 3 ( X − X s ) + b 3 ( Y − Y s ) + c 3 ( Z − Z s )

​ 其中 x0,y0,f x 0 , y 0 , f 已知, abc a b c 为旋转矩阵,可以利用 ϕ,ω,κ ϕ , ω , κ 表示如下:

a1=cosϕcosκsinϕsinωsinκ,a2=cosϕsinκsinϕsinωcosκ,a3=sinϕcosω,b1=cosωsinκ,b2=cosωcosκ,b3=sinω,c1=sinϕcosκ+cosϕsinωsinκ,c2=sinϕsinκ+cosϕsinωcosκ,c3=cosϕcosω(4) (4) { a 1 = c o s ϕ c o s κ − s i n ϕ s i n ω s i n κ , a 2 = − c o s ϕ s i n κ − s i n ϕ s i n ω c o s κ , a 3 = − s i n ϕ c o s ω , b 1 = c o s ω s i n κ , b 2 = c o s ω c o s κ , b 3 = − s i n ω , c 1 = s i n ϕ c o s κ + c o s ϕ s i n ω s i n κ , c 2 = − s i n ϕ s i n κ + c o s ϕ s i n ω c o s κ , c 3 = c o s ϕ c o s ω

(2)步骤

​ (2.1)读入数据,格式为 (x,y,X,Y,Z) ( x , y , X , Y , Z ) 。前2维像素坐标—单位 mm m m ,后三维代像坐标—单位 m m

​ (2.2)编写CostFunction结构体。

​ (2.3)构造一个求解非线性最小二乘法的Problem来进行未知数求解。

(3)运行结果

Photogrammetry

1.4 Powell’s Quartic Function

(1)数学表达式

(5)f(X)=(x1+10x2)2+5(x3x4)2+(x22x3)4+10(x1x4)4

​ 其中:

10xi10,i=1,2,3,4 ∙ − 10 ≤ x i ≤ 10 , i = 1 , 2 , 3 , 4

fmin(X)=0 ∙ f m i n ( X ∗ ) = 0

xi=0 ∙ x i ∗ = 0

(2)Powell’s Quartic Function分解

f1(x)f2(x)f3(x)f4(x)F(x)=x1+10x2=5(x3x4)=(x22x3)2=10(x1x4)2=[f1(x),f2(x),f3(x),f4(x)](6) (6) f 1 ( x ) = x 1 + 10 x 2 f 2 ( x ) = 5 ( x 3 − x 4 ) f 3 ( x ) = ( x 2 − 2 x 3 ) 2 f 4 ( x ) = 10 ( x 1 − x 4 ) 2 F ( x ) = [ f 1 ( x ) , f 2 ( x ) , f 3 ( x ) , f 4 ( x ) ]

(3)最优化问题数学描述

argminx12F(x)2(7) (7) arg ⁡ min x 1 2 ‖ F ( x ) ‖ 2

(4)步骤

​ (4.1)编写CostFunction结构体。

​ (4.2)构造一个求解非线性最小二乘法的Problem来进行未知数求解。

(5)运行结果

Powell

1.5 Bundle Adjustment

(1)BA数据集

Bundle Adjustment in the Large

​ 备注:此处使用Ladybug Dataset:problem-49-7776-pre.txt.bz2

(2)BA问题

ceres solver学习之bundle adjustment

Bundle Adjustment Projection Error

(3)步骤

​ (3.1)读取problem-49-7776-pre.txt.bz2数据。

​ (3.2)编写CostFunction结构体。

​ (3.3)构造一个求解非线性最小二乘法的Problem来进行未知数求解。

(4)运行结果

Simple Bundle Adjustment Solve Result

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值