Spaces:
Running
Running
File size: 2,111 Bytes
404d2af 8b973ee 404d2af 8b973ee 404d2af 8b973ee 404d2af 8b973ee 404d2af 8b973ee 404d2af 8b973ee 404d2af 8b973ee 404d2af 8b973ee 404d2af 8b973ee 404d2af 8b973ee |
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 |
import argparse
import imagesize
import os
import subprocess
parser = argparse.ArgumentParser(description="MegaDepth Undistortion")
parser.add_argument(
"--colmap_path", type=str, default="/usr/bin/", help="path to colmap executable"
)
parser.add_argument(
"--base_path", type=str, default="/root/MegaDepth", help="path to MegaDepth"
)
args = parser.parse_args()
sfm_path = os.path.join(args.base_path, "MegaDepth_v1_SfM")
base_depth_path = os.path.join(args.base_path, "phoenix/S6/zl548/MegaDepth_v1")
output_path = os.path.join(args.base_path, "Undistorted_SfM")
os.mkdir(output_path)
for scene_name in os.listdir(base_depth_path):
current_output_path = os.path.join(output_path, scene_name)
os.mkdir(current_output_path)
image_path = os.path.join(base_depth_path, scene_name, "dense0", "imgs")
if not os.path.exists(image_path):
continue
# Find the maximum image size in scene.
max_image_size = 0
for image_name in os.listdir(image_path):
max_image_size = max(
max_image_size, max(imagesize.get(os.path.join(image_path, image_name)))
)
# Undistort the images and update the reconstruction.
subprocess.call(
[
os.path.join(args.colmap_path, "colmap"),
"image_undistorter",
"--image_path",
os.path.join(sfm_path, scene_name, "images"),
"--input_path",
os.path.join(sfm_path, scene_name, "sparse", "manhattan", "0"),
"--output_path",
current_output_path,
"--max_image_size",
str(max_image_size),
]
)
# Transform the reconstruction to raw text format.
sparse_txt_path = os.path.join(current_output_path, "sparse-txt")
os.mkdir(sparse_txt_path)
subprocess.call(
[
os.path.join(args.colmap_path, "colmap"),
"model_converter",
"--input_path",
os.path.join(current_output_path, "sparse"),
"--output_path",
sparse_txt_path,
"--output_type",
"TXT",
]
)
|