Shiaoming / Python-VO

A simple python implemented frame-by-frame visual odometry with SuperPoint feature detector and SuperGlue feature matcher.
323 stars 40 forks source link

Error when run TUM dataset #10

Open zhanghua7099 opened 3 years ago

zhanghua7099 commented 3 years ago

I try to run code in TUM datasets but get the error message.

Traceback (most recent call last): File "main.py", line 109, in run(args) File "main.py", line 65, in run loader = create_dataloader(config["dataset"]) File "/home/zhy/PyProject/Python-VO/DataLoader/init.py", line 9, in create_dataloader loader = eval(code_line) File "", line 1, in File "/home/zhy/PyProject/Python-VO/DataLoader/TUMRGBLoader.py", line 32, in init self.read_imgs() File "/home/zhy/PyProject/Python-VO/DataLoader/TUMRGBLoader.py", line 76, in read_imgs rgb_list = lines[:, 1] IndexError: too many indices for array

I use this code for running: python main.py --config params/tumrgb_superpoint_supergluematch.yaml

The TUM dataset is organized as follows: ├ TUM └rgbd_dataset_freiburg1_360    └── depth └ ...    └── rgb └ ...    └── depth.txt    └── rgb.txt    └── rgbd_gt.txt

How to fix this error?

Shiaoming commented 3 years ago

it's probably the rgbd_gt.txt is incomplete.

make sure the rgbd_gt.txt contains the correct file paths and gt poses like this:

# rgbd with groundtruth
# timestamp rgb_filename depth_filename tx ty tz qx qy qz qw
1305031790.645155 rgb/1305031790.645155.png depth/1305031790.640468.png 0.4388 -0.4332 1.4779 0.8596 -0.3534 0.0838 -0.3594
1305031790.681208 rgb/1305031790.681208.png depth/1305031790.672866.png 0.4389 -0.4402 1.4698 0.8628 -0.3571 0.0780 -0.3492
1305031790.713097 rgb/1305031790.713097.png depth/1305031790.709421.png 0.4390 -0.4459 1.4644 0.8651 -0.3609 0.0735 -0.3406
1305031790.745223 rgb/1305031790.745223.png depth/1305031790.739530.png 0.4393 -0.4516 1.4593 0.8654 -0.3660 0.0699 -0.3350
1305031790.781258 rgb/1305031790.781258.png depth/1305031790.773548.png 0.4404 -0.4592 1.4530 0.8661 -0.3748 0.0642 -0.3244
zhanghua7099 commented 3 years ago

Thank you for your reply.

By the way, TUM dataset didn't provide this format's groundtruth file. The gt file is collected by motion capture systems, its timestamp is different from the associate file containing RGB and depth. It may be serious to generate the rgbd_gt.txt you mentioned.

Shiaoming commented 3 years ago

@zhanghua7099

I use the code below along with associate.py provided by TUM dataset to generate rgbd_gt.txt:

import argparse
import os
import sys

LOCAL_PATH = './'
if LOCAL_PATH not in sys.path:
    sys.path.append(LOCAL_PATH)

from associate import associate, read_file_list
from tqdm import tqdm

def associate_two_files(fname1, fname2, outname, filehead):
    fname1_list = read_file_list(fname1)
    fname2_list = read_file_list(fname2)

    fname1_fname2_matches = associate(fname1_list, fname2_list, float(args.offset), float(args.max_difference))

    with open(outname, 'w') as f:
        f.write(filehead)
        for a, b in fname1_fname2_matches:
            f.write("%f %s %s\n" % (a, " ".join(fname1_list[a]), " ".join(fname2_list[b])))

if __name__ == '__main__':
    # parse command line
    parser = argparse.ArgumentParser(
        description='''This script associate the rgb.txt, depth.txt, groundtruth.txt for all tumrgbd data sequences''')
    parser.add_argument('root_path', help='first text file (format: timestamp data)')
    parser.add_argument('--offset', help='time offset added to the timestamps of the second file (default: 0.0)',
                        default=0.0)
    parser.add_argument('--max_difference',
                        help='maximally allowed time difference for matching entries (default: 0.02)', default=0.02)
    args = parser.parse_args()

    for sequence_name in tqdm(os.listdir(args.root_path)):
        rgbd = os.path.join(args.root_path, sequence_name, 'rgbd.txt')
        if not os.path.exists(rgbd):
            rgb = os.path.join(args.root_path, sequence_name, 'rgb.txt')
            depth = os.path.join(args.root_path, sequence_name, 'depth.txt')
            associate_two_files(rgb, depth, rgbd, '# rgbd\n'
                                                  '# timestamp rgb_filename depth_filename\n')

        rgbd_gt = os.path.join(args.root_path, sequence_name, 'rgbd_gt.txt')
        if not os.path.exists(rgbd_gt):
            gt = os.path.join(args.root_path, sequence_name, 'groundtruth.txt')
            associate_two_files(rgbd, gt, rgbd_gt, '# rgbd with groundtruth\n'
                                                   '# timestamp rgb_filename depth_filename tx ty tz qx qy qz qw\n')
zhubingerdai commented 1 year ago

你们好,我想请教下问题,为什么我按照这个格式跑TUM数据集: print(i, t[0, 0], t[1, 0], t[2, 0], gt_pose[0, 3], gt_pose[1, 3], gt_pose[2, 3], file=log_fopen) img1 = keypoints_plot(img, vo) img2 = traj_plotter.update(t, gt_pose[:, 3]) img2只有一个点,t的值是0,最后生成的result是这样的: 0 0.0 0.0 0.0 1.686 -0.8133 0.0353 0 0.0 0.0 0.0 1.686 -0.8133 0.0353 0 0.0 0.0 0.0 1.686 -0.8133 0.0353 0 0.0 0.0 0.0 1.686 -0.8133 0.0353 0 0.0 0.0 0.0 1.686 -0.8133 0.0353 0 0.0 0.0 0.0 1.686 -0.8133 0.0353 0 0.0 0.0 0.0 1.686 -0.8133 0.0353 0 0.0 0.0 0.0 1.686 -0.8133 0.0353 这是什么问题???