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

Update gaussian_pipeline.py

Browse files
Files changed (1) hide show
  1. 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 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)
 
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)