diff --git a/examples/python-dataflow/dataflow_without_webcam.yml b/examples/python-dataflow/dataflow_without_webcam.yml deleted file mode 100644 index 07839cb8..00000000 --- a/examples/python-dataflow/dataflow_without_webcam.yml +++ /dev/null @@ -1,25 +0,0 @@ -nodes: - - id: no_webcam - custom: - source: ./no_webcam.py - inputs: - tick: - source: dora/timer/millis/100 - queue_size: 100 - outputs: - - image - - - id: object_detection - custom: - source: ./object_detection.py - inputs: - image: no_webcam/image - outputs: - - bbox - - - id: plot - custom: - source: ./plot.py - inputs: - image: no_webcam/image - bbox: object_detection/bbox diff --git a/examples/python-dataflow/no_webcam.py b/examples/python-dataflow/no_webcam.py deleted file mode 100755 index dac61cea..00000000 --- a/examples/python-dataflow/no_webcam.py +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- - -import time -import urllib.request - -import cv2 -import numpy as np -from dora import Node - -req = urllib.request.urlopen("https://ultralytics.com/images/zidane.jpg") - -arr = np.asarray(bytearray(req.read()), dtype=np.uint8) -node = Node() - -start = time.time() - -while time.time() - start < 20: - # Wait next dora_input - event = node.next() - match event["type"]: - case "INPUT": - print("received input", event["id"]) - node.send_output("image", arr.tobytes()) - case "STOP": - print("received stop") - case other: - print("received unexpected event:", other) diff --git a/examples/python-dataflow/webcam.py b/examples/python-dataflow/webcam.py index 88b4698b..d130b50c 100755 --- a/examples/python-dataflow/webcam.py +++ b/examples/python-dataflow/webcam.py @@ -1,15 +1,20 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- +import os import time - +import numpy as np import cv2 from dora import Node node = Node() -video_capture = cv2.VideoCapture(0) +CAMERA_INDEX = int(os.getenv("CAMERA_INDEX", 0)) +CAMERA_WIDTH = 640 +CAMERA_HEIGHT = 480 +video_capture = cv2.VideoCapture(CAMERA_INDEX) +font = cv2.FONT_HERSHEY_SIMPLEX start = time.time() @@ -20,12 +25,23 @@ while time.time() - start < 10: match event["type"]: case "INPUT": ret, frame = video_capture.read() - if ret: - node.send_output( - "image", - cv2.imencode(".jpg", frame)[1].tobytes(), - event["metadata"], + if not ret: + frame = np.zeros((CAMERA_HEIGHT, CAMERA_WIDTH, 3), dtype=np.uint8) + cv2.putText( + frame, + "No Webcam was found at index %d" % (CAMERA_INDEX), + (int(30), int(30)), + font, + 0.75, + (255, 255, 255), + 2, + 1, ) + node.send_output( + "image", + cv2.imencode(".jpg", frame)[1].tobytes(), + event["metadata"], + ) case "STOP": print("received stop") break diff --git a/examples/python-operator-dataflow/dataflow_without_webcam.yml b/examples/python-operator-dataflow/dataflow_without_webcam.yml deleted file mode 100644 index c82b992e..00000000 --- a/examples/python-operator-dataflow/dataflow_without_webcam.yml +++ /dev/null @@ -1,23 +0,0 @@ -nodes: - - id: no_webcam - custom: - source: ./no_webcam.py - inputs: - tick: dora/timer/millis/100 - outputs: - - image - - - id: object_detection - operator: - python: object_detection.py - inputs: - image: no_webcam/image - outputs: - - bbox - - - id: plot - operator: - python: plot.py - inputs: - image: no_webcam/image - bbox: object_detection/bbox diff --git a/examples/python-operator-dataflow/no_webcam.py b/examples/python-operator-dataflow/no_webcam.py deleted file mode 100755 index 60a4f950..00000000 --- a/examples/python-operator-dataflow/no_webcam.py +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/env python3 -# -*- coding: utf-8 -*- - -import time -import urllib.request - -import cv2 -import numpy as np -import pyarrow as pa - -from dora import Node - -print("Hello from no_webcam.py") - - -CAMERA_WIDTH = 640 -CAMERA_HEIGHT = 480 - -# Preprocessing the image -req = urllib.request.urlopen( - "https://img0.baidu.com/it/u=2940037857,1417768899&fm=253&fmt=auto&app=138&f=PNG?w=724&h=500" -) # This image works in china better -arr = np.asarray(bytearray(req.read()), dtype=np.uint8) -image = cv2.imdecode(arr, -1)[:, :, :3] -image = cv2.resize(image, (CAMERA_WIDTH, CAMERA_HEIGHT)) - -# Numpy -> Arrow -image = pa.array(image.flatten().view(np.uint8)) -node = Node() - -start = time.time() - -while time.time() - start < 20: - # Wait next dora_input - event = node.next() - match event["type"]: - case "INPUT": - print("received input", event["id"]) - node.send_output("image", image) - case "STOP": - print("received stop") - case other: - print("received unexpected event:", other) diff --git a/examples/python-operator-dataflow/webcam.py b/examples/python-operator-dataflow/webcam.py index d0d198f0..ae2fbb77 100755 --- a/examples/python-operator-dataflow/webcam.py +++ b/examples/python-operator-dataflow/webcam.py @@ -13,7 +13,7 @@ from dora import DoraStatus CAMERA_WIDTH = 640 CAMERA_HEIGHT = 480 -CAMERA_INDEX = os.getenv("CAMERA_INDEX", 0) +CAMERA_INDEX = int(os.getenv("CAMERA_INDEX", 0)) font = cv2.FONT_HERSHEY_SIMPLEX