diff --git a/neural-networks/3D-detection/objectron/main.py b/neural-networks/3D-detection/objectron/main.py index 6f77b4f78..5704f23d7 100644 --- a/neural-networks/3D-detection/objectron/main.py +++ b/neural-networks/3D-detection/objectron/main.py @@ -1,9 +1,9 @@ from pathlib import Path import depthai as dai from depthai_nodes import ParsingNeuralNetwork +from depthai_nodes.nodes.utils import generate_script_content from utils.arguments import initialize_argparser from utils.annotation_node import AnnotationNode -from utils.script import generate_script_content _, args = initialize_argparser() diff --git a/neural-networks/3D-detection/objectron/requirements.txt b/neural-networks/3D-detection/objectron/requirements.txt index 275cdb23e..6770fa70e 100644 --- a/neural-networks/3D-detection/objectron/requirements.txt +++ b/neural-networks/3D-detection/objectron/requirements.txt @@ -1,3 +1,3 @@ --extra-index-url https://artifacts.luxonis.com/artifactory/luxonis-python-release-local/ depthai>=3.0.0a11 -depthai-nodes>=0.1.1 \ No newline at end of file +git+https://github.com/luxonis/depthai-nodes.git@feat/detection-manip-config-script \ No newline at end of file diff --git a/neural-networks/3D-detection/objectron/utils/script.py b/neural-networks/3D-detection/objectron/utils/script.py deleted file mode 100644 index ad7506f06..000000000 --- a/neural-networks/3D-detection/objectron/utils/script.py +++ /dev/null @@ -1,55 +0,0 @@ -from typing import List - - -def generate_script_content( - platform: str, - resize_width: int = 224, - resize_height: int = 224, - padding: float = 0.2, - valid_labels: List[int] = [56], -) -> str: - """The function generates the script content for the dai.Script node. It is used to crop and resize the input image based on the detected object.""" - - if platform.lower() == "rvc2": - cfg_content = f""" - cfg = ImageManipConfig() - cfg.setCropRect(det.xmin - {padding}, det.ymin - {padding}, det.xmax + {padding}, det.ymax + {padding}) - cfg.setResize({resize_width}, {resize_height}) - cfg.setKeepAspectRatio(False) - """ - elif platform.lower() == "rvc4": - cfg_content = f""" - cfg = ImageManipConfigV2() - rect = RotatedRect() - rect.center.x = (det.xmin + det.xmax) / 2 - rect.center.y = (det.ymin + det.ymax) / 2 - rect.size.width = det.xmax - det.xmin - rect.size.height = det.ymax - det.ymin - rect.size.width = rect.size.width + {padding} * 2 - rect.size.height = rect.size.height + {padding} * 2 - rect.angle = 0 - - cfg.addCropRotatedRect(rect=rect, normalizedCoords=True) - cfg.setOutputSize({resize_width}, {resize_height}) - """ - else: - raise ValueError("Unsupported version") - - return f""" -try: - while True: - frame = node.inputs['preview'].get() - dets = node.inputs['det_in'].get() - - for i, det in enumerate(dets.detections): - if det.label not in {valid_labels}: - continue - - {cfg_content.strip()} - - node.outputs['manip_cfg'].send(cfg) - node.outputs['manip_img'].send(frame) - -except Exception as e: - node.warn(str(e)) -""" diff --git a/neural-networks/pose-estimation/animal-pose/main.py b/neural-networks/pose-estimation/animal-pose/main.py index dd3dae577..7a179fafa 100644 --- a/neural-networks/pose-estimation/animal-pose/main.py +++ b/neural-networks/pose-estimation/animal-pose/main.py @@ -1,9 +1,9 @@ from pathlib import Path import depthai as dai from depthai_nodes import ParsingNeuralNetwork +from depthai_nodes.nodes.utils import generate_script_content from utils.arguments import initialize_argparser from utils.annotation_node import AnnotationNode -from utils.script import generate_script_content _, args = initialize_argparser() diff --git a/neural-networks/pose-estimation/animal-pose/requirements.txt b/neural-networks/pose-estimation/animal-pose/requirements.txt index 275cdb23e..6770fa70e 100644 --- a/neural-networks/pose-estimation/animal-pose/requirements.txt +++ b/neural-networks/pose-estimation/animal-pose/requirements.txt @@ -1,3 +1,3 @@ --extra-index-url https://artifacts.luxonis.com/artifactory/luxonis-python-release-local/ depthai>=3.0.0a11 -depthai-nodes>=0.1.1 \ No newline at end of file +git+https://github.com/luxonis/depthai-nodes.git@feat/detection-manip-config-script \ No newline at end of file diff --git a/neural-networks/pose-estimation/animal-pose/utils/script.py b/neural-networks/pose-estimation/animal-pose/utils/script.py deleted file mode 100644 index 0a2871061..000000000 --- a/neural-networks/pose-estimation/animal-pose/utils/script.py +++ /dev/null @@ -1,61 +0,0 @@ -from typing import List - - -def generate_script_content( - platform: str, - resize_width: int = 224, - resize_height: int = 224, - padding: float = 0.1, - valid_labels: List[int] = [0, 15, 16, 17, 18, 19, 20, 21, 22, 23], -) -> str: - """The function generates the script content for the dai.Script node. It is used to crop and resize the input image based on the detected object.""" - - if platform.lower() == "rvc2": - cfg_content = f""" - cfg = ImageManipConfig() - rect = RotatedRect() - rect.center.x = (det.xmin + det.xmax) / 2 - rect.center.y = (det.ymin + det.ymax) / 2 - rect.size.width = det.xmax - det.xmin - rect.size.height = det.ymax - det.ymin - rect.size.width = rect.size.width + {padding} * 2 - rect.size.height = rect.size.height + {padding} * 2 - rect.angle = 0 - - cfg.setCropRotatedRect(rect, True) - cfg.setResize({resize_width}, {resize_height}) - cfg.setKeepAspectRatio(False) - """ - elif platform.lower() == "rvc4": - cfg_content = f""" - cfg = ImageManipConfigV2() - rect = RotatedRect() - rect.center.x = (det.xmin + det.xmax) / 2 - rect.center.y = (det.ymin + det.ymax) / 2 - rect.size.width = det.xmax - det.xmin - rect.size.height = det.ymax - det.ymin - rect.size.width = rect.size.width + {padding} * 2 - rect.size.height = rect.size.height + {padding} * 2 - rect.angle = 0 - cfg.addCropRotatedRect(rect=rect, normalizedCoords=True) - cfg.setOutputSize({resize_width}, {resize_height}) - """ - else: - raise ValueError("Unsupported version") - - return f""" -try: - while True: - frame = node.inputs['preview'].get() - dets = node.inputs['det_in'].get() - - for i, det in enumerate(dets.detections): - if det.label not in {valid_labels}: - continue - - {cfg_content.strip()} - node.outputs['manip_cfg'].send(cfg) - node.outputs['manip_img'].send(frame) -except Exception as e: - node.warn(str(e)) -""" diff --git a/neural-networks/pose-estimation/human-pose/main.py b/neural-networks/pose-estimation/human-pose/main.py index 6037fdca7..ff314234e 100644 --- a/neural-networks/pose-estimation/human-pose/main.py +++ b/neural-networks/pose-estimation/human-pose/main.py @@ -1,9 +1,9 @@ from pathlib import Path import depthai as dai from depthai_nodes import ParsingNeuralNetwork, HRNetParser +from depthai_nodes.nodes.utils import generate_script_content from utils.arguments import initialize_argparser from utils.annotation_node import AnnotationNode -from utils.script import generate_script_content _, args = initialize_argparser() diff --git a/neural-networks/pose-estimation/human-pose/requirements.txt b/neural-networks/pose-estimation/human-pose/requirements.txt index 275cdb23e..6770fa70e 100644 --- a/neural-networks/pose-estimation/human-pose/requirements.txt +++ b/neural-networks/pose-estimation/human-pose/requirements.txt @@ -1,3 +1,3 @@ --extra-index-url https://artifacts.luxonis.com/artifactory/luxonis-python-release-local/ depthai>=3.0.0a11 -depthai-nodes>=0.1.1 \ No newline at end of file +git+https://github.com/luxonis/depthai-nodes.git@feat/detection-manip-config-script \ No newline at end of file diff --git a/neural-networks/pose-estimation/human-pose/utils/script.py b/neural-networks/pose-estimation/human-pose/utils/script.py deleted file mode 100644 index 46c8a411e..000000000 --- a/neural-networks/pose-estimation/human-pose/utils/script.py +++ /dev/null @@ -1,61 +0,0 @@ -from typing import List - - -def generate_script_content( - platform: str, - resize_width: int = 192, - resize_height: int = 256, - padding: float = 0.1, - valid_labels: List[int] = [0], -) -> str: - """The function generates the script content for the dai.Script node. It is used to crop and resize the input image based on the detected object.""" - - if platform.lower() == "rvc2": - cfg_content = f""" - cfg = ImageManipConfig() - rect = RotatedRect() - rect.center.x = (det.xmin + det.xmax) / 2 - rect.center.y = (det.ymin + det.ymax) / 2 - rect.size.width = det.xmax - det.xmin - rect.size.height = det.ymax - det.ymin - rect.size.width = rect.size.width + {padding} * 2 - rect.size.height = rect.size.height + {padding} * 2 - rect.angle = 0 - - cfg.setCropRotatedRect(rect, True) - cfg.setResize({resize_width}, {resize_height}) - cfg.setKeepAspectRatio(False) - """ - elif platform.lower() == "rvc4": - cfg_content = f""" - cfg = ImageManipConfigV2() - rect = RotatedRect() - rect.center.x = (det.xmin + det.xmax) / 2 - rect.center.y = (det.ymin + det.ymax) / 2 - rect.size.width = det.xmax - det.xmin - rect.size.height = det.ymax - det.ymin - rect.size.width = rect.size.width + {padding} * 2 - rect.size.height = rect.size.height + {padding} * 2 - rect.angle = 0 - cfg.addCropRotatedRect(rect=rect, normalizedCoords=True) - cfg.setOutputSize({resize_width}, {resize_height}) - """ - else: - raise ValueError("Unsupported version") - - return f""" -try: - while True: - frame = node.inputs['preview'].get() - dets = node.inputs['det_in'].get() - - for i, det in enumerate(dets.detections): - if det.label not in {valid_labels}: - continue - - {cfg_content.strip()} - node.outputs['manip_cfg'].send(cfg) - node.outputs['manip_img'].send(frame) -except Exception as e: - node.warn(str(e)) -"""