How luxonis/depthai works
Project Type & Purpose
• This is a full-featured demo application for DepthAI. It not only demonstrates different AI models and camera pipelines (such as UVC streaming and video recording) but also acts as a backbone for rapid prototyping on OAK camera hardware.
• The project contains both demo applications (apps/uvc, apps/record) and the underlying DepthAI SDK library (in depthai_sdk) with various integrations (such as ROS) and utilities for tasks like calibration, neural network (NN) configurations, hardware interactions, and visualization.
Analyzing the File Structure for Architectural Clues
• Top-Level Directories: Notice distinct directories like apps, depthai_sdk, gui, launcher, and resources. Each plays a separate role:
• apps: Contains application-specific entry points (e.g., record and uvc demos).
• depthai_sdk: Contains the core SDK code including components, managers, NN model definitions, integrations (ROS, Roboflow, etc.), recorders, visualizers, and other utilities.
• gui: Provides a QT-based graphical interface.
• launcher: Hosts a separate launcher module with its own scripts to initiate the demo, especially on Windows.
• resources: Contains neural network (NN) models and calibration boards.
• The extensive subdirectories within depthai_sdk (such as components, managers, readers, recorders, and integrations) indicate that the system is modular in nature and follows clean layering principles.
Main Components
a. User Interface Layer:
• CLI / Console: Invoked via command-line arguments in depthai_demo.py.
• GUI: The QT-based interface (in gui/) for a clickable, user-friendly experience.
• Launcher: The launcher module (in launcher/) that helps initialize the demo apps.
b. Application Layer:
• DepthAI Demo Application: The central script (depthai_demo.py) that routes commands for different demo areas (like UVC streaming or recording).
• Apps: “uvc” and “record” apps under the apps/ directory, which enable distinct functionalities (streaming pipelines and multi-format video recording).
c. SDK / Core Library Layer:
• DepthAI SDK: The core library (depthai_sdk/) offering a rich set of modules.
• Components: e.g., camera_component, imu_component, nn_component, stereo_component.
• Managers: e.g., pipeline_manager, encoding_manager, preview_manager, nnet_manager – these manage individual aspects of the workflow.
• NN Models: Folder “nn_models” provides predefined neural network configurations and handlers for models like YOLO, MobileNet, etc.
• Integrations: ROS and other external integrations to communicate with third-party systems.
• Readers & Recorders: Abstractions to read inputs (from webcams or file sources) and to record outputs (to mp4, MCAP, or ROS bag files).
• Trigger Actions: Modules implementing triggers and actions based on sensor input or detections.
d. Hardware & External Interfaces:
• OAK Camera Hardware: Highlight the physical depth camera devices that get managed by the SDK.
• Docker and OS-level Dependencies: Illustrate the containerization aspect (via Dockerfile, installation scripts) and OS integration (e.g., calibration scripts and autostart).
e. Resource Storage:
• Resources Directory: Houses neural network blobs, JSON configurations, calibration boards, etc.
Relationships and Data Flows
• Demo Application interacting with the SDK’s core modules (managers, components, NN models) which in turn communicate with both the hardware (camera devices) and external integration services.
• From the hardware through the SDK’s reader components.
• Through internal processing modules (like NN inference, image encoding).
• Then output through visualizers or recorders.
• Feedback loops such as triggers activating actions (through the trigger_action modules).
• Optionally incorporate deployment/control flows (for Docker usage and installation scripts) as a supporting layer.
Architectural Patterns or Principles
• Modularity & Separation of Concerns: Each major functionality (UI, processing, hardware abstraction) is in its own module.
• Extensibility & Integration: The SDK is designed for integration (e.g., ROS, custom NN models) and rapid prototyping.
• Layered Architecture: Distinct layers for UI, demo/application logic, and core SDK functionality.