Spaces:
Sleeping
Sleeping
Update detector/yolo_pipeline.py
Browse files- detector/yolo_pipeline.py +20 -4
detector/yolo_pipeline.py
CHANGED
|
@@ -13,16 +13,32 @@ class YOLO3DReconstructor:
|
|
| 13 |
63: 'conveyor' # ์ปค์คํ
๋งคํ (COCO์๋ ์์)
|
| 14 |
}
|
| 15 |
|
| 16 |
-
|
| 17 |
point_cloud = []
|
| 18 |
|
| 19 |
for frame_idx, frame_path in enumerate(frame_paths):
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
# ํฌ์ธํธ ํด๋ผ์ฐ๋ ํ์ฒ๋ฆฌ ์ถ๊ฐ
|
| 23 |
if point_cloud:
|
| 24 |
points = np.array(point_cloud)
|
| 25 |
points = PointCloudProcessor.filter_outliers(points)
|
| 26 |
points = PointCloudProcessor.normalize_points(points)
|
| 27 |
|
| 28 |
-
return PointCloudProcessor.create_mesh(points) if len(points) > 0 else None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
63: 'conveyor' # ์ปค์คํ
๋งคํ (COCO์๋ ์์)
|
| 14 |
}
|
| 15 |
|
| 16 |
+
def process_frames(self, frame_paths):
|
| 17 |
point_cloud = []
|
| 18 |
|
| 19 |
for frame_idx, frame_path in enumerate(frame_paths):
|
| 20 |
+
img = cv2.imread(frame_path)
|
| 21 |
+
if img is None:
|
| 22 |
+
continue
|
| 23 |
+
|
| 24 |
+
results = self.model(img)[0]
|
| 25 |
+
for box in results.boxes.xywh.cpu().numpy():
|
| 26 |
+
cls_id = int(box[5])
|
| 27 |
+
if cls_id in self.class_mapping:
|
| 28 |
+
x, y, w, h = box[:4]
|
| 29 |
+
# ๊ฐ๋จํ 3D ๋ณํ (ํ๋ ์ ์ธ๋ฑ์ค๋ฅผ Z์ถ์ผ๋ก ์ฌ์ฉ)
|
| 30 |
+
point_cloud.append([x, y, frame_idx * 50])
|
| 31 |
+
|
| 32 |
# ํฌ์ธํธ ํด๋ผ์ฐ๋ ํ์ฒ๋ฆฌ ์ถ๊ฐ
|
| 33 |
if point_cloud:
|
| 34 |
points = np.array(point_cloud)
|
| 35 |
points = PointCloudProcessor.filter_outliers(points)
|
| 36 |
points = PointCloudProcessor.normalize_points(points)
|
| 37 |
|
| 38 |
+
return PointCloudProcessor.create_mesh(points) if len(points) > 0 else None
|
| 39 |
+
|
| 40 |
+
if not point_cloud:
|
| 41 |
+
return None
|
| 42 |
+
|
| 43 |
+
mesh = trimesh.points.PointCloud(np.array(point_cloud))
|
| 44 |
+
return mesh
|