Browse Source

Removing `no_webcam.py` and relying on default error image for the CI

tags/v0.2.5-alpha
haixuanTao 2 years ago
parent
commit
2f62eabc20
6 changed files with 24 additions and 127 deletions
  1. +0
    -25
      examples/python-dataflow/dataflow_without_webcam.yml
  2. +0
    -28
      examples/python-dataflow/no_webcam.py
  3. +23
    -7
      examples/python-dataflow/webcam.py
  4. +0
    -23
      examples/python-operator-dataflow/dataflow_without_webcam.yml
  5. +0
    -43
      examples/python-operator-dataflow/no_webcam.py
  6. +1
    -1
      examples/python-operator-dataflow/webcam.py

+ 0
- 25
examples/python-dataflow/dataflow_without_webcam.yml View File

@@ -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

+ 0
- 28
examples/python-dataflow/no_webcam.py View File

@@ -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)

+ 23
- 7
examples/python-dataflow/webcam.py View File

@@ -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


+ 0
- 23
examples/python-operator-dataflow/dataflow_without_webcam.yml View File

@@ -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

+ 0
- 43
examples/python-operator-dataflow/no_webcam.py View File

@@ -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)

+ 1
- 1
examples/python-operator-dataflow/webcam.py View File

@@ -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



Loading…
Cancel
Save