-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathobject_detection.py
More file actions
executable file
·39 lines (30 loc) · 1.11 KB
/
object_detection.py
File metadata and controls
executable file
·39 lines (30 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""TODO: Add docstring."""
import numpy as np
import pyarrow as pa
from adora import AdoraStatus
from ultralytics import YOLO
CAMERA_WIDTH = 640
CAMERA_HEIGHT = 480
model = YOLO("yolov8n.pt")
class Operator:
"""Inferring object from images."""
def on_event(
self,
adora_event,
send_output,
) -> AdoraStatus:
"""TODO: Add docstring."""
if adora_event["type"] == "INPUT":
frame = (
adora_event["value"].to_numpy().reshape((CAMERA_HEIGHT, CAMERA_WIDTH, 3))
)
frame = frame[:, :, ::-1] # OpenCV image (BGR to RGB)
results = model(frame, verbose=False) # includes NMS
# Process results
boxes = np.array(results[0].boxes.xyxy.cpu())
conf = np.array(results[0].boxes.conf.cpu())
label = np.array(results[0].boxes.cls.cpu())
# concatenate them together
arrays = np.concatenate((boxes, conf[:, None], label[:, None]), axis=1)
send_output("bbox", pa.array(arrays.ravel()), adora_event["metadata"])
return AdoraStatus.CONTINUE