Spaces:
Sleeping
Sleeping
Update gaussian_pipeline.py
Browse files- gaussian_pipeline.py +19 -24
gaussian_pipeline.py
CHANGED
|
@@ -1,43 +1,38 @@
|
|
| 1 |
from spaces import GPU # Hugging Face Spaces์์ GPU ์ฌ์ฉ
|
| 2 |
|
| 3 |
@GPU()
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
|
| 11 |
points_3d = []
|
| 12 |
|
| 13 |
-
for frame_path in
|
| 14 |
-
image = cv2.imread(frame_path
|
| 15 |
if image is None:
|
| 16 |
continue
|
| 17 |
|
| 18 |
-
|
| 19 |
-
pixels = np.stack([xs, ys], axis=-1)
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
pca = PCA(n_components=3)
|
| 26 |
-
try:
|
| 27 |
-
points_3d_frame = pca.fit_transform(pixels)
|
| 28 |
-
points_3d.append(points_3d_frame)
|
| 29 |
-
except Exception as e:
|
| 30 |
-
print(f"PCA failed on {frame_path}: {e}")
|
| 31 |
-
continue
|
| 32 |
|
| 33 |
if not points_3d:
|
| 34 |
-
raise ValueError("No valid 3D points were reconstructed.")
|
| 35 |
|
| 36 |
-
all_points = np.
|
| 37 |
mesh = trimesh.points.PointCloud(all_points)
|
| 38 |
|
| 39 |
os.makedirs(output_dir, exist_ok=True)
|
| 40 |
-
output_model_path = os.path.join(output_dir, "
|
| 41 |
mesh.export(output_model_path)
|
| 42 |
|
| 43 |
return output_model_path
|
|
|
|
|
|
| 1 |
from spaces import GPU # Hugging Face Spaces์์ GPU ์ฌ์ฉ
|
| 2 |
|
| 3 |
@GPU()
|
| 4 |
+
from ultralytics import YOLO
|
| 5 |
+
import numpy as np
|
| 6 |
+
import cv2
|
| 7 |
+
import os
|
| 8 |
+
import trimesh
|
| 9 |
+
|
| 10 |
+
def reconstruct_3d_from_yolo(frames, output_dir, device="cuda"):
|
| 11 |
+
model = YOLO("yolov8n.pt") # ๊ฒฝ๋ ๋ชจ๋ธ ์ฌ์ฉ
|
| 12 |
|
| 13 |
points_3d = []
|
| 14 |
|
| 15 |
+
for idx, frame_path in enumerate(frames):
|
| 16 |
+
image = cv2.imread(frame_path)
|
| 17 |
if image is None:
|
| 18 |
continue
|
| 19 |
|
| 20 |
+
results = model(image)[0]
|
|
|
|
| 21 |
|
| 22 |
+
for box in results.boxes.xywh: # ์ค์ฌ ์ขํ (x_center, y_center, width, height)
|
| 23 |
+
x, y, w, h = box[:4].cpu().numpy()
|
| 24 |
+
z = idx * 10 # ํ๋ ์ ์์์ ๋ฐ๋ผ z๊ฐ ์ฆ๊ฐ์์ผ ๊ฐ์์ ๊น์ด ๋ถ์ฌ
|
| 25 |
+
points_3d.append([x, y, z])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
if not points_3d:
|
| 28 |
+
raise ValueError("No valid YOLO 3D points were reconstructed.")
|
| 29 |
|
| 30 |
+
all_points = np.array(points_3d)
|
| 31 |
mesh = trimesh.points.PointCloud(all_points)
|
| 32 |
|
| 33 |
os.makedirs(output_dir, exist_ok=True)
|
| 34 |
+
output_model_path = os.path.join(output_dir, "yolo_3d_model.obj")
|
| 35 |
mesh.export(output_model_path)
|
| 36 |
|
| 37 |
return output_model_path
|
| 38 |
+
|