Software Stack
DepthAI

ON THIS PAGE

  • Auto Reconnect
  • Pipeline
  • Source code

Auto Reconnect

Demonstrates setting a reconnection callback and limited retry attempts on the device. The example opens a simple camera preview; unplug the device briefly to see reconnection attempts reported via the callback.This example requires the DepthAI v3 API, see installation instructions.

Pipeline

Source code

Python
C++

Python

Python
GitHub
1#!/usr/bin/env python3
2
3import cv2
4import depthai as dai
5
6
7
8def callback(x: dai.Device.ReconnectionStatus):
9    print(f"Reconnecting state {x}")
10
11# Create pipeline
12device = dai.Device()
13device.setMaxReconnectionAttempts(3, callback)
14
15# You can try unplugging the camera to see the reconnection in action
16with dai.Pipeline(device) as pipeline:
17    # Define source and output
18    cam = pipeline.create(dai.node.Camera).build()
19    videoQueue = cam.requestOutput((640,400)).createOutputQueue()
20
21    # Connect to device and start pipeline
22    pipeline.start()
23    while pipeline.isRunning():
24        videoIn = videoQueue.get()
25        assert isinstance(videoIn, dai.ImgFrame)
26        cv2.imshow("video", videoIn.getCvFrame())
27
28        if cv2.waitKey(1) == ord("q"):
29            break

Need assistance?

Head over to Discussion Forum for technical support or any other questions you might have.