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.

webcam_operator.py 1.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from enum import Enum
  2. from typing import Callable
  3. import cv2
  4. class DoraStatus(Enum):
  5. CONTINUE = 0
  6. STOP = 1
  7. class Operator:
  8. """
  9. Example operator incrementing a counter every times its been called.
  10. The current value of the counter is sent back to dora on `counter`.
  11. """
  12. def __init__(self):
  13. self.video_capture = cv2.VideoCapture(0)
  14. def on_input(
  15. self,
  16. input_id: str,
  17. value: bytes,
  18. send_output: Callable[[str, bytes], None],
  19. ) -> DoraStatus:
  20. """Handle input by incrementing count by one.
  21. Args:
  22. input_id (str): Id of the input declared in the yaml configuration
  23. value (bytes): Bytes message of the input
  24. send_output (Callable[[str, bytes]]): Function enabling sending output back to dora.
  25. """
  26. ret, frame = self.video_capture.read()
  27. if ret:
  28. send_output("image", frame.tobytes())
  29. else:
  30. print("did not sent video")
  31. return DoraStatus.CONTINUE
  32. def drop_operator(self):
  33. self.video_capture.release()

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