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.

plot.py 1.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. from enum import Enum
  2. from typing import Callable
  3. import cv2
  4. import numpy as np
  5. class DoraStatus(Enum):
  6. CONTINUE = 0
  7. STOP = 1
  8. class Operator:
  9. """
  10. Example operator incrementing a counter every times its been called.
  11. The current value of the counter is sent back to dora on `counter`.
  12. """
  13. def __init__(self):
  14. self.image = []
  15. def on_input(
  16. self,
  17. input_id: str,
  18. value: bytes,
  19. send_output: Callable[[str, bytes], None],
  20. ) -> DoraStatus:
  21. """Handle input by incrementing count by one.
  22. Args:
  23. input_id (str): Id of the input declared in the yaml configuration
  24. value (bytes): Bytes message of the input
  25. send_output (Callable[[str, bytes]]): Function enabling sending output back to dora.
  26. """
  27. if input_id == "image":
  28. frame = np.frombuffer(value, dtype="uint8")
  29. frame = cv2.imdecode(frame, -1)
  30. self.image = frame
  31. elif input_id == "bbox" and len(self.image) != 0:
  32. bboxs = np.frombuffer(value, dtype="float32")
  33. bboxs = np.reshape(bboxs, (-1, 6))
  34. for bbox in bboxs:
  35. [
  36. min_x,
  37. min_y,
  38. max_x,
  39. max_y,
  40. _confidence,
  41. _class_label,
  42. ] = bbox
  43. cv2.rectangle(
  44. self.image,
  45. (int(min_x), int(min_y)),
  46. (int(max_x), int(max_y)),
  47. (0, 255, 0),
  48. 2,
  49. )
  50. cv2.imshow("frame", self.image)
  51. if cv2.waitKey(1) & 0xFF == ord("q"):
  52. return DoraStatus.STOP
  53. return DoraStatus.CONTINUE
  54. def drop_operator(self):
  55. cv2.destroyAllWindows()

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