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_cv2.py 1.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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.counter = 0
  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. self.counter += 1
  28. if input_id == "image":
  29. frame = np.frombuffer(value, dtype="uint8")
  30. frame = np.reshape(frame, (480, 640, 3))
  31. cv2.imshow("frame", frame)
  32. if cv2.waitKey(1) & 0xFF == ord("q"):
  33. return DoraStatus.STOP
  34. if self.counter > 20:
  35. return DoraStatus.STOP
  36. else:
  37. return DoraStatus.CONTINUE
  38. def drop_operator(self):
  39. 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