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 "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 "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 "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 "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 "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 "color": [255, 0, 0], // color of the box, default is red
"score": 100, // optional score of the object "score": 100 // optional score of the object
}, }
]
}
} }
``` ```

View File

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