对相机位姿 导出 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)
相关推荐
智能汽车人几秒前
行业分析---自动驾驶行业的发展
人工智能·机器学习·自动驾驶
注册机几秒前
锐尔15注册机 锐尔文档扫描影像处理系统15功能介绍
人工智能·信息可视化·软件工程
##晴天小猪1 分钟前
ByteTrack多目标跟踪流程图
人工智能·算法·目标检测·机器学习·目标跟踪
小ᶻᶻᶻ20 分钟前
如何有效管理技术债务:IT项目中的长期隐患
人工智能
Colddd_d38 分钟前
动手学深度学习(五)循环神经网络RNN
人工智能·rnn·深度学习
sp_fyf_20241 小时前
人工智能-大语言模型-微调技术-LoRA及背后原理简介
人工智能·语言模型·自然语言处理
xuehaishijue1 小时前
射击靶标检测系统源码分享
人工智能·计算机视觉·目标跟踪
Kenneth風车1 小时前
【机器学习(九)】分类和回归任务-多层感知机 (MLP) -Sentosa_DSML社区版
人工智能·算法·低代码·机器学习·分类·数据分析·回归
知来者逆1 小时前
ChemChat——大语言模型与化学的未来,以及整合外部工具和聊天机器人的潜力
人工智能·gpt·语言模型·自然语言处理·机器人·llm·大语言模型
AI领航者1 小时前
大型语言模型的结构性幻觉:不可避免的局限性
人工智能·语言模型·自然语言处理·llm·大语言模型·ai大模型·大模型幻觉