对相机位姿 导出 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)
相关推荐
橙时数据 FineInsight11 分钟前
AI 能回答数据问题,但能解释业务原因吗?
大数据·人工智能·数据分析·指标平台·fineinsight
CTA终结者15 分钟前
示例、拆解和练习,要连成一条量化补课线
人工智能·python
Omics Pro17 分钟前
Arc研究所Cell|全新虚拟细胞官方基准评测框架
大数据·人工智能·深度学习·算法·机器学习
yychen_java19 分钟前
从像素到汉字:基于深度学习的中文OCR系统六步全链路剖析
人工智能·深度学习·ocr
Chengbei1120 分钟前
SRC报告成稿 Skill(SRC/0day 提交稿、分层验证门、Step 式 PoC、截图铁律)
网络·人工智能·安全·web安全·自动化·系统安全
花开富贵AI小白进化记24 分钟前
《从微软2.8万美元Token账单,看企业AI的模型路由与成本治理》
人工智能·api
甲维斯25 分钟前
Grok4.6速评GPT6:先当员工,再当科学家 !
人工智能
因_崔斯汀27 分钟前
用 AI 生成 Three.js 沉浸式网站,代码与 Skill 均已开源
前端·人工智能
Vidu_API开放平台33 分钟前
每一句台词都是 AI 现编的:我用一个 WebSocket 接住了 Vidu S1 实时数字人
人工智能
LingYi_033 分钟前
建筑提取—BuildFormer
人工智能·深度学习