From b291e9548664d3b2fae3db675c29aec7e355da95 Mon Sep 17 00:00:00 2001 From: zrezke Date: Tue, 27 Feb 2024 16:51:06 +0100 Subject: [PATCH] py-lints --- pipeline.json | 1 - rerun_py/depthai_viewer/_backend/device.py | 15 ++++++++------- .../_backend/device_configuration.py | 10 ++++++---- .../_backend/device_defaults/oak_t_default.py | 2 +- .../depthai_viewer/_backend/packet_handler.py | 19 +++++++++---------- .../depthai_viewer/install_requirements.py | 1 - 6 files changed, 24 insertions(+), 24 deletions(-) delete mode 100644 pipeline.json diff --git a/pipeline.json b/pipeline.json deleted file mode 100644 index 8be259b8cf54..000000000000 --- a/pipeline.json +++ /dev/null @@ -1 +0,0 @@ -{"assetStorage": [], "assets": {"map": {}}, "pipeline": {"connections": [{"node1Id": 4, "node1Output": "out", "node1OutputGroup": "", "node2Id": 3, "node2Input": "in", "node2InputGroup": ""}, {"node1Id": 0, "node1Output": "raw", "node1OutputGroup": "", "node2Id": 1, "node2Input": "in", "node2InputGroup": ""}], "globalProperties": {"calibData": null, "cameraTuningBlobSize": null, "cameraTuningBlobUri": "", "leonCssFrequencyHz": 700000000.0, "leonMssFrequencyHz": 700000000.0, "pipelineName": null, "pipelineVersion": null, "sippBufferSize": 18432, "sippDmaBufferSize": 16384, "xlinkChunkSize": -1}, "nodes": [[0, {"id": 0, "ioInfo": [[["", "video"], {"blocking": false, "group": "", "id": 12, "name": "video", "queueSize": 8, "type": 0, "waitForMessage": false}], [["", "still"], {"blocking": false, "group": "", "id": 10, "name": "still", "queueSize": 8, "type": 0, "waitForMessage": false}], [["", "isp"], {"blocking": false, "group": "", "id": 9, "name": "isp", "queueSize": 8, "type": 0, "waitForMessage": false}], [["", "preview"], {"blocking": false, "group": "", "id": 11, "name": "preview", "queueSize": 8, "type": 0, "waitForMessage": false}], [["", "raw"], {"blocking": false, "group": "", "id": 8, "name": "raw", "queueSize": 8, "type": 0, "waitForMessage": false}], [["", "frameEvent"], {"blocking": false, "group": "", "id": 7, "name": "frameEvent", "queueSize": 8, "type": 0, "waitForMessage": false}], [["", "inputConfig"], {"blocking": false, "group": "", "id": 6, "name": "inputConfig", "queueSize": 8, "type": 3, "waitForMessage": false}], [["", "inputControl"], {"blocking": true, "group": "", "id": 5, "name": "inputControl", "queueSize": 8, "type": 3, "waitForMessage": false}]], "name": "Camera", "properties": {"boardSocket": 4, "calibAlpha": null, "cameraName": "", "colorOrder": 0, "fp16": false, "fps": 30.0, "imageOrientation": -1, "initialControl": {"aeLockMode": false, "aeMaxExposureTimeUs": 0, "aeRegion": {"height": 0, "priority": 0, "width": 0, "x": 0, "y": 0}, "afRegion": {"height": 0, "priority": 0, "width": 0, "x": 0, "y": 0}, "antiBandingMode": 0, "autoFocusMode": 3, "awbLockMode": false, "awbMode": 0, "brightness": 0, "captureIntent": 0, "chromaDenoise": 0, "cmdMask": 0, "contrast": 0, "controlMode": 0, "effectMode": 0, "expCompensation": 0, "expManual": {"exposureTimeUs": 0, "frameDurationUs": 0, "sensitivityIso": 0}, "frameSyncMode": 0, "lensPosAutoInfinity": 0, "lensPosAutoMacro": 0, "lensPosition": 0, "lensPositionRaw": 0.0, "lowPowerNumFramesBurst": 0, "lowPowerNumFramesDiscard": 0, "lumaDenoise": 0, "saturation": 0, "sceneMode": 0, "sharpness": 0, "strobeConfig": {"activeLevel": 0, "enable": 0, "gpioNumber": 0}, "strobeTimings": {"durationUs": 0, "exposureBeginOffsetUs": 0, "exposureEndOffsetUs": 0}, "wbColorTemp": 0}, "interleaved": true, "isp3aFps": 0, "ispScale": {"horizDenominator": 0, "horizNumerator": 0, "vertDenominator": 0, "vertNumerator": 0}, "numFramesPoolIsp": 3, "numFramesPoolPreview": 4, "numFramesPoolRaw": 3, "numFramesPoolStill": 4, "numFramesPoolVideo": 4, "previewHeight": 300, "previewKeepAspectRatio": true, "previewWidth": 300, "rawPacked": null, "resolutionHeight": -1, "resolutionWidth": -1, "sensorCropX": -1.0, "sensorCropY": -1.0, "sensorType": -1, "stillHeight": -1, "stillWidth": -1, "videoHeight": -1, "videoWidth": -1, "warpMeshHeight": 0, "warpMeshSource": -1, "warpMeshStepHeight": 32, "warpMeshStepWidth": 32, "warpMeshUri": "", "warpMeshWidth": 0}}], [1, {"id": 1, "ioInfo": [[["", "in"], {"blocking": true, "group": "", "id": 4, "name": "in", "queueSize": 8, "type": 3, "waitForMessage": true}]], "name": "XLinkOut", "properties": {"maxFpsLimit": -1.0, "metadataOnly": false, "streamName": "thermal_cam"}}], [2, {"id": 2, "ioInfo": [[["", "out"], {"blocking": false, "group": "", "id": 3, "name": "out", "queueSize": 8, "type": 0, "waitForMessage": false}]], "name": "IMU", "properties": {"batchReportThreshold": 5, "enableFirmwareUpdate": false, "imuSensors": [{"changeSensitivity": 0, "reportRate": 100, "sensitivityEnabled": false, "sensitivityRelative": false, "sensorId": 20}, {"changeSensitivity": 0, "reportRate": 100, "sensitivityEnabled": false, "sensitivityRelative": false, "sensorId": 21}], "maxBatchReports": 10}}], [3, {"id": 3, "ioInfo": [[["", "in"], {"blocking": true, "group": "", "id": 2, "name": "in", "queueSize": 8, "type": 3, "waitForMessage": true}]], "name": "XLinkOut", "properties": {"maxFpsLimit": -1.0, "metadataOnly": false, "streamName": "sys_logger"}}], [4, {"id": 4, "ioInfo": [[["", "out"], {"blocking": false, "group": "", "id": 1, "name": "out", "queueSize": 8, "type": 0, "waitForMessage": false}]], "name": "SystemLogger", "properties": {"rateHz": 0.10000000149011612}}]]}} \ No newline at end of file diff --git a/rerun_py/depthai_viewer/_backend/device.py b/rerun_py/depthai_viewer/_backend/device.py index 3864e6bd7894..450d1a5ccaa8 100644 --- a/rerun_py/depthai_viewer/_backend/device.py +++ b/rerun_py/depthai_viewer/_backend/device.py @@ -1,9 +1,9 @@ import itertools +import os import time from queue import Empty as QueueEmpty from queue import Queue from typing import Dict, List, Optional, Tuple -import os import depthai as dai import numpy as np @@ -15,7 +15,6 @@ ) from depthai_sdk.components.tof_component import Component from numpy.typing import NDArray -from depthai_viewer.install_requirements import model_dir import depthai_viewer as viewer from depthai_viewer._backend.device_configuration import ( @@ -41,8 +40,9 @@ Message, WarningMessage, ) -from depthai_viewer._backend.packet_handler import PacketHandler, PacketHandlerContext, DetectionContext +from depthai_viewer._backend.packet_handler import DetectionContext, PacketHandler, PacketHandlerContext from depthai_viewer._backend.store import Store +from depthai_viewer.install_requirements import model_dir class XlinkStatistics: @@ -84,7 +84,7 @@ class Device: _sys_info_q: Optional[Queue] = None # type: ignore[type-arg] _pipeline_start_t: Optional[float] = None _queues: List[Tuple[Component, ComponentOutput]] = [] - _dai_queues: List[Tuple[dai.Node, Optional[PacketHandlerContext]]] = [] + _dai_queues: List[Tuple[dai.Node, dai.DataOutputQueue, Optional[PacketHandlerContext]]] = [] # _profiler = cProfile.Profile() @@ -274,8 +274,9 @@ def reconnect_to_oak(self) -> Message: def _get_component_by_socket(self, socket: dai.CameraBoardSocket) -> Optional[CameraComponent]: component = list( - filter( - lambda c: isinstance(c, CameraComponent) and c.node.getBoardSocket() == socket, self._oak._components + filter( # type: ignore[arg-type] + lambda c: isinstance(c, CameraComponent) and c.node.getBoardSocket() == socket, + self._oak._components if self._oak else [], ) ) if not component: @@ -386,7 +387,7 @@ def update_pipeline(self, runtime_only: bool) -> Message: else: self._create_auto_pipeline_config(config) - create_dai_queues_after_start: Dict[str, (dai.Node, Optional[PacketHandlerContext])] = {} + create_dai_queues_after_start: Dict[str, Tuple[dai.Node, Optional[PacketHandlerContext]]] = {} self._stereo = None self._packet_handler.reset() self._sys_info_q = None diff --git a/rerun_py/depthai_viewer/_backend/device_configuration.py b/rerun_py/depthai_viewer/_backend/device_configuration.py index c4a42c843e65..1b2e93a691c5 100644 --- a/rerun_py/depthai_viewer/_backend/device_configuration.py +++ b/rerun_py/depthai_viewer/_backend/device_configuration.py @@ -56,7 +56,9 @@ def to_runtime_controls(self) -> Dict[str, Any]: "align": ( "RECTIFIED_LEFT" if self.align == dai.CameraBoardSocket.LEFT - else "RECTIFIED_RIGHT" if self.align == dai.CameraBoardSocket.RIGHT else "CENTER" + else "RECTIFIED_RIGHT" + if self.align == dai.CameraBoardSocket.RIGHT + else "CENTER" ), "lr_check": self.lr_check, "lrc_check_threshold": self.lrc_threshold, @@ -275,9 +277,9 @@ class DeviceProperties(BaseModel): # type: ignore[misc] id: str cameras: List[CameraFeatures] = [] imu: Optional[ImuKind] - stereo_pairs: List[Tuple[dai.CameraBoardSocket, dai.CameraBoardSocket]] = ( - [] - ) # Which cameras can be paired for stereo + stereo_pairs: List[ + Tuple[dai.CameraBoardSocket, dai.CameraBoardSocket] + ] = [] # Which cameras can be paired for stereo default_stereo_pair: Optional[Tuple[dai.CameraBoardSocket, dai.CameraBoardSocket]] = None info: DeviceInfo = DeviceInfo() diff --git a/rerun_py/depthai_viewer/_backend/device_defaults/oak_t_default.py b/rerun_py/depthai_viewer/_backend/device_defaults/oak_t_default.py index a990530906ef..13e42e87d545 100644 --- a/rerun_py/depthai_viewer/_backend/device_defaults/oak_t_default.py +++ b/rerun_py/depthai_viewer/_backend/device_defaults/oak_t_default.py @@ -1,9 +1,9 @@ import depthai as dai from depthai_viewer._backend.device_configuration import ( + AiModelConfiguration, CameraConfiguration, CameraSensorResolution, PipelineConfiguration, - AiModelConfiguration, ) config = PipelineConfiguration( diff --git a/rerun_py/depthai_viewer/_backend/packet_handler.py b/rerun_py/depthai_viewer/_backend/packet_handler.py index 5e805bb12f23..24e80a1dc4b5 100644 --- a/rerun_py/depthai_viewer/_backend/packet_handler.py +++ b/rerun_py/depthai_viewer/_backend/packet_handler.py @@ -7,7 +7,6 @@ from depthai_sdk.classes.packets import ( # PointcloudPacket, BasePacket, DepthPacket, - Detection, DetectionPacket, DisparityDepthPacket, FramePacket, @@ -17,16 +16,15 @@ from depthai_sdk.components import CameraComponent, Component, NNComponent, StereoComponent from depthai_sdk.components.tof_component import ToFComponent from numpy.typing import NDArray +from pydantic import BaseModel import depthai_viewer as viewer from depthai_viewer._backend.store import Store from depthai_viewer._backend.topic import Topic from depthai_viewer.components.rect2d import RectFormat -from pydantic import BaseModel - -class PacketHandlerContext(BaseModel): +class PacketHandlerContext(BaseModel): # type: ignore[misc] class Config: arbitrary_types_allowed = True @@ -64,7 +62,7 @@ def set_camera_intrinsics_getter( # type: ignore[assignment, misc] self._get_camera_intrinsics = camera_intrinsics_getter - def log_dai_packet(self, node: dai.Node, packet: dai.Buffer, context: PacketHandlerContext) -> None: + def log_dai_packet(self, node: dai.Node, packet: dai.Buffer, context: Optional[PacketHandlerContext]) -> None: if isinstance(packet, dai.ImgFrame): board_socket = None if isinstance(node, dai.node.ColorCamera): @@ -78,8 +76,9 @@ def log_dai_packet(self, node: dai.Node, packet: dai.Buffer, context: PacketHand else: print("Unknown node type:", type(node), "for packet:", type(packet)) elif isinstance(packet, dai.ImgDetections): - if not isinstance(context, DetectionContext): + if context is None or not isinstance(context, DetectionContext): print("Invalid context for detections packet", context) + return self._on_dai_detections(packet, context) else: print("Unknown dai packet type:", type(packet)) @@ -274,10 +273,10 @@ def _on_age_gender_packet(self, packet: TwoStagePacket, component: NNComponent) def _rect_from_detection(self, detection: dai.ImgDetection, max_height: int, max_width: int) -> List[int]: return [ - max(min(detection.xmin, max_width), 0) * max_width, - max(min(detection.xmax, max_height), 0) * max_height, - max(min(detection.ymax, max_width), 0) * max_width, - max(min(detection.ymin, max_height), 0) * max_height, + int(max(min(detection.xmin, max_width), 0) * max_width), + int(max(min(detection.xmax, max_height), 0) * max_height), + int(max(min(detection.ymax, max_width), 0) * max_width), + int(max(min(detection.ymin, max_height), 0) * max_height), ] diff --git a/rerun_py/depthai_viewer/install_requirements.py b/rerun_py/depthai_viewer/install_requirements.py index 36af4c210b8c..1a5cac475e19 100644 --- a/rerun_py/depthai_viewer/install_requirements.py +++ b/rerun_py/depthai_viewer/install_requirements.py @@ -5,7 +5,6 @@ import subprocess import sys import traceback -from typing import Any, Dict from pathlib import Path # type: ignore[attr-defined]