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.

no_webcam.py 1.0 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. import time
  4. import urllib.request
  5. import cv2
  6. import numpy as np
  7. import pyarrow as pa
  8. from dora import Node
  9. print("Hello from no_webcam.py")
  10. CAMERA_WIDTH = 640
  11. CAMERA_HEIGHT = 480
  12. # Preprocessing the image
  13. req = urllib.request.urlopen(
  14. "https://img0.baidu.com/it/u=2940037857,1417768899&fm=253&fmt=auto&app=138&f=PNG?w=724&h=500"
  15. ) # This image works in china better
  16. arr = np.asarray(bytearray(req.read()), dtype=np.uint8)
  17. image = cv2.imdecode(arr, -1)[:, :, :3]
  18. image = cv2.resize(image, (CAMERA_WIDTH, CAMERA_HEIGHT))
  19. # Numpy -> Arrow
  20. image = pa.array(image.flatten().view(np.uint8))
  21. node = Node()
  22. start = time.time()
  23. while time.time() - start < 20:
  24. # Wait next dora_input
  25. event = node.next()
  26. match event["type"]:
  27. case "INPUT":
  28. print("received input", event["id"])
  29. node.send_output("image", image)
  30. case "STOP":
  31. print("received stop")
  32. case other:
  33. print("received unexpected event:", other)

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