Skip to content

Commit

Permalink
Added create_script
Browse files Browse the repository at this point in the history
  • Loading branch information
justincdavis committed Aug 1, 2024
1 parent 2a34c53 commit 73e98c2
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/oakutils/nodes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -90,6 +94,7 @@
models,
mono_camera,
neural_network,
script,
stereo_depth,
xin,
xout,
Expand All @@ -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
Expand All @@ -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",
Expand All @@ -148,6 +155,7 @@
"models",
"mono_camera",
"neural_network",
"script",
"stereo_depth",
"xin",
"xout",
Expand Down
57 changes: 57 additions & 0 deletions src/oakutils/nodes/script.py
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

0 comments on commit 73e98c2

Please sign in to comment.