-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexec_model.py
More file actions
99 lines (85 loc) · 4.86 KB
/
exec_model.py
File metadata and controls
99 lines (85 loc) · 4.86 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import sys
import argparse
sys.path.append(".")
import add_noise
from alicevision import AliceVision
from colmap import Colmap
from fast_dipole_sums import FDS
from sdfstudio import SDFStudio
def parse_error_threshold(error_str):
if error_str.endswith("%"):
# Relative error (percentage)
return False, float(error_str.rstrip("%")) / 100.0
else:
# Absolute error
return True, float(error_str)
def parse_noise(conf):
parts = conf.split("#")
noise_type = parts[0]
if noise_type == "none":
return {"type": "none"}
elif noise_type == "gaussian":
return {"type": "gaussian", "mean": float(parts[1]), "var": float(parts[2])}
elif noise_type == "salt_pepper":
return {"type": "salt_pepper", "prob": float(parts[1])}
else:
raise ValueError(f"Noise type {noise_type} not recognized")
def str2bool(v):
if isinstance(v, bool):
return v
if v.lower() in ("yes", "true", "t", "y", "1"):
return True
elif v.lower() in ("no", "false", "f", "n", "0"):
return False
else:
raise argparse.ArgumentTypeError("Boolean value expected.")
def reconstruct(method, reconstruct, mono_prior, inside, input_dir, out_dir, error_threshold, use_icp, use_global_icp, export_csv, image_noise):
noise_conf = parse_noise(image_noise)
if noise_conf["type"] == "gaussian":
add_noise.gaussian_noise(f"{input_dir}/render",mean=noise_conf["mean"],var=noise_conf["var"])
elif noise_conf["type"] == "salt_pepper":
add_noise.salt_and_pepper_noise(f"{input_dir}/render",prob=noise_conf["prob"])
if method == "alice":
selected_method = AliceVision(input_dir, out_dir, "config.ini")
elif method == "colmap":
selected_method = Colmap(input_dir, out_dir, "config.ini")
elif method == "fds":
selected_method = FDS(input_dir, out_dir, "config.ini", inside)
elif method == "nerfacto":
selected_method = SDFStudio(input_dir, out_dir, "config.ini", "nerfacto")
elif method == "bakedsdf":
selected_method = SDFStudio(input_dir, out_dir, "config.ini", "bakedsdf")
else:
raise ValueError(f"Method {method} not recognized")
if reconstruct:
if method in ["nerfacto", "bakedsdf"]:
selected_method.run(mono_prior=mono_prior, inside=inside, noise=noise_conf["type"])
else:
selected_method.run(noise=noise_conf["type"])
is_absolute, error_value = parse_error_threshold(error_threshold)
if method in ["nerfacto", "bakedsdf"]:
selected_method.compute_stats(export_csv=export_csv,neural=True,absolute_d=is_absolute,d=error_value)
else:
selected_method.compute_stats(use_icp=use_icp, use_global_icp=use_global_icp, export_csv=export_csv,absolute_d=is_absolute,d=error_value)
selected_method.print_errors(absolute_d=is_absolute)
def main():
parser = argparse.ArgumentParser(description="Main interface for executing the photogrammetry pipeline")
parser.add_argument("--method", type=str, required=True, help="Method to use for reconstruction. alice,colmap,fds,nerfacto,bakedsdf")
parser.add_argument("--input_dir", type=str, required=True, help="Directory containing input scene")
parser.add_argument("--out_dir", type=str, required=True, help="Path to output directory")
parser.add_argument("--error_threshold", type=str, required=True, help="Error threshold for mesh export. Use 0.05% for relative error of 5% or 0.01 for absolute error of 0.01 units")
parser.add_argument("--reconstruct", type=str2bool, required=True, help="[True] for whole process, [False] just for metrics")
parser.add_argument("--mono_prior", type=str2bool, default=False, help="Whether to use mono prior for neural methods. Option for bakedsdf")
parser.add_argument("--inside", type=str2bool, default=True, help="Whether the reconstruction is inside a room (True), or it is a single object outside (False). Option for bakedsdf")
parser.add_argument("--use_icp", type=str2bool, default=False, help="Whether to use ICP for alignment")
parser.add_argument("--use_global_icp", type=str2bool, default=False, help="Whether to use global ICP for alignment")
parser.add_argument("--image_noise", type=str, default="none", help="Whether to use (gaussian#mean#variance, salt_pepper#prob, none) noise in the training images")
parser.add_argument("--export_csv", type=str2bool, default=True, help="Whether to export results as CSV")
args = parser.parse_args()
print(f"Running reconstruction using {args.method} on images in {args.input_dir}")
reconstruct(args.method, args.reconstruct, args.mono_prior, args.inside,
args.input_dir, args.out_dir, args.error_threshold,
args.use_icp, args.use_global_icp, args.export_csv, args.image_noise)
print("Reconstruction complete!")
if __name__ == "__main__":
main()