Upload examples/quickstart.py
Browse files- examples/quickstart.py +29 -0
examples/quickstart.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Quick-start: single image → metric depth → point cloud in 10 lines.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
from depthpro_wrapper import (
|
| 7 |
+
DepthProEstimator,
|
| 8 |
+
rgbd_to_point_cloud,
|
| 9 |
+
save_point_cloud,
|
| 10 |
+
)
|
| 11 |
+
|
| 12 |
+
# 1. Load estimator (downloads ~2 GB weights on first run)
|
| 13 |
+
estimator = DepthProEstimator(device="cuda:0")
|
| 14 |
+
|
| 15 |
+
# 2. Estimate depth
|
| 16 |
+
result = estimator.estimate("photo.jpg")
|
| 17 |
+
print(f"Focal length: {result.focal_length:.1f} px")
|
| 18 |
+
print(f"Depth range: {result.depth.min():.2f} – {result.depth.max():.2f} m")
|
| 19 |
+
|
| 20 |
+
# 3. Back-project to coloured point cloud
|
| 21 |
+
points, colors = rgbd_to_point_cloud(
|
| 22 |
+
result.depth,
|
| 23 |
+
result.image,
|
| 24 |
+
result.focal_length,
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
# 4. Save
|
| 28 |
+
save_point_cloud("output.ply", points, colors=colors)
|
| 29 |
+
print(f"Saved {len(points):,} points to output.ply")
|