Spaces:
Sleeping
Sleeping
3D 포인트 클라우드 생성
Browse files- detector/yolo_pipeline.py +35 -0
detector/yolo_pipeline.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ultralytics import YOLO
|
| 2 |
+
import cv2
|
| 3 |
+
import numpy as np
|
| 4 |
+
import trimesh
|
| 5 |
+
|
| 6 |
+
class YOLO3DReconstructor:
|
| 7 |
+
def __init__(self, model_size='m'):
|
| 8 |
+
self.model = YOLO(f'yolov8{model_size}.pt')
|
| 9 |
+
self.class_mapping = {
|
| 10 |
+
0: 'person',
|
| 11 |
+
7: 'forklift', # COCO 'truck'을 지게차로 매핑
|
| 12 |
+
63: 'conveyor' # 커스텀 매핑 (COCO에는 없음)
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
def process_frames(self, frame_paths):
|
| 16 |
+
point_cloud = []
|
| 17 |
+
|
| 18 |
+
for frame_idx, frame_path in enumerate(frame_paths):
|
| 19 |
+
img = cv2.imread(frame_path)
|
| 20 |
+
if img is None:
|
| 21 |
+
continue
|
| 22 |
+
|
| 23 |
+
results = self.model(img)[0]
|
| 24 |
+
for box in results.boxes.xywh.cpu().numpy():
|
| 25 |
+
cls_id = int(box[5])
|
| 26 |
+
if cls_id in self.class_mapping:
|
| 27 |
+
x, y, w, h = box[:4]
|
| 28 |
+
# 간단한 3D 변환 (프레임 인덱스를 Z축으로 사용)
|
| 29 |
+
point_cloud.append([x, y, frame_idx * 50])
|
| 30 |
+
|
| 31 |
+
if not point_cloud:
|
| 32 |
+
return None
|
| 33 |
+
|
| 34 |
+
mesh = trimesh.points.PointCloud(np.array(point_cloud))
|
| 35 |
+
return mesh
|