-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2a34c53
commit 73e98c2
Showing
2 changed files
with
65 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Copyright (c) 2024 Justin Davis (davisjustin302@gmail.com) | ||
# | ||
# MIT License | ||
""" | ||
Create script nodes on the OAK device. | ||
Functions | ||
--------- | ||
create_script | ||
Use to create a script node | ||
""" | ||
|
||
from __future__ import annotations | ||
|
||
import time | ||
from pathlib import Path | ||
|
||
import depthai as dai | ||
|
||
|
||
def create_script( | ||
pipeline: dai.Pipeline, | ||
script: str | Path, | ||
name: str | None = None, | ||
processor: dai.ProcessorType = dai.ProcessorType.LEON_CSS, | ||
) -> None: | ||
""" | ||
Use to create a script node. | ||
Parameters | ||
---------- | ||
pipeline : dai.Pipeline | ||
The pipeline to add the script node to | ||
script : str | Path | ||
The script to run on the device. | ||
If the type is a string, then the script will be | ||
used directly to create the node. | ||
If a pathlib.Path is given, then the Path should | ||
be a file containing the script. | ||
name : str | None, optional | ||
The name of the script node, by default None | ||
If None, then the name will be timestamped. | ||
script_{timestamp} | ||
processor : dai.ProcessorType, optional | ||
The processor type to run the script on, by default dai.ProcessorType.LEON_CSS | ||
Should only be changed if you know what you are doing. | ||
""" | ||
name = name if name else f"script_{time.time()}" | ||
script_node = pipeline.create(dai.node.Script) | ||
script_node.setProcessor(processor) | ||
if isinstance(script, Path): | ||
script_node.setScriptPath(path=script, name=name) | ||
else: | ||
script_node.setScript(script=script, name=name) | ||
return script_node |