对相机位姿 导出 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)
相关推荐
CoovallyAIHub3 分钟前
当小龙虾算法遇上YOLO:如何提升太阳能电池缺陷检测精度?
深度学习·算法·计算机视觉
J_Xiong01178 分钟前
【VLMs篇】12:Cambrian-S:迈向视频中的空间超感知
人工智能·机器人
轻竹办公PPT10 分钟前
2026 年工作计划 PPT 制作,对比几种 AI 生成思路
人工智能·python·powerpoint
RestCloud11 分钟前
谷云科技发布 API × AI 战略:让 AI 从“理解数据”走向“驱动业务能力”
人工智能·科技·api·数据集成·ipaas·aiagent·ai网关
其美杰布-富贵-李14 分钟前
PyTorch Lightning 中 TorchMetrics
人工智能·pytorch·python·计算损失
苛子14 分钟前
谷云科技发布API × AI 战略是什么?
大数据·人工智能
CoovallyAIHub14 分钟前
AI如何精准关联照片与抽象平面图?C3数据集迈向3D视觉多模态
深度学习·算法·计算机视觉
GEO AI搜索优化助手16 分钟前
数据共振:GEO与SEO的算法协同与智能决策系统
人工智能·算法·搜索引擎·生成式引擎优化·ai优化·geo搜索优化
张彦峰ZYF21 分钟前
持续改进 RAG 应用效果:从“能用”到“好用”的系统化方法
人工智能·rag·rag进阶
yumgpkpm21 分钟前
Cloudera CDP 7.3(国产CMP 鲲鹏版)平台与银行五大平台的技术对接方案
大数据·人工智能·hive·zookeeper·flink·kafka·cloudera