DepthAI Python Library

3.5.0 · active · verified Thu Apr 16

The `depthai` Python library provides an API to interact with Luxonis OAK (OpenCV AI Kit) devices, enabling users to build sophisticated computer vision and AI applications with on-device processing. It supports various nodes for camera input, neural inference, depth estimation, and data output. The current version is 3.5.0, with a rapid release cadence introducing new features and improvements, often alongside firmware updates.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart code initializes a DepthAI pipeline to capture a 1080p color stream from the OAK-D's RGB camera, resizes it to 300x300 for preview, and displays it using OpenCV. Ensure `opencv-python` is installed (`pip install opencv-python`).

import depthai as dai
import cv2

# Create pipeline
pipeline = dai.Pipeline()

# Define source and output nodes
camRgb = pipeline.create(dai.node.ColorCamera)
xoutRgb = pipeline.create(dai.node.XLinkOut)

xoutRgb.setStreamName("rgb")

# Properties for ColorCamera
camRgb.setPreviewSize(300, 300) # Output resolution for preview stream
camRgb.setBoardSocket(dai.CameraBoardSocket.RGB)
camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
camRgb.setInterleaved(False) # Non-interleaved (separate R, G, B planes)

# Link nodes: camera preview output to XLinkOut input
camRgb.preview.link(xoutRgb.input)

# Connect to device and start pipeline
with dai.Device(pipeline) as device:
    print(f"Connected to OAK-D with MxId: {device.get=}")

    # Get output queue for the RGB stream
    qRgb = device.getOutputQueue(name="rgb", maxSize=4, blocking=False)

    while True:
        inRgb = qRgb.tryGet()

        if inRgb is not None:
            # Get a NumPy array from the image frame and display it
            frame = inRgb.getCvFrame()
            cv2.imshow("rgb", frame)

        # Wait for 'q' key to exit
        if cv2.waitKey(1) == ord('q'):
            break

view raw JSON →