diff --git a/src/oakutils/nodes/__init__.py b/src/oakutils/nodes/__init__.py index 9817fb1..116b39e 100644 --- a/src/oakutils/nodes/__init__.py +++ b/src/oakutils/nodes/__init__.py @@ -18,6 +18,8 @@ Module for creating mono camera nodes. neural_network Module for creating neural network nodes. +script + Module for creating script nodes. stereo_depth Module for creating stereo depth nodes. xin @@ -50,6 +52,8 @@ Wrapper function for creating the left and right mono cameras. create_neural_network Creates a neural network node. +create_script + Creates a script node. create_stereo_depth Creates a stereo depth node. create_stereo_depth_from_mono_cameras @@ -90,6 +94,7 @@ models, mono_camera, neural_network, + script, stereo_depth, xin, xout, @@ -110,6 +115,7 @@ get_nn_frame, get_nn_gray_frame, ) +from .script import create_script from .stereo_depth import create_stereo_depth, create_stereo_depth_from_mono_cameras from .xin import create_xin from .xout import create_xout @@ -131,6 +137,7 @@ "create_mobilenet_detection_network", "create_mono_camera", "create_neural_network", + "create_script", "create_stereo_depth", "create_stereo_depth_from_mono_cameras", "create_xin", @@ -148,6 +155,7 @@ "models", "mono_camera", "neural_network", + "script", "stereo_depth", "xin", "xout", diff --git a/src/oakutils/nodes/script.py b/src/oakutils/nodes/script.py new file mode 100644 index 0000000..b1810ee --- /dev/null +++ b/src/oakutils/nodes/script.py @@ -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