Spaces:
Sleeping
Sleeping
File size: 1,723 Bytes
5c12344 bfe81cc 5c12344 bfe81cc 5c12344 bfe81cc 5c12344 bfe81cc 5c12344 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | # utils/pointcloud_tools.py
import numpy as np
import trimesh
from typing import List
class PointCloudProcessor:
@staticmethod
def normalize_points(points: np.ndarray) -> np.ndarray:
"""ํฌ์ธํธ ํด๋ผ์ฐ๋ ์ ๊ทํ"""
if len(points) == 0:
return points
# Z-score ์ ๊ทํ
mean = np.mean(points, axis=0)
std = np.std(points, axis=0)
# ํ์คํธ์ฐจ๊ฐ 0์ธ ๊ฒฝ์ฐ ๋๋น
std = np.where(std < 1e-8, 1, std)
return (points - mean) / std
@staticmethod
def filter_outliers(points: np.ndarray, z_thresh=3.0) -> np.ndarray:
"""์ด์์น ์ ๊ฑฐ"""
if len(points) == 0:
return points
if len(points) <= 3: # ํฌ์ธํธ๊ฐ ๋๋ฌด ์ ์ผ๋ฉด ํํฐ๋ง ์๋ต
return points
z_scores = np.abs(points - np.mean(points, axis=0)) / (np.std(points, axis=0) + 1e-8)
mask = (z_scores < z_thresh).all(axis=1)
# ๋ชจ๋ ํฌ์ธํธ๊ฐ ํํฐ๋ง๋์ง ์๋๋ก ๋ณดํธ
if not np.any(mask):
return points
return points[mask]
@staticmethod
def create_mesh(points: np.ndarray) -> trimesh.Trimesh:
"""ํฌ์ธํธ ํด๋ผ์ฐ๋์์ ๋ฉ์ฌ ์์ฑ"""
return trimesh.points.PointCloud(points)
@staticmethod
def merge_pointclouds(clouds: List[np.ndarray]) -> np.ndarray:
"""๋ค์ค ํฌ์ธํธ ํด๋ผ์ฐ๋ ๋ณํฉ"""
return np.vstack(clouds) if clouds else np.array([])
@staticmethod
def save_as_obj(points: np.ndarray, filename: str):
"""OBJ ํ์ผ๋ก ์ ์ฅ"""
mesh = trimesh.points.PointCloud(points)
mesh.export(filename) |