对相机位姿 导出 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)
相关推荐
cxr8284 分钟前
第6章 强制执行令牌
人工智能·智能体
vibecoding7711 分钟前
GitHub 2026 年 7 月热榜:累计 Star 总榜与月度飙星榜
人工智能·github·ai编程
anscos15 分钟前
面向人工智能安全和 ISO/PAS 8800 的自动化 C/C++ 测试路线图
人工智能·parasoft
<-->17 分钟前
Megatron-LM 深度学习与源码分析文档
人工智能·深度学习
aqi0019 分钟前
15天学会AI应用开发(十八)使用LangGraph实现精确记忆功能
人工智能·python·大模型·ai编程·ai应用
Michaelliu_dev26 分钟前
RoPE通俗讲解
人工智能·llm·位置编码·多模态大模型·rope·旋转位置编码·mllm
呆呆敲代码的小Y31 分钟前
5 分钟上手 OpenMontage:把 AI 编程助手变成视频工作室
人工智能·aigc·音视频·ai视频生成·claude code·openmontage
swany42 分钟前
同步数据中,只需要几秒钟 & milvus向量数据库不可用 dify1.16.1 升级后踩坑记录
开发语言·python·numpy
ShallWeL1 小时前
【机器学习】(30)—— 嵌入空间
人工智能·神经网络·机器学习·embedding
MindUp1 小时前
AI辅助PPT生成工具实测:百度文库等平台在技术学习场景下的内容生成与排版能力对比
人工智能·百度·powerpoint