Spaces:
Sleeping
Sleeping
Create map_builder.py
Browse files- map_builder.py +26 -0
map_builder.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from PIL import Image, ImageDraw
|
| 2 |
+
|
| 3 |
+
def generate_factory_map(detections, canvas_size=(512, 512)):
|
| 4 |
+
img = Image.new("RGB", canvas_size, "white")
|
| 5 |
+
draw = ImageDraw.Draw(img)
|
| 6 |
+
|
| 7 |
+
class_colors = {
|
| 8 |
+
"conveyor": "blue",
|
| 9 |
+
"machine": "gray",
|
| 10 |
+
"person": "green",
|
| 11 |
+
"forklift": "orange"
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
for det in detections:
|
| 15 |
+
cls = det["class"]
|
| 16 |
+
bbox = det["bbox"]
|
| 17 |
+
color = class_colors.get(cls, "red")
|
| 18 |
+
# ๋จ์ํ bbox ์ขํ๋ฅผ ์ถ์ํ์ฌ canvas์ ํ์
|
| 19 |
+
x0 = int(bbox[0] / 4)
|
| 20 |
+
y0 = int(bbox[1] / 4)
|
| 21 |
+
x1 = int(bbox[2] / 4)
|
| 22 |
+
y1 = int(bbox[3] / 4)
|
| 23 |
+
draw.rectangle([x0, y0, x1, y1], outline=color, width=2)
|
| 24 |
+
draw.text((x0, y0), cls, fill=color)
|
| 25 |
+
|
| 26 |
+
return img
|