Spaces:
Sleeping
Sleeping
Update gaussian_pipeline.py
Browse files- gaussian_pipeline.py +11 -11
gaussian_pipeline.py
CHANGED
|
@@ -11,31 +11,31 @@ def reconstruct_3d_gaussian(keyframes, output_dir, device="cpu"):
|
|
| 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
|
| 24 |
-
continue
|
| 25 |
|
| 26 |
-
#
|
| 27 |
pca = PCA(n_components=3)
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|
|
|
|
| 11 |
points_3d = []
|
| 12 |
|
| 13 |
for frame_path in keyframes:
|
|
|
|
| 14 |
image = cv2.imread(frame_path, cv2.IMREAD_GRAYSCALE)
|
| 15 |
if image is None:
|
| 16 |
+
continue
|
| 17 |
|
|
|
|
| 18 |
ys, xs = np.where(image > 128)
|
| 19 |
pixels = np.stack([xs, ys], axis=-1)
|
| 20 |
|
| 21 |
+
if pixels.shape[0] < 3: # ์ต์ 3๊ฐ ํฌ์ธํธ ์์ผ๋ฉด PCA ์คํจ
|
| 22 |
+
continue
|
| 23 |
|
| 24 |
+
# 2D โ 3D PCA
|
| 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.concatenate(points_3d, axis=0)
|
|
|
|
|
|
|
| 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, "reconstructed_model.obj")
|
| 41 |
mesh.export(output_model_path)
|