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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import os
  4. import time
  5. import numpy as np
  6. import cv2
  7. from dora import Node
  8. node = Node()
  9. CAMERA_INDEX = int(os.getenv("CAMERA_INDEX", 0))
  10. CAMERA_WIDTH = 640
  11. CAMERA_HEIGHT = 480
  12. video_capture = cv2.VideoCapture(CAMERA_INDEX)
  13. font = cv2.FONT_HERSHEY_SIMPLEX
  14. start = time.time()
  15. # Run for 20 seconds
  16. while time.time() - start < 10:
  17. # Wait next dora_input
  18. event = node.next()
  19. match event["type"]:
  20. case "INPUT":
  21. ret, frame = video_capture.read()
  22. if not ret:
  23. frame = np.zeros((CAMERA_HEIGHT, CAMERA_WIDTH, 3), dtype=np.uint8)
  24. cv2.putText(
  25. frame,
  26. "No Webcam was found at index %d" % (CAMERA_INDEX),
  27. (int(30), int(30)),
  28. font,
  29. 0.75,
  30. (255, 255, 255),
  31. 2,
  32. 1,
  33. )
  34. node.send_output(
  35. "image",
  36. cv2.imencode(".jpg", frame)[1].tobytes(),
  37. event["metadata"],
  38. )
  39. case "STOP":
  40. print("received stop")
  41. break
  42. case other:
  43. print("received unexpected event:", other)
  44. break
  45. 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