sxyu / svox2

Plenoxels: Radiance Fields without Neural Networks
BSD 2-Clause "Simplified" License
2.79k stars 359 forks source link

view_data.py with custom dataset - error with `seg` indexing implementation #9

Closed phelps-matthew closed 2 years ago

phelps-matthew commented 2 years ago

Upon defining a dataset of images and running bash proc_colmap.sh, when running view_data.py I get an error when trying to pass an empty rotation matrix to scene.add_camera_frustrum from the nerfvis library. The error stems from a faulty list of segs as defined in view_data.py

    all_poses = []
    pnum, seg_begin = None, 0
    segs = []
    for i, pose_file in enumerate(pose_files):
        pose = np.loadtxt(path.join(pose_dir, pose_file)).reshape(4, 4)
        splt = path.splitext(pose_file)[0].split('_')
        num = int(splt[1] if len(splt) > 1 else splt[0])
        if pnum is not None and num - pnum > 1 and seg_begin < num:
            segs.append((seg_begin, num))
            seg_begin = num
        pnum = num
        all_poses.append(pose)
    all_poses = np.stack(all_poses)
    segs.append((seg_begin, len(pose_files)))

Specifically, segs appears to be a list of 2-tuples corresponding to the connection between two pose matrices. Given my pose directory contents of

├── 0_00019.txt
├── 0_00095.txt
├── 0_00107.txt
├── 0_00134.txt
├── 0_00140.txt
├── 0_00143.txt
├── 0_00169.txt
├── 0_00187.txt
├── 0_00191.txt
├── 0_00197.txt
├── 0_00200.txt
├── 0_00212.txt
├── 0_00242.txt
├── 0_00251.txt
├── 0_00252.txt
├── 0_00260.txt
├── 0_00291.txt
├── 1_00017.txt
└── 1_00259.txt

segs evaluates to

[(0, 19), (19, 95), (95, 107), (107, 134), (134, 140), (140, 143), (143, 169), (169, 187), (187, 191), (191, 197), (197, 200), (200, 212), (212, 242), (242, 251), (251, 259), (259, 291), (291, 19)]

In the following loop

    for i, seg in enumerate(segs):
        print(seg)
        print(R.shape, t.shape)
        print(seg[0], seg[1])
        scene.add_camera_frustum(name=f"traj_{i:04d}", focal_length=focal,
                                 image_width=image_wh[0],
                                 image_height=image_wh[1],
                                 z=0.1,
                                 r=R[seg[0]:seg[1]],
                                 t=t[seg[0]:seg[1]],
                                 connect=args.seg,
                                 color=[1.0, 0.0, 0.0])

The indexing of R and t thus yield errors.

Just to get it running, I changed seg to an incremental list like [(0, 1), (1, 2), ... (n-1, n)], but I'm not sure what the original intention was here as the logic was unclear to me.

sxyu commented 2 years ago

Hi, sorry about the error. I took this visualizer script from some other code I was working on and did not test thoroughly. Let me take a look

sxyu commented 2 years ago

I just removed the seg logic entirely, so it should be fine now. Originally I was working with video data, so this draws a line through the cameras, but breaks up the line when the numbering becomes non-consecutive. However when I adapted the code I broke it.

phelps-matthew commented 2 years ago

No worries! Thank you for taking a look and updating :)