From 5b713e4a77c30bbaf891786a24ff2521a5bcade5 Mon Sep 17 00:00:00 2001 From: haixuanTao Date: Tue, 18 Jul 2023 14:43:28 +0200 Subject: [PATCH] Fix typo on the getting started section of `README.md` After re-bootrapping the project, I realised that the README had some typo that I fixed in this commit. --- README.md | 18 ++++++++---- examples/python-operator-dataflow/webcam.py | 32 +++++++++++++++++---- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index acb5d583..7061a0d1 100644 --- a/README.md +++ b/README.md @@ -73,22 +73,28 @@ For more installation guideline, check out our installation guide here: https:// 1. Install the example python dependencies: ```bash -pip install opencv-python numpy pyarrow +pip install -r https://raw.githubusercontent.com/dora-rs/dora/v0.2.4/examples/python-operator-dataflow/requirements.txt ``` 2. Get some example operators: ```bash -wget https://raw.githubusercontent.com/dora-rs/dora/main/examples/python-operator-dataflow/webcam.py -wget https://raw.githubusercontent.com/dora-rs/dora/main/examples/python-operator-dataflow/plot.py -wget https://raw.githubusercontent.com/dora-rs/dora/main/examples/python-operator-dataflow/utils.py -wget https://raw.githubusercontent.com/dora-rs/dora/main/examples/python-operator-dataflow/dataflow.yml +wget https://raw.githubusercontent.com/dora-rs/dora/v0.2,4/examples/python-operator-dataflow/webcam.py +wget https://raw.githubusercontent.com/dora-rs/dora/v0.2.4/examples/python-operator-dataflow/plot.py +wget https://raw.githubusercontent.com/dora-rs/dora/v0.2.4/examples/python-operator-dataflow/utils.py +wget https://raw.githubusercontent.com/dora-rs/dora/v0.2.4/examples/python-operator-dataflow/object_detection.py +wget https://raw.githubusercontent.com/dora-rs/dora/v0.2.4/examples/python-operator-dataflow/dataflow.yml ``` 3. Start the dataflow ```bash -dora start dataflow.yaml --attach --hot-reload +dora up +dora start dataflow.yml --attach --hot-reload ``` +> Make sure to have a webcam + +To stop your dataflow, you can use ctrl+c + To go further, you can add a yolov5 operator, check out our getting started here: https://dora.carsmos.ai/docs/guides/getting-started/yolov5 ## Documentation diff --git a/examples/python-operator-dataflow/webcam.py b/examples/python-operator-dataflow/webcam.py index f489062a..1f5e62b5 100755 --- a/examples/python-operator-dataflow/webcam.py +++ b/examples/python-operator-dataflow/webcam.py @@ -4,13 +4,18 @@ import time from typing import Callable +import os import cv2 +import numpy as np import pyarrow as pa from dora import DoraStatus CAMERA_WIDTH = 640 CAMERA_HEIGHT = 480 +CAMERA_INDEX = os.getenv("CAMERA_INDEX", 0) + +font = cv2.FONT_HERSHEY_SIMPLEX class Operator: @@ -19,7 +24,7 @@ class Operator: """ def __init__(self): - self.video_capture = cv2.VideoCapture(0) + self.video_capture = cv2.VideoCapture(CAMERA_INDEX) self.start_time = time.time() self.video_capture.set(cv2.CAP_PROP_FRAME_WIDTH, CAMERA_WIDTH) self.video_capture.set(cv2.CAP_PROP_FRAME_HEIGHT, CAMERA_HEIGHT) @@ -32,13 +37,28 @@ class Operator: match dora_event["type"]: case "INPUT": ret, frame = self.video_capture.read() - frame = cv2.resize(frame, (CAMERA_WIDTH, CAMERA_HEIGHT)) if ret: - send_output( - "image", - pa.array(frame.ravel()), - dora_event["metadata"], + frame = cv2.resize(frame, (CAMERA_WIDTH, CAMERA_HEIGHT)) + + ## Push an error image in case the camera is not available. + else: + 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, ) + + send_output( + "image", + pa.array(frame.ravel()), + dora_event["metadata"], + ) case "STOP": print("received stop") case other: