对相机位姿 导出 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)
相关推荐
ms365copilot4 分钟前
Copilot分析销售收入变化、找出涨跌原因
大数据·人工智能·copilot
YOLO数据集集合13 分钟前
煤炭质量目标检测数据集 、| 煤炭检测 工业视觉 质量分级 异物检测 煤炭异物8005期
人工智能·yolo·目标检测·计算机视觉·分类·煤炭检测数据集·异物数据集
躺柒16 分钟前
读数据可视化16大规模多变量空间数据(下)
人工智能·信息可视化·可视化·数据可视化·空间·大数据分析
qq4078556018 分钟前
中小五金建材贸易企业:进销存数字化要重点关注哪些环节?
人工智能·低代码·制造
HIT_Weston19 分钟前
190、【Agent】【OpenCode】TuiThreadCmd(alias)
人工智能·agent·opencode
点PY25 分钟前
《基于深度超分辨率网络的集成电路CT图像增强方法及系统》专利解读
人工智能
DeepAgent26 分钟前
AI Agent 工程实践(34):企业 AI Agent 架构
数据库·人工智能·agent
MartinYeung537 分钟前
[论文学习]AI-Trader:实时金融市场中自主代理的基准测试
人工智能·深度学习·学习
君顾140 分钟前
AI新零售线上商城系统实战指南:架构设计与开发经验分享
人工智能·经验分享·零售
乐迪信息40 分钟前
防爆AI摄像机实时监测船舶异常姿态
大数据·人工智能·算法·安全·目标跟踪