shin0624 commited on
Commit
5c12344
ยท
verified ยท
1 Parent(s): 4fb583f

Create pointcloud_tools.py

Browse files
Files changed (1) hide show
  1. utils/pointcloud_tools.py +41 -0
utils/pointcloud_tools.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # utils/pointcloud_tools.py
2
+ import numpy as np
3
+ import trimesh
4
+ from typing import List
5
+
6
+ class PointCloudProcessor:
7
+ @staticmethod
8
+ def normalize_points(points: np.ndarray) -> np.ndarray:
9
+ """ํฌ์ธํŠธ ํด๋ผ์šฐ๋“œ ์ •๊ทœํ™”"""
10
+ if len(points) == 0:
11
+ return points
12
+
13
+ # Z-score ์ •๊ทœํ™”
14
+ mean = np.mean(points, axis=0)
15
+ std = np.std(points, axis=0)
16
+ return (points - mean) / (std + 1e-8)
17
+
18
+ @staticmethod
19
+ def filter_outliers(points: np.ndarray, z_thresh=3.0) -> np.ndarray:
20
+ """์ด์ƒ์น˜ ์ œ๊ฑฐ"""
21
+ if len(points) == 0:
22
+ return points
23
+
24
+ z_scores = np.abs((points - np.mean(points, axis=0)) / np.std(points, axis=0)
25
+ return points[(z_scores < z_thresh).all(axis=1)]
26
+
27
+ @staticmethod
28
+ def create_mesh(points: np.ndarray) -> trimesh.Trimesh:
29
+ """ํฌ์ธํŠธ ํด๋ผ์šฐ๋“œ์—์„œ ๋ฉ”์‹œ ์ƒ์„ฑ"""
30
+ return trimesh.points.PointCloud(points)
31
+
32
+ @staticmethod
33
+ def merge_pointclouds(clouds: List[np.ndarray]) -> np.ndarray:
34
+ """๋‹ค์ค‘ ํฌ์ธํŠธ ํด๋ผ์šฐ๋“œ ๋ณ‘ํ•ฉ"""
35
+ return np.vstack(clouds) if clouds else np.array([])
36
+
37
+ @staticmethod
38
+ def save_as_obj(points: np.ndarray, filename: str):
39
+ """OBJ ํŒŒ์ผ๋กœ ์ €์žฅ"""
40
+ mesh = trimesh.points.PointCloud(points)
41
+ mesh.export(filename)