Spaces:
Sleeping
Sleeping
객체 위치 2D 시각화 스크립트
Browse files- plot_map.py +35 -0
plot_map.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import matplotlib.pyplot as plt
|
| 2 |
+
import io
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
def generate_layout(detections_per_frame):
|
| 6 |
+
all_positions = {}
|
| 7 |
+
|
| 8 |
+
for detections in detections_per_frame:
|
| 9 |
+
for name, (x, y) in detections:
|
| 10 |
+
if name not in all_positions:
|
| 11 |
+
all_positions[name] = []
|
| 12 |
+
all_positions[name].append((x, y))
|
| 13 |
+
|
| 14 |
+
# 평균 좌표 계산
|
| 15 |
+
avg_positions = {
|
| 16 |
+
name: np.mean(pos, axis=0)
|
| 17 |
+
for name, pos in all_positions.items()
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
# 시각화
|
| 21 |
+
fig, ax = plt.subplots(figsize=(6, 6))
|
| 22 |
+
ax.set_xlim(0, 1280)
|
| 23 |
+
ax.set_ylim(720, 0) # y축 뒤집기 (영상 좌표계 기준)
|
| 24 |
+
|
| 25 |
+
for name, (x, y) in avg_positions.items():
|
| 26 |
+
ax.plot(x, y, 'o', label=name)
|
| 27 |
+
ax.text(x + 10, y, name, fontsize=10)
|
| 28 |
+
|
| 29 |
+
ax.set_title("Factory 2D Layout (Prototype)")
|
| 30 |
+
ax.legend()
|
| 31 |
+
|
| 32 |
+
buf = io.BytesIO()
|
| 33 |
+
plt.savefig(buf, format='png')
|
| 34 |
+
buf.seek(0)
|
| 35 |
+
return buf
|