采用线性回归方法降低双目测距到平面的误差(sklearn)

家住魔仙堡 提交于 2019-12-06 06:35:02

上一篇中,利用线性回归方法改善标定板的深度信息:

remove_idx1 = np.where(Z <= 0)
remove_idx2 = np.where(Z > 500)#将Z轴坐标限定在0-500,以减少非标定板区域的坐标影响

采用线性回归并显示坐标信息

from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

#删除掉无效及多余点后,得到points_3d
X = points_3d[:, 0]
Y = points_3d[:, 1]
Z = points_3d[:, 2]
XY = points_3d[:, :2]

#利用线性回归计算新的Z轴坐标
reg = LinearRegression()
reg.fit(XY, Z)
Z_predict = reg.predict(XY)

fig=plt.figure()
ax = plt.axes(projection='3d')
ax.scatter3D(X, Y, Z, c='gray', s=1)#显示原始点信息
ax.scatter3D(X, Y, Z_predict, c='red')#显示修正点信息
ax.set_xlabel(r'$x_1$',fontsize = 20, color = 'blue')
ax.set_ylabel(r'$x_2$',fontsize = 20, color = 'blue')
ax.set_zlabel(r'$x_3$',fontsize = 20, color = 'blue')

 


 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!