我正在尝试在点云上进行一些后期处理, 当我尝试使用Axis3D绘制点云时,我会看到点云的外观不同,它沿轴拉伸。 当我尝试另一个点云视图时,会得到完全不同的网格。
这是我的代码 和图片
def main():
#process first point cloud
f3data = np.loadtxt(r'c:\ahmed\Waltersdorf_F3.csv', delimiter=',',
dtype=[('id', np.str_, 20), ('x1', np.float32), ('x2', np.float32), ('x3', np.float32),
])
ptcloud_1 = np.vstack((f3data['x1'], f3data['x2'], f3data['x3'])).transpose()
pc_1 = pcl.PointCloud.PointXYZ(ptcloud_1)
X = np.vstack((pc_1.x, pc_1.y, pc_1.z)).transpose()
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d as m3d
ax = m3d.Axes3D(plt.figure())
ax.scatter3D(*X.T)
plt.show()
# pc_1 = pclpy.radius_outlier_removal(pc_1, search_radius=1.0, min_neighbors=4)
#plotScatterRot3(f3rot)
pc_type = utils.get_point_cloud_type(pc_1)
seg = getattr(pcl.segmentation.SACSegmentation, pc_type)()
seg.setOptimizeCoefficients(True)
model = getattr(pcl.sample_consensus, "SACMODEL_" + 'PLANE'.upper())
seg.setModelType(model)
seg.setMethodType(pcl.sample_consensus.SAC_RANSAC)
seg.setDistanceThreshold(1)
seg.setInputCloud(pc_1)
coefficients = pcl.ModelCoefficients()
inliers = pcl.PointIndices()
arr = np.ndarray(shape=(3,1), dtype= np.float32)
arr[0] = 0
arr[1] = 0
arr[2] = 1
seg.setAxis(arr)
seg.segment(inliers, coefficients)
inla = pc_1.xyz[inliers.indices]
cloud_filtered = pcl.PointCloud.PointXYZ(inla)
X = np.vstack((cloud_filtered.x, cloud_filtered.y, cloud_filtered.z)).transpose()
pca = decomposition.PCA(n_components=3)
pca.fit(X)
X = pca.transform(X)
final_cloud = pcl.PointCloud.PointXYZ(X)
pcl.io.savePCDFile("original_first.txt", final_cloud)
import mpl_toolkits.mplot3d as m3d
ax = m3d.Axes3D(plt.figure())
ax.scatter3D(*X.T)
plt.show()
pptk.viewer(X)
这是数据集
http://www.mediafire.com/file/f8tz1zbpxvyvko7/Waltersdorf_F3.csv/file