Browse Source

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.
tags/v0.2.4
haixuanTao 2 years ago
parent
commit
5b713e4a77
2 changed files with 38 additions and 12 deletions
  1. +12
    -6
      README.md
  2. +26
    -6
      examples/python-operator-dataflow/webcam.py

+ 12
- 6
README.md View File

@@ -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 <kbd>ctrl</kbd>+<kbd>c</kbd>

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


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

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


Loading…
Cancel
Save