Spaces:
Sleeping
Sleeping
Update gaussian_pipeline.py
Browse files- gaussian_pipeline.py +27 -6
gaussian_pipeline.py
CHANGED
|
@@ -1,21 +1,42 @@
|
|
| 1 |
-
from spaces import GPU #
|
| 2 |
|
| 3 |
@GPU()
|
| 4 |
def reconstruct_3d_gaussian(keyframes, output_dir, device="cpu"):
|
| 5 |
import os
|
| 6 |
-
import trimesh
|
| 7 |
import numpy as np
|
|
|
|
|
|
|
| 8 |
from sklearn.decomposition import PCA
|
| 9 |
|
| 10 |
points_3d = []
|
|
|
|
| 11 |
for frame_path in keyframes:
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
pca = PCA(n_components=3)
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
|
|
|
|
|
|
|
|
|
|
| 19 |
output_model_path = os.path.join(output_dir, "reconstructed_model.obj")
|
| 20 |
mesh.export(output_model_path)
|
| 21 |
|
|
|
|
| 1 |
+
from spaces import GPU # Hugging Face Spaces์์ GPU ์ฌ์ฉ
|
| 2 |
|
| 3 |
@GPU()
|
| 4 |
def reconstruct_3d_gaussian(keyframes, output_dir, device="cpu"):
|
| 5 |
import os
|
|
|
|
| 6 |
import numpy as np
|
| 7 |
+
import cv2
|
| 8 |
+
import trimesh
|
| 9 |
from sklearn.decomposition import PCA
|
| 10 |
|
| 11 |
points_3d = []
|
| 12 |
+
|
| 13 |
for frame_path in keyframes:
|
| 14 |
+
# ์ด๋ฏธ์ง ๋ก๋
|
| 15 |
+
image = cv2.imread(frame_path, cv2.IMREAD_GRAYSCALE)
|
| 16 |
+
if image is None:
|
| 17 |
+
continue # ์ด๋ฏธ์ง ๋ก๋ ์คํจ ์ ์คํต
|
| 18 |
+
|
| 19 |
+
# ์๊ณ๊ฐ์ ๊ธฐ์ค์ผ๋ก ํฝ์
์์น ์ถ์ถ (๋ฐ์ ํฝ์
๋ง)
|
| 20 |
+
ys, xs = np.where(image > 128)
|
| 21 |
+
pixels = np.stack([xs, ys], axis=-1)
|
| 22 |
+
|
| 23 |
+
if len(pixels) < 3:
|
| 24 |
+
continue # PCA์ ํ์ํ ์ต์ ์ฐจ์ ๋ถ์กฑ ์ ์คํต
|
| 25 |
+
|
| 26 |
+
# PCA๋ก 2D โ 3D ๋ณํ
|
| 27 |
pca = PCA(n_components=3)
|
| 28 |
+
points_3d_frame = pca.fit_transform(pixels)
|
| 29 |
+
points_3d.append(points_3d_frame)
|
| 30 |
+
|
| 31 |
+
if not points_3d:
|
| 32 |
+
raise ValueError("No valid 3D points were reconstructed.")
|
| 33 |
|
| 34 |
+
# ๋ชจ๋ ํ๋ ์ ํฌ์ธํธ ๋ณํฉ
|
| 35 |
+
all_points = np.concatenate(points_3d, axis=0)
|
| 36 |
|
| 37 |
+
# 3D ํฌ์ธํธ ํด๋ผ์ฐ๋๋ก ์ ์ฅ
|
| 38 |
+
mesh = trimesh.points.PointCloud(all_points)
|
| 39 |
+
os.makedirs(output_dir, exist_ok=True)
|
| 40 |
output_model_path = os.path.join(output_dir, "reconstructed_model.obj")
|
| 41 |
mesh.export(output_model_path)
|
| 42 |
|