程序输入需要
1 真值是为为了最后的评估
2 深度图也是为了评估或者跑深度的

运行
source /home/dongdong/1sorftware/1work/yes/etc/profile.d/conda.sh
conda activate MonoGS
(MonoGS) dongdong@dongdong:~/2project/MonoGS$ python slam.py --config configs/mono/tum/fr3_office.yaml
1 脚本生成 文件名字列表 程序依靠着输入图像
/home/dongdong/2project/MonoGS/utils/generate_txts.py --dataset tum --scene fr3_office --output tum/fr3_office.txt
1-1 修改图像文件夹
base_folder = '/media/dongdong/Elements/项目/ehang_/2TestData/2TestData/ehang3'
1-2 修改保存名字 经度
f.write(f"{idx:04d} {filename_with_path}\n")
2 修改配置文件的数据地址
dataset_path: "/home/dongdong/2project/0data/RTK/data_3_jianda/300_map_3pm"
3 修改参数
/home/dongdong/2project/MonoGS/configs/mono/tum/base_config.yaml
迭代次数
init_itr_num: 1050
tracking_itr_num: 1500 #
mapping_itr_num: 1500 #150
开始运行
cd ~/2project/MonoGS/
python slam.py --config configs/mono/tum/mytrial_rtk.yaml
配置文件
inherit_from: "/home/dongdong/2project/MonoGS/configs/mono/tum/base_config.yaml"
Dataset:
dataset_path: "/home/dongdong/2project/0data/RTK/data_4_city/300_map_2pm"
Calibration:
fx: 1193.7076128098686
fy: 1193.1735265967602
cx: 910.8785687265895
cy: 602.174293145834
k1: 0.0
k2: 0.0
p1: 0.0
p2: 0.0
k3: 0.0
width: 1805
height: 1203
distorted: False
脚本
从原始真值中提取和图片一一对应的位姿
原来的真值是时间戳,对应不上


手动对其 找最近的时间戳


import os
import numpy as np
def extract_timestamp(filename):
"""从文件名中提取时间戳(去掉.png后缀)"""
return float(filename.replace('.png', ''))
def read_ground_truth(file_path):
"""读取ground truth文件,返回时间戳和位姿数据的列表"""
ground_truth_data = []
with open(file_path, 'r') as f:
for line in f:
# 跳过注释行
if line.startswith('#'):
continue
# 分割行数据
parts = line.strip().split()
if len(parts) >= 8: # 确保有足够的数据
timestamp = float(parts[0])
timestamp_s=str(parts[0])
tx, ty, tz = map(float, parts[1:4])
qx, qy, qz, qw = map(float, parts[4:8])
ground_truth_data.append((timestamp, tx, ty, tz, qx, qy, qz, qw,timestamp_s))
# 按时间戳排序
ground_truth_data.sort(key=lambda x: x[0])
return ground_truth_data
def find_closest_ground_truth(target_timestamp, ground_truth_data):
"""在ground truth数据中找到时间戳最接近的那一行"""
# 将ground truth数据转换为numpy数组以便计算
timestamps = np.array([data[0] for data in ground_truth_data])
# 计算时间差
time_diffs = np.abs(timestamps - target_timestamp)
# 找到最小差值的索引
closest_idx = np.argmin(time_diffs)
return ground_truth_data[closest_idx]
def process_images(rgb_folder, ground_truth_file, output_file):
"""处理图片和ground truth数据,生成新的输出文件"""
# 读取ground truth数据
ground_truth_data = read_ground_truth(ground_truth_file)
# 获取所有图片文件名
image_files = [f for f in os.listdir(rgb_folder) if f.endswith('.png')]
# 提取每个图片的时间戳并创建(时间戳, 文件名)的元组列表
image_timestamps = []
for image_file in image_files:
timestamp = extract_timestamp(image_file)
image_timestamps.append((timestamp, image_file))
# 按时间戳排序(升序)
image_timestamps.sort(key=lambda x: x[0])
# 打开输出文件
with open(output_file, 'w') as out_f:
# 写入表头(可选)
#out_f.write("# image_filename tx ty tz qx qy qz qw original_timestamp\n")
for image_timestamp, image_file in image_timestamps:
# 找到最接近的ground truth
closest_gt = find_closest_ground_truth(image_timestamp, ground_truth_data)
# 写入输出文件
out_line = f"{image_file} {closest_gt[1]} {closest_gt[2]} {closest_gt[3]} {closest_gt[4]} {closest_gt[5]} {closest_gt[6]} {closest_gt[7]} {closest_gt[8]}\n"
out_f.write(out_line)
# 主程序
if __name__ == "__main__":
# 文件夹和文件路径
data="rgbd_dataset_freiburg1_desk"
rgb_folder = data+'/rgb' # 图片文件夹路径
ground_truth_file = data+'/groundtruth.txt' # ground truth文件路径
output_file = data+'/gnss.txt' # 输出文件路径
# 处理数据
process_images(rgb_folder, ground_truth_file, output_file)
print(f"处理完成,结果已保存到 {output_file}")
浙公网安备 33010602011771号