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 995 B

123456789101112131415161718192021222324252627282930313233343536
  1. from typing import Callable
  2. import cv2
  3. import numpy as np
  4. import torch
  5. from dora import DoraStatus
  6. class Operator:
  7. """
  8. Infering object from images
  9. """
  10. def __init__(self):
  11. self.model = torch.hub.load("ultralytics/yolov5", "yolov5n")
  12. def on_input(
  13. self,
  14. dora_input: dict,
  15. send_output: Callable[[str, bytes], None],
  16. ) -> DoraStatus:
  17. """Handle image
  18. Args:
  19. dora_input (dict): Dict containing the "id", "data", and "metadata"
  20. send_output (Callable[[str, bytes]]): Function enabling sending output back to dora.
  21. """
  22. frame = np.frombuffer(dora_input["data"], dtype="uint8")
  23. frame = cv2.imdecode(frame, -1)
  24. frame = frame[:, :, ::-1] # OpenCV image (BGR to RGB)
  25. results = self.model(frame) # includes NMS
  26. arrays = np.array(results.xyxy[0].cpu()).tobytes()
  27. send_output("bbox", arrays, dora_input["metadata"])
  28. return DoraStatus.CONTINUE

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