Remove obsolete implementation and simplify project structure

This commit is contained in:
2026-08-21 09:46:50 +08:00
parent b5a2f9690c
commit af5603045c
100 changed files with 365 additions and 365 deletions

View File

@@ -0,0 +1,10 @@
from .depth import write_da3_depth, write_moge_depth
from .surface import write_normal_texture, write_surface_archive
__all__ = (
"write_da3_depth",
"write_moge_depth",
"write_normal_texture",
"write_surface_archive",
)

View File

@@ -0,0 +1,24 @@
from pathlib import Path
def write_prediction(prediction, output_path):
import numpy as np
values = {}
for name in (
"depth",
"conf",
"extrinsics",
"intrinsics",
"processed_images",
"is_metric",
"sky",
"scale_factor",
):
value = getattr(prediction, name, None)
if value is not None:
values[name] = np.asarray(value)
output_path = Path(output_path)
output_path.parent.mkdir(parents=True, exist_ok=True)
np.savez(output_path, **values)
return output_path

View File

@@ -0,0 +1,13 @@
from pathlib import Path
def write_prediction(prediction, output_path):
import numpy as np
output_path = Path(output_path)
output_path.parent.mkdir(parents=True, exist_ok=True)
np.savez(
output_path,
**{name: np.asarray(value) for name, value in prediction.items()},
)
return output_path

View File

@@ -0,0 +1,64 @@
from pathlib import Path
from .surface import write_normal_texture
def write_da3_depth(prediction, output_path):
import numpy as np
values = {"depth": np.round(prediction.depth, 8)}
for name in ("conf", "extrinsics", "intrinsics"):
value = getattr(prediction, name, None)
if value is not None:
values[name] = np.round(value, 2) if name == "conf" else value
output_path = Path(output_path)
output_path.parent.mkdir(parents=True, exist_ok=True)
np.savez_compressed(output_path, **values)
return output_path
def write_moge_depth(output_directory, prediction):
import numpy as np
output_directory = Path(output_directory)
np.savez(
output_directory / "results.npz",
**prediction.archive_values(),
)
for index, (depth, normal, mask) in enumerate(
zip(prediction.depth, prediction.normal, prediction.mask)
):
_write_moge_maps(
output_directory,
None if len(prediction.depth) == 1 else index,
depth,
normal,
mask,
)
def _write_moge_maps(output_directory, index, depth, normal, mask):
import numpy as np
from PIL import Image
suffix = "" if index is None else f".{index + 1:04d}"
valid = mask & np.isfinite(depth) & (depth > 0)
preview = np.zeros(depth.shape, dtype=np.uint8)
if np.any(valid):
low, high = np.percentile(depth[valid], (2.0, 98.0))
span = max(float(high - low), 1e-6)
preview[valid] = np.clip(
(depth[valid] - low) / span * 255.0,
0.0,
255.0,
).astype(np.uint8)
Image.fromarray(preview, mode="L").save(
output_directory / f"depth{suffix}.png"
)
write_normal_texture(
normal,
output_directory / f"normal{suffix}.png",
)
Image.fromarray(mask.astype(np.uint8) * 255, mode="L").save(
output_directory / f"mask{suffix}.png"
)

View File

@@ -0,0 +1,35 @@
from pathlib import Path
def write_surface_archive(mesh, output_path):
import numpy as np
output_path = Path(output_path)
output_path.parent.mkdir(parents=True, exist_ok=True)
np.savez_compressed(
output_path,
vertices=mesh.vertices,
faces=mesh.faces,
uv=mesh.uv,
intrinsics=mesh.intrinsics,
image_size=np.asarray(mesh.image_size, dtype=np.int32),
reference_depth=np.asarray(mesh.reference_depth, dtype=np.float32),
**mesh.point_attributes,
**mesh.face_attributes,
)
return output_path
def write_normal_texture(normal, output_path):
import numpy as np
from PIL import Image
normal_rgb = np.clip(
(normal * np.array([1.0, -1.0, -1.0], dtype=np.float32) + 1.0)
* 127.5,
0.0,
255.0,
).astype(np.uint8)
output_path = Path(output_path)
Image.fromarray(normal_rgb, mode="RGB").save(output_path)
return output_path