Support multiple box annotations

This commit is contained in:
Nick Mowen 2023-05-02 20:38:22 -06:00
parent 9ba7f5c2ae
commit 1eb9403dc1
2 changed files with 27 additions and 21 deletions

View File

@ -307,11 +307,16 @@ Create a manual API with a given `label` (ex: doorbell press) to capture a speci
"subLabel": "some_string", // add sub label to event
"duration": 30, // predetermined length of event (default: 30 seconds) or can be to null for indeterminate length event
"include_recording": true, // whether the event should save recordings along with the snapshot that is taken
"draw": { // optional bounding box that will be drawn on the snapshot
"box": [0.5, 0.5, 0.25, 0.25], // box consists of x, 1, width, height which are on a scale between 0 - 1
"color": [255, 0, 0], // color of the box, default is red
"score": 100, // optional score of the object
},
"draw": {
// optional annotations that will be drawn on the snapshot
"boxes": [
{
"box": [0.5, 0.5, 0.25, 0.25], // box consists of x, 1, width, height which are on a scale between 0 - 1
"color": [255, 0, 0], // color of the box, default is red
"score": 100 // optional score of the object
}
]
}
}
```

View File

@ -107,23 +107,24 @@ class ExternalEventProcessor:
p.write(png.tobytes())
# write jpg snapshot with optional annotations
if draw.get("box"):
x = draw["box"][0] * camera_config.detect.width
y = draw["box"][1] * camera_config.detect.height
width = draw["box"][2] * camera_config.detect.width
height = draw["box"][3] * camera_config.detect.height
if draw.get("boxes") and isinstance(draw.get("boxes"), list):
for box in draw.get("boxes"):
x = box["box"][0] * camera_config.detect.width
y = box["box"][1] * camera_config.detect.height
width = box["box"][2] * camera_config.detect.width
height = box["box"][3] * camera_config.detect.height
draw_box_with_label(
img_bytes,
x,
y,
x + width,
y + height,
label,
f"{draw.get('score', '-')}% {int(width * height)}",
thickness=2,
color=draw.get("color", (255, 0, 0)),
)
draw_box_with_label(
img_bytes,
x,
y,
x + width,
y + height,
label,
f"{box.get('score', '-')}% {int(width * height)}",
thickness=2,
color=box.get("color", (255, 0, 0)),
)
ret, jpg = cv2.imencode(".jpg", img_bytes)
with open(