Spaces:
Sleeping
Sleeping
Create pointcloud_tools.py
Browse files- 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)
|