You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

object_detection.py 1.1 kB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. from typing import Callable
  4. from dora import Node
  5. import cv2
  6. import numpy as np
  7. import torch
  8. model = torch.hub.load("ultralytics/yolov5", "yolov5n")
  9. node = Node()
  10. for event in node:
  11. event_type = event["type"]
  12. if event_type == "INPUT":
  13. event_id = event["id"]
  14. if event_id == "image":
  15. print("[object detection] received image input")
  16. frame = event["value"].to_numpy()
  17. frame = cv2.imdecode(frame, -1)
  18. frame = frame[:, :, ::-1] # OpenCV image (BGR to RGB)
  19. results = model(frame) # includes NMS
  20. arrays = np.array(results.xyxy[0].cpu()).tobytes()
  21. node.send_output("bbox", arrays, event["metadata"])
  22. else:
  23. print("[object detection] ignoring unexpected input:", event_id)
  24. elif event_type == "INPUT":
  25. print("[object detection] received stop")
  26. elif event_type == "ERROR":
  27. print("[object detection] error: ", event["error"])
  28. else:
  29. print("[object detection] received unexpected event:", event_type)

DORA (Dataflow-Oriented Robotic Architecture) is middleware designed to streamline and simplify the creation of AI-based robotic applications. It offers low latency, composable, and distributed datafl