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.1 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import time
  4. from typing import Callable
  5. import cv2
  6. from dora import DoraStatus
  7. class Operator:
  8. """
  9. Sending image from webcam to the dataflow
  10. """
  11. def __init__(self):
  12. self.video_capture = cv2.VideoCapture(0)
  13. self.start_time = time.time()
  14. def on_event(
  15. self,
  16. dora_event: dict,
  17. send_output: Callable[[str, bytes], None],
  18. ) -> DoraStatus:
  19. match dora_event["type"]:
  20. case "INPUT":
  21. ret, frame = self.video_capture.read()
  22. if ret:
  23. send_output(
  24. "image",
  25. cv2.imencode(".jpg", frame)[1].tobytes(),
  26. dora_event["metadata"],
  27. )
  28. case "STOP":
  29. print("received stop")
  30. case other:
  31. print("received unexpected event:", other)
  32. if time.time() - self.start_time < 20:
  33. return DoraStatus.CONTINUE
  34. else:
  35. return DoraStatus.STOP
  36. def __del__(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