如何从点云重新格式化文本文档?
How to reformat a text document from a point cloud?
我正在尝试从我的 3D 扫描仪转换点列表。扫描器以 "X Y Z Intensity R G B" 格式输出点
示例:
-20.909 -7.091 -1.204 -1466 119 102 90
-20.910 -7.088 -1.203 -1306 121 103 80
-20.910 -7.090 -1.204 -1456 123 102 89
我想将它转换成这个(在添加逗号和括号的同时删除强度和颜色数据)
期望的输出:
(-20.909, -7.091, -1.204),
(-20.910, -7.088, -1.203),
(-20.910, -7.090, -1.204),
(-20.910, -7.088, -1.204),
(-20.909, -7.088, -1.204),
(-20.910, -7.088, -1.203),
(-20.909, -7.090, -1.202),
(-20.905, -7.091, -1.204),
(-20.907, -7.090, -1.204),
(-20.907, -7.090, -1.204)
我正在尝试这样做,以便我可以将点云数据导入到 Blender3D 中的脚本中。任何帮助,将不胜感激。
编辑:打字错误。
def convert_line(line):
parts = line.split(maxsplit=3)
return f'({parts[0]}, {parts[1]}, {parts[2]})'
with open('data.txt') as in_:
lines = in_.readlines()
converted = [convert_line(x) for x in lines]
with open('output.txt', 'w') as out_:
out_.write(',\n'.join(converted))
这是一个非常基本的脚本,但假设没有数据损坏,它应该可以满足您的需要。使用适当的文件名(路径)更改 data.txt
和 output.txt
。
def convert(line):
x, y, z, intensity, r, g, b = line.split()
return f'({x}, {y}, {z})'
with open('input.txt') as f:
with open('output.txt', 'w') as out:
lines = f.readlines()
out.write(',\n'.join(convert(line) for line in lines))
我正在尝试从我的 3D 扫描仪转换点列表。扫描器以 "X Y Z Intensity R G B" 格式输出点 示例:
-20.909 -7.091 -1.204 -1466 119 102 90
-20.910 -7.088 -1.203 -1306 121 103 80
-20.910 -7.090 -1.204 -1456 123 102 89
我想将它转换成这个(在添加逗号和括号的同时删除强度和颜色数据)
期望的输出:
(-20.909, -7.091, -1.204),
(-20.910, -7.088, -1.203),
(-20.910, -7.090, -1.204),
(-20.910, -7.088, -1.204),
(-20.909, -7.088, -1.204),
(-20.910, -7.088, -1.203),
(-20.909, -7.090, -1.202),
(-20.905, -7.091, -1.204),
(-20.907, -7.090, -1.204),
(-20.907, -7.090, -1.204)
我正在尝试这样做,以便我可以将点云数据导入到 Blender3D 中的脚本中。任何帮助,将不胜感激。
编辑:打字错误。
def convert_line(line):
parts = line.split(maxsplit=3)
return f'({parts[0]}, {parts[1]}, {parts[2]})'
with open('data.txt') as in_:
lines = in_.readlines()
converted = [convert_line(x) for x in lines]
with open('output.txt', 'w') as out_:
out_.write(',\n'.join(converted))
这是一个非常基本的脚本,但假设没有数据损坏,它应该可以满足您的需要。使用适当的文件名(路径)更改 data.txt
和 output.txt
。
def convert(line):
x, y, z, intensity, r, g, b = line.split()
return f'({x}, {y}, {z})'
with open('input.txt') as f:
with open('output.txt', 'w') as out:
lines = f.readlines()
out.write(',\n'.join(convert(line) for line in lines))