Upload examples/batch_processing.py
Browse files- examples/batch_processing.py +29 -0
examples/batch_processing.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Batch-processing example: estimate depth for a folder of images and export
|
| 3 |
+
point clouds with one call.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
from depthpro_wrapper import DepthProEstimator, rgbd_to_point_cloud, save_point_cloud
|
| 8 |
+
|
| 9 |
+
image_dir = Path("photos/")
|
| 10 |
+
output_dir = Path("pointclouds/")
|
| 11 |
+
output_dir.mkdir(exist_ok=True)
|
| 12 |
+
|
| 13 |
+
estimator = DepthProEstimator(device="cuda:0")
|
| 14 |
+
|
| 15 |
+
# Batch size = 4 is a sweet spot for most GPUs
|
| 16 |
+
image_paths = sorted(image_dir.glob("*.jpg"))
|
| 17 |
+
for i in range(0, len(image_paths), 4):
|
| 18 |
+
batch_paths = image_paths[i : i + 4]
|
| 19 |
+
results = estimator.estimate_batch(batch_paths)
|
| 20 |
+
|
| 21 |
+
for path, result in zip(batch_paths, results):
|
| 22 |
+
points, colors = rgbd_to_point_cloud(
|
| 23 |
+
result.depth,
|
| 24 |
+
result.image,
|
| 25 |
+
result.focal_length,
|
| 26 |
+
)
|
| 27 |
+
out_path = output_dir / f"{path.stem}.ply"
|
| 28 |
+
save_point_cloud(out_path, points, colors=colors)
|
| 29 |
+
print(f" {path.name} → {out_path} ({len(points):,} pts)")
|