对相机位姿 导出 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)
相关推荐
jiayong236 小时前
harness 与 hermes-agent 运行原理和核心流程
人工智能·ai·智能体·harness·hermes-agent
码海浮生6 小时前
人工智能日报 每日AI新闻(2026年5月25日):Google I/O余波下的AI安全、多模态生成与搜索体验分化
大数据·人工智能·安全
dingzd956 小时前
Pinterest年度色彩发布后跨境内容团队如何统一视觉风格与选题方向
大数据·人工智能·新媒体运营·市场营销·跨境
ting94520006 小时前
深度解析 Google Stitch 3.0:文本驱动跨端 UI 生成技术原理、架构与工程实现
人工智能·ui·架构
数字化转型20256 小时前
重构Sales Force AI Agent
人工智能·重构
多年小白6 小时前
开盘策略】2026年5月28日(周四)
大数据·人工智能·物联网·金融·区块链
luyu007_0076 小时前
AGV无人叉车无线充电厂家怎么选?鲁渝能源大功率无线充电方案解析
人工智能·机器人·能源·制造
YueJoy.AI6 小时前
创业团队如何建立技术品牌
人工智能·ai·语言模型
星辰AI6 小时前
AIOps 实战:智能运维在 AI 应用中的实践
人工智能·ai·语言模型
zhangfeng11336 小时前
vLLM + AWQ 是什么,为什么有算力架构要求 为什么v100默认不支持
人工智能·语言模型·显卡·vllm