点云平面拟合效果对比(Matlab/Opencv/C++)

8 篇文章 1 订阅
8 篇文章 1 订阅

//大部分数据点在一个平面效果测试(方法3,4有问题)

X=[1,1,1,2,2,2,3,3,3]; Y=[1,2,3,1,2,3,1,2,3]; Z=[5,5,5,5,5,5,5,8,8]; 矩阵S=[1,1,5;1,2,5;1,3,5;2,1,5;2,2,5;2,3,5;3,1,5;3,2,8;3,3,8];

S=[1,1,5;1,2,5;1,3,5;2,1,5;2,2,5;2,3,5;3,1,5;3,2,8;3,3,8]; [A1,B1,C1,D1] = PlaneFitting_1(S)
X=[1,1,1,2,2,2,3,3,3]; Y=[1,2,3,1,2,3,1,2,3]; Z=[5,5,5,5,5,5,5,8,8];  [A2,B2,C2,D2] = PlaneFitting_2(X,Y,Z)
X=[1,1,1,2,2,2,3,3,3]; Y=[1,2,3,1,2,3,1,2,3]; Z=[5,5,5,5,5,5,5,8,8];  [A3,B3,C3,D3] = PlaneFitting_3(X,Y,Z)

    //===============plane_Out=A4,B4,C4,D4
    vector <float > X_vector = { 1,1,1,2,2,2,3,3,3 };
    vector <float > Y_vector = { 1,2,3,1,2,3,1,2,3 };
    vector <float > Z_vector = { 5,5,5,5,5,5,5,8,8};

    //float *plane_Out;
    //cvFitPlane(X_vector, Y_vector, Z_vector, *plane_Out);

    float plane_Out[4];
    FitPlane_1(X_vector, Y_vector, Z_vector,plane_Out);
    //Ax+by+cz=D  
    //===============Para=A5,B5,C5,D5
    double A[9][3] = { 1,1,5,1,2,5,1,3,5,2,1,5,2,2,5,2,3,5,3,1,5,3,2,8,3,3,8 };
    double Para[3];
    LinearFit(A, 5, Para);
    //Ax+By+1Z=D
    //printf("%lf %lf %lf", Para[0], Para[1], Para[2]);
    //===========================================================

//========结果:

A1,B1,C1,D1=[0.7777, 0.3889, -0.4939,-0.4655]            fitPlane1
A2,B2,C2,D2=[1,0.5,-1,-2.6667]   fitPlane2
A3,B3,C3,D3=[1,1.4901e-08,0,2]   fitPlane3
A4,B4,C4,D4=[-1.0490e-15,1,9.0778e-20,-1]    fitPlane4
A5,B5,C5,D5=[-0.777726769, -0.388863564, 0.493888885, 0.465523005]       Opencv
A6,B6,C6,D6=[-2.4868995751603507e-13, -1.4566126083082054e-13,1, 5.0000000000006537]      C++

Show_Point(X,Y,Z)
Show_Plane(A1,B1,C1,D1,-5,5,-5,5)
Show_Plane(A2,B2,C2,D2,-5,5,-5,5)
Show_Plane(A3,B3,C3,D3,-5,5,-5,5)
Show_Plane(A4,B4,C4,D4,-5,5,-5,5)
Show_Plane(A5,B5,C5,D5,-5,5,-5,5)

//====================================================================================效果:

 

//================================================

//测试1===============================================================大部分数据点在一个平面效果测试(方法3有问题)
S=[1,1,5;1,2,5;1,3,5;2,1,5;2,2,5;2,3,5;3,1,5;3,2,8;3,3,8]; [A1,B1,C1,D1] = PlaneFitting_1(S)
X=[1,1,1,2,2,2,3,3,3]; Y=[1,2,3,1,2,3,1,2,3]; Z=[5,5,5,5,5,5,5,8,8];  [A2,B2,C2,D2] = PlaneFitting_2(X,Y,Z)
X=[1,1,1,2,2,2,3,3,3]; Y=[1,2,3,1,2,3,1,2,3]; Z=[5,5,5,5,5,5,5,8,8];  [A3,B3,C3,D3] = PlaneFitting_3(X,Y,Z)


A1,B1,C1,D1=[0.7777, 0.3889, -0.4939,-0.4655]            fitPlane1
A2,B2,C2,D2=[1,0.5,-1,-2.6667]   fitPlane2
A3,B3,C3,D3=[1,1.4901e-08,0,2]   fitPlane3
A5,B5,C5,D5=[-0.777726769, -0.388863564, 0.493888885, 0.465523005]       Opencv和你和方法1结果一样
A6,B6,C6,D6=[-2.4868995751603507e-13,-1.4566126083082054e-13,1, 5.0000000000006537]      C++

Show_Point(X,Y,Z)
Show_Plane(A1,B1,C1,D1,-5,5,-5,5)
Show_Plane(A2,B2,C2,D2,-5,5,-5,5)
Show_Plane(A3,B3,C3,D3,-5,5,-5,5)

Show_Plane(A5,B5,C5,D5,-5,5,-5,5)
Show_Plane(A6,B6,C6,D6,-5,5,-5,5)

//测试2===============================================================大量数据点并且不在一个平面效果测试()
S=[1,1,3;1,2,4;1,3,6;1,4,8;1,5,3;2,1,2;2,2,4;2,3,5;2,4,6;2,5,3;3,1,7;3,2,5;3,3,4;3,4,3;3,5,5;4,1,2;4,2,4;4,3,5;4,4,6;4,5,3;]; [A1,B1,C1,D1] = PlaneFitting_1(S)
X=[1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4]; Y=[1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5]; Z=[3,4,6,8,3,2,4,5,6,3,7,5,4,3,5,2,4,5,6,3];  [A2,B2,C2,D2] = PlaneFitting_2
(X,Y,Z)
X=[1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4]; Y=[1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5]; Z=[3,4,6,8,3,2,4,5,6,3,7,5,4,3,5,2,4,5,6,3];  [A3,B3,C3,D3] = PlaneFitting_3
(X,Y,Z)

A1,B1,C1,D1=[0.9846, -0.0624, 0.1630,2.9915]            fitPlane1     
A2,B2,C2,D2=[-0.1600,0.1500,-1,-4.3500]   fitPlane2                 OK
A3,B3,C3,D3=[1,1.8626e-09,0,2.5000]       fitPlane3
A5,B5,C5,D5=[0.984648466, -0.0624423623, 0.162997052, 2.99148130]       Opencv和你和方法1结果一样
A6,B6,C6,D6=[-0.1599999, 0.15000000,1, 4.349999]      C++   OK符号还有问题和方法2

//测试3===============================================================数据接近接近实际生产(Z变化较小)
S=[1,1,3.3;1,2,3.4;1,3,3.6;1,4,3.8;1,5,3.3;2,1,3.2;2,2,3.4;2,3,3.5;2,4,3.6;2,5,3.3;3,1,3.7;3,2,3.5;3,3,3.4;3,4,3.3;3,5,3.5;4,1,3.2;4,2,3.4;4,3,3.5;4,4,3.6;4,5,3.3;];
[A1,B1,C1,D1] = PlaneFitting_1(S)
X=[1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4]; Y=[1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5]; Z=
[3.3,3.4,3.6,3.8,3.3,3.2,3.4,3.5,3.6,3.3,3.7,3.5,3.4,3.3,3.5,3.2,3.4,3.5,3.6,3.3];  [A2,B2,C2,D2] = PlaneFitting_2(X,Y,Z)
X=[1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,4,4,4,4]; Y=[1,2,3,4,5,1,2,3,4,5,1,2,3,4,5,1,2,3,4,5];
[3.3,3.4,3.6,3.8,3.3,3.2,3.4,3.5,3.6,3.3,3.7,3.5,3.4,3.3,3.5,3.2,3.4,3.5,3.6,3.3]  [A3,B3,C3,D3] = PlaneFitting_3(X,Y,Z)


A1,B1,C1,D1=[0.0163, -0.0152, 0.9998,3.4344]            fitPlane1        OK
A2,B2,C2,D2=[-0.0160,0.0150,-1,-3.4350]   fitPlane2                      OK
A3,B3,C3,D3=[1,1.8626e-09,0,2.5000]       fitPlane3                      有问题
A5,B5,C5,D5=[0.0163173713, -0.0151831107, 0.999751508, 3.43438983]       Opencv和你和方法1结果一样    OK
A6,B6,C6,D6=[-0.015999999999953829, 0.015000000000033431,1, 3.4349999999997607]          OK符号还有问题和方法2

数据趋于接近一个平面时,平面方程的结果基本相同的

//==========================================总结

总结:除了方法3有问题,1,2,5,6结果基本相同。(一带基本总感觉要被骂的感觉)

其中拟合2是一直用的方法效果最佳,不过因为是Matlab方法,所以不能用,最终选择方法6,C++方法。

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值