-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upate webcam operator example to make use of opentelemetry jaeger
- Loading branch information
1 parent
350c4d5
commit 75e7f2c
Showing
5 changed files
with
52 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
import torch | ||
|
||
from dora import DoraStatus | ||
|
||
|
||
class Operator: | ||
""" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,46 @@ | ||
#!/usr/bin/env python | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
|
||
import time | ||
from typing import Callable | ||
|
||
import cv2 | ||
from dora import Node | ||
|
||
node = Node() | ||
|
||
video_capture = cv2.VideoCapture(0) | ||
|
||
start = time.time() | ||
|
||
# Run for 20 seconds | ||
while time.time() - start < 10: | ||
# Wait next dora_input | ||
event = node.next() | ||
match event["type"]: | ||
case "INPUT": | ||
ret, frame = video_capture.read() | ||
if ret: | ||
node.send_output("image", cv2.imencode(".jpg", frame)[1].tobytes()) | ||
case "STOP": | ||
print("received stop") | ||
break | ||
case other: | ||
print("received unexpected event:", other) | ||
break | ||
|
||
video_capture.release() | ||
|
||
from dora import DoraStatus | ||
|
||
|
||
class Operator: | ||
""" | ||
Sending image from webcam to the dataflow | ||
""" | ||
|
||
def __init__(self): | ||
self.video_capture = cv2.VideoCapture(0) | ||
self.start_time = time.time() | ||
|
||
def on_event( | ||
self, | ||
dora_event: dict, | ||
send_output: Callable[[str, bytes], None], | ||
) -> DoraStatus: | ||
match dora_event["type"]: | ||
case "INPUT": | ||
ret, frame = self.video_capture.read() | ||
if ret: | ||
send_output( | ||
"image", | ||
cv2.imencode(".jpg", frame)[1].tobytes(), | ||
dora_event["metadata"], | ||
) | ||
case "STOP": | ||
print("received stop") | ||
case other: | ||
print("received unexpected event:", other) | ||
|
||
if time.time() - self.start_time < 20: | ||
return DoraStatus.CONTINUE | ||
else: | ||
return DoraStatus.STOP | ||
|
||
def __del__(self): | ||
self.video_capture.release() |