shin0624 commited on
Commit
744fb89
ยท
verified ยท
1 Parent(s): aa6b6af

Update gaussian_pipeline.py

Browse files
Files changed (1) hide show
  1. gaussian_pipeline.py +27 -6
gaussian_pipeline.py CHANGED
@@ -1,21 +1,42 @@
1
- from spaces import GPU # huggingface_hub ํŒจํ‚ค์ง€์—์„œ ์ œ๊ณต๋จ
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
- image = trimesh.load(frame_path)
 
 
 
 
 
 
 
 
 
 
 
 
13
  pca = PCA(n_components=3)
14
- points_3d.append(pca.fit_transform(image.vertices))
 
 
 
 
15
 
16
- points_3d = np.concatenate(points_3d, axis=0)
17
- mesh = trimesh.points.PointCloud(points_3d)
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