最近在做毕业设计,课题研究对象就是ScanNet数据集Scannet主页,所以也学到了一些处理点云的方法。在这里记录一下。
数据集简介
下载完数据集后,内部结果如下所示,每一个场景一个文件夹。
<scanId>
|-- <scanId>_vh_clean.ply
(Updated if had remove annotations)
|-- <scanId>_vh_clean_2.ply
(Updated if had remove annotations)
|-- <scanId>.aggregation.json, <scanId>_vh_clean.aggregation.json
Updated aggregated instance-level semantic annotations on lo-res, hi-res meshes, respectively
|-- <scanId>_vh_clean_2.labels.ply
Updated visualization of aggregated semantic segmentation; colored by nyu40 labels (see legend referenced above; ply property 'label' denotes the ScanNet label id)
|-- <scanId>_2d-label.zip
Updated raw 2d projections of aggregated annotation labels as 16-bit pngs with ScanNet label ids
|-- <scanId>_2d-instance.zip
Updated raw 2d projections of aggregated annotation instances as 8-bit pngs
|-- <scanId>_2d-label-filt.zip
Updated filtered 2d projections of aggregated annotation labels as 16-bit pngs with ScanNet label ids
|-- <scanId>_2d-instance-filt.zip
Updated filtered 2d projections of aggregated annotation instances as 8-bit pngs
如下图所示:
其中scene0000_00_vh_clean.ply
和scene0000_00_vh_clean_2.ply
都是点云图像的ply文件(两者清晰度不同),可以直接用meshlab打开,也可用open3d绘制。但是可以看出,整幅点云图像对于坐标轴原点来讲是有偏移的。
scene0000_00_vh_clean_2.labels.ply
是带标签的点云,是分隔之后的结果。
可以看出,以上3幅图对于远点都是有偏移的。那么如何处理便宜呢?
3D点云处理偏移
在文件夹下,有一个scene0000_00.txt
文件,第一行axisAlignment
就是坐标偏移。
点的处理偏移
if __name__ == '__main__':
# 1. 得到 ply 文件,分别得到 x, y, z, r, g, b
filename = os.path.join(ROOT, "scene0000_00_vh_clean_2.ply")
with open(filename, 'rb') as f:
plydata = PlyData.read(f)
num_verts = plydata['vertex'].count
vertices = np.zeros(shape=[num_verts, 6], dtype=np.float32)
vertices[:, 0] = plydata['vertex'].data['x']
vertices[:, 1] = plydata['vertex'].data['y']
vertices[:, 2] = plydata['vertex'].data['z']
vertices[:, 3] = plydata['vertex'].data['red']
vertices[:, 4] = plydata['vertex'].data['green']
vertices[:, 5] = plydata['vertex'].data['blue']
# 2. 得到偏移
meta_file = os.path.join(ROOT, "scene0000_00.txt")
lines = open(meta_file).readlines()
axis_align_matrix = None
for line