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.0 kB

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

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