-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an example with threaded host nodes
- Loading branch information
Matevz Morato
committed
May 3, 2024
1 parent
4453096
commit 39db2d9
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
bindings/python/examples/v3/HostNodes/threaded_host_nodes.py
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import depthai as dai | ||
import time | ||
|
||
class TestPassthrough(dai.node.ThreadedHostNode): | ||
def __init__(self): | ||
dai.node.ThreadedHostNode.__init__(self) | ||
self.input = dai.Node.Input(self) | ||
self.output = dai.Node.Output(self) | ||
def run(self): | ||
while self.isRunning(): | ||
buffer = self.input.get() | ||
print("The passthrough node received a buffer!") | ||
self.output.send(buffer) | ||
|
||
class TestSink(dai.node.ThreadedHostNode): | ||
def __init__(self): | ||
dai.node.ThreadedHostNode.__init__(self) | ||
self.input = dai.Node.Input(self) | ||
def run(self): | ||
while self.isRunning(): | ||
buffer = self.input.get() | ||
print("The sync node received a buffer!") | ||
|
||
class TestSource(dai.node.ThreadedHostNode): | ||
def __init__(self): | ||
dai.node.ThreadedHostNode.__init__(self) | ||
self.output = dai.Node.Output(self) | ||
def run(self): | ||
while self.isRunning(): | ||
buffer = dai.Buffer() | ||
print("The source node is sending a buffer!") | ||
self.output.send(buffer) | ||
time.sleep(1) | ||
|
||
with dai.Pipeline(False) as p: | ||
source = TestSource() | ||
sink = TestSink() | ||
passthrough = TestPassthrough() | ||
source.output.link(passthrough.input) | ||
passthrough.output.link(sink.input) | ||
p.start() | ||
while True: | ||
time.sleep(1) | ||
print("Pipeline is running...") |