对相机位姿 导出 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)
相关推荐
辉视广播对讲21 小时前
医院IPTV,让医疗服务更有温度
网络·人工智能
xqqxqxxq21 小时前
Java AI智能P图工具技术笔记
java·人工智能·笔记
AI袋鼠帝21 小时前
本地4B开源模型,把任何App当Skil用!告 别token焦虑,私密性强~
人工智能
ComputerInBook21 小时前
数字图像处理(4版)——第 11 章——特征提取(下)(Rafael C.Gonzalez&Richard E. Woods)
图像处理·人工智能·特征提取
在线打码21 小时前
ToutiaoAI:AI 驱动的智能新闻杂志平台
人工智能·ai·aigc·ai写作·新闻资讯
ar012321 小时前
AR电路巡检:让电力运维进入智能可视化时代
运维·人工智能·ar
低调小一21 小时前
Midscene.js 原理拆解:它不是“自然语言点按钮”,而是一套会看屏幕的 UI 自动化运行时
人工智能·rnn·架构·大模型·transformer·tdd·midscene
Slow菜鸟1 天前
Codex CLI 教程(五)| Skills 安装指南:面向 Java 全栈工程师打造个人 ECC(V1版)
大数据·前端·人工智能
昇腾CANN1 天前
5月11日直播丨CANN算子挑战赛(江山赛区)赛题和评分规则解读
人工智能·昇腾·cann·deepseek
菜鸡信息技术1 天前
VSCode 安装 Claude Code 插件,配置 DeepSeek V4(Windows)
人工智能