File size: 2,635 Bytes
2df809d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import subprocess
import os
import argparse
import glob


def get_parser():
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--mapfree_dir",
        default="mapfree/train/",
    )
    parser.add_argument(
        "--colmap_dir",
        default="mapfree/colmap",
    )
    parser.add_argument(
        "--output_dir",
        default="processed_mapfree",
    )
    return parser


def run_patch_match_stereo(root_colmap_dir, root_img_dir):
    scene_names = sorted(os.listdir(root_colmap_dir))
    sub_dir_names = ["seq0", "seq1"]
    for scene_name in scene_names:
        scene_dir = os.path.join(root_colmap_dir, scene_name)
        img_dir = os.path.join(root_img_dir, scene_name)
        for i, sub in enumerate(sub_dir_names):
            sub_dir = os.path.join(scene_dir, sub)
            out_dir = os.path.join(scene_dir, f"dense{i}")
            if not os.path.exists(sub_dir):
                continue
            if os.path.exists(out_dir) and os.path.exists(
                os.path.join(out_dir, f"stereo/depth_maps/{sub}")
            ):
                if len(
                    glob.glob(
                        os.path.join(out_dir, f"stereo/depth_maps/{sub}/*geometric.bin")
                    )
                ) == len(glob.glob(os.path.join(img_dir, sub, "*.jpg"))):
                    print(f"depth maps already computed, skip {sub_dir}")
                    continue

            print(sub_dir)
            cmd = f"colmap image_undistorter \
                    --image_path {img_dir} \
                    --input_path {sub_dir} \
                    --output_path {out_dir} \
                    --output_type COLMAP;"

            subprocess.call(cmd, shell=True)
            cmd = f"rm -rf {out_dir}/images/seq{i}; rm -rf {out_dir}/sparse;"
            cmd += f"cp -r {sub_dir} {out_dir}/sparse;"
            cmd += f"cp -r {img_dir}/{sub} {out_dir}/images;"
            subprocess.call(cmd, shell=True)

            # we comment this because we have released the mvs results, but feel free to re-run the mvs

            # cmd = f"colmap patch_match_stereo \
            #         --workspace_path {out_dir} \
            #         --workspace_format COLMAP \
            #         --PatchMatchStereo.cache_size 512 \
            #         --PatchMatchStereo.geom_consistency true"
            # subprocess.call(cmd, shell=True)


if __name__ == "__main__":
    parser = get_parser()
    args = parser.parse_args()
    root_colmap_dir = args.colmap_dir
    root_img_dir = args.mapfree_dir

    # run patch match stereo
    run_patch_match_stereo(root_colmap_dir, root_img_dir)