| | import numpy as np |
| | import pyarrow as pa |
| | import sys |
| | print(sys.version) |
| | from dora import DoraStatus |
| | from ultralytics import YOLO |
| |
|
| |
|
| | CAMERA_WIDTH = 640 |
| | CAMERA_HEIGHT = 480 |
| |
|
| |
|
| | model = YOLO("/home/peiji/yolov8n.pt") |
| |
|
| |
|
| | class Operator: |
| | """ |
| | Inferring object from images |
| | """ |
| |
|
| | def on_event( |
| | self, |
| | dora_event, |
| | send_output, |
| | ) -> DoraStatus: |
| | if dora_event["type"] == "INPUT": |
| | frame = ( |
| | dora_event["value"].to_numpy().reshape((CAMERA_HEIGHT, CAMERA_WIDTH, 3)) |
| | ) |
| | frame = frame[:, :, ::-1] |
| | results = model(frame, verbose=False) |
| | |
| | boxes = np.array(results[0].boxes.xyxy.cpu()) |
| | conf = np.array(results[0].boxes.conf.cpu()) |
| | label = np.array(results[0].boxes.cls.cpu()) |
| | |
| | arrays = np.concatenate((boxes, conf[:, None], label[:, None]), axis=1) |
| |
|
| | send_output("bbox", pa.array(arrays.ravel()), dora_event["metadata"]) |
| |
|
| | return DoraStatus.CONTINUE |
| |
|