对相机位姿 导出 Tum 格式的位姿

需求:针对 N,4,4 格式的 poses np.darray 导出其 Tum 格式 的位姿。

时间戳根据 N 的值,线性得到。

python 复制代码
import numpy as np
import os
import torch
from scipy.spatial.transform import Rotation

def rotation_matrix_to_tum_format(rotation_matrix):
    rotation = Rotation.from_matrix(rotation_matrix)
    quaternion = rotation.as_quat()
    return quaternion

def convert_to_tum_format(poses, timestamps):
    tum_poses = []
    for i in range(poses.shape[0]):
        pose = poses[i]
        quaternion = rotation_matrix_to_tum_format(pose[:3, :3])
        tum_timestamp = timestamps[i] * 0.1  # Scaling factor of 0.1 to convert timestamps to seconds
        tum_pose = f"{tum_timestamp:.6f} {' '.join(map(str, pose[:3, 3]))} {' '.join(map(str, quaternion))}" 
        tum_poses.append(tum_pose)
    return tum_poses
def write_tum_poses_to_file(file_path, tum_poses):
    with open(file_path, 'w') as f:
        for pose in tum_poses:
            f.write(pose + '\n')
def convert_and_write_tum_poses(c2w_variable, output_filename, timestamps):
    # 调用适当的函数将变量转换为 TUM 格式
    tum_poses = convert_to_tum_format(c2w_variable, timestamps)
    
    # 将 TUM 格式的位姿写入文件
    write_tum_poses_to_file(output_filename, tum_poses)
n_poses = c2w_GT_traj.shape[0]
custom_timestamps = np.arange(n_poses)
convert_and_write_tum_poses(c2w_GT_traj, 'tum_c2w_GT_traj.txt', custom_timestamps)
相关推荐
海盗12348 小时前
AI 新闻日报 2026-09-17:多智能体长程交付、机器人通用工程底座、端侧与国产算力
人工智能·机器人·aigc
xwz小王子8 小时前
Show-Harness:让视觉语言模型直接“玩”机器人,跨形态操作成功率89%
人工智能·机器人
zhenaibo5218 小时前
10分钟答辩PPT如何呈现,才会显得特别稳?
大数据·人工智能
回眸&啤酒鸭8 小时前
【回眸】DeepSeek V4 Flash 批量处理实战指南
人工智能
云上工程笔记8 小时前
零基础 Vibe Coding 实战:用 p5.js 把一句古诗做成可交互的离线小工具
人工智能
wshzd8 小时前
LLM之Agent(八十二)|PI(二十一)Skills 与 Prompt Templates
人工智能
硅谷秋水8 小时前
GE-Act 2.0:面向机器人操作的“世界-动作”模型预训练与扩展
机器学习·计算机视觉·语言模型·机器人
tokenKe8 小时前
Github 开源热榜 【2026-0917】
人工智能·chrome·github
动恰客流统计8 小时前
用客流数据优化门店排班:高峰不缺人、平峰不浪费的落地路径
大数据·前端·人工智能