我正在尝试从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))