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.py 1.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. 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. ret, frame = self.video_capture.read()
  28. if ret:
  29. send_output("image", frame.tobytes())
  30. else:
  31. print("did not sent video")
  32. self.counter += 1
  33. if self.counter > 100:
  34. return DoraStatus.STOP
  35. return DoraStatus.CONTINUE
  36. def drop_operator(self):
  37. 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