Skip to main content

Webcam operator

Inputs

  • tick: Dora tick.

Outputs

  • image: HEIGHTxWIDTHxBGR array.

Configuration

Using cv2 package to get the webcam image. The webcam number can be configured using CAMERA_INDEX

Graph Description

  - id: yolov5
operator:
outputs:
- bbox
inputs:
image: webcam/image
python: ../../operators/webcam_op.py

Methods

__init__()

Source Code
    def __init__(self):
self.video_capture = cv2.VideoCapture(int(DEVICE_INDEX))
self.video_capture.set(cv2.CAP_PROP_FRAME_WIDTH, OUTPUT_WIDTH)
self.video_capture.set(cv2.CAP_PROP_FRAME_HEIGHT, OUTPUT_HEIGHT)


.on_event(...)

Source Code

def on_event(
self,
dora_event: dict,
send_output: Callable[[str, bytes], None],
) -> DoraStatus:
if dora_event["type"] == "INPUT":
return self.on_input(dora_event, send_output)
return DoraStatus.CONTINUE


.on_input(...)

Source Code

def on_input(
self,
dora_input: dict,
send_output: Callable[[str, bytes], None],
):
ret, frame = self.video_capture.read()
if ret:
frame = cv2.resize(frame, (OUTPUT_WIDTH, OUTPUT_HEIGHT))
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2BGRA)
send_output(
"image",
pa.array(frame.ravel()),
dora_input["metadata"],
)
else:
print("could not get webcam.")
return DoraStatus.CONTINUE