把点云(point cloud)视作位姿的平移部分, 导出 Tum 格式的位姿

本文介绍了一个Python函数,用于给给定的N×3pointcloudtxt文件添加时间戳和单位阵四元数,将其转换为Tum格式的位姿txt,以便于使用EVO轨迹评测工具计算点云间的相似变换距离。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

需求:对一个 [N,3] 的 point cloud txt 补充 时间戳跟 单位阵 四元数。输出 Tum 格式的 位姿 txt。方便对 原始 point cloud 使用 EVO 轨迹评测工具,在 相似变换的 尺度上计算两个 点云的整体距离。

import os
import numpy as np

def transform_and_write_txt(input_file, output_file):
    # 读取输入文件
    with open(input_file, "r") as f:
        lines = f.readlines()

    # 生成时间戳
    timestamps = np.linspace(0, 1000, len(lines), endpoint=False)

    # 处理每一行
    output_lines = []
    for timestamp, line in zip(timestamps, lines):
        # 分割每一行的坐标值
        coords = line.strip().split()

        # 添加时间戳,零值和1
        output_line = [f"{timestamp:.6f}"] + coords + ["0", "0", "0", "1"]

        # 将该行数据转为字符串并添加到输出列表
        output_lines.append(" ".join(output_line))

    # 将处理后的数据写入输出文件
    with open(output_file, "w") as f:
        f.write("\n".join(output_lines))

    print(f"Output written to {output_file}")

current_directory = os.path.dirname(os.path.abspath(__file__))
input_file1 =   os.path.join(current_directory , "LoFTR_pt.txt") 
output_file1 =  os.path.join(current_directory , 'Tum'+os.path.basename(input_file1)) 

transform_and_write_txt(input_file1, output_file1)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

培之

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值