DepthAI
Software Stack

ON THIS PAGE

  • Setup
  • Source code

XLink Bridge

Supported on:RVC2RVC4
This example shows how to access the implicit XLink bridge created when a stream crosses the host-device boundary and adjust transport settings such as FPS limit.

Setup

This example requires the DepthAI v3 API, see installation instructions.

Source code

Python

Python
GitHub
1#!/usr/bin/env python3
2
3import argparse
4import cv2
5import depthai as dai
6
7
8parser = argparse.ArgumentParser()
9parser.add_argument(
10    "--fps_limit", type=float, default=3.0, help="Limit output FPS (float, optional)"
11)
12args = parser.parse_args()
13
14# Create pipeline
15with dai.Pipeline() as pipeline:
16    # Define source and output
17    cam = pipeline.create(dai.node.Camera).build()
18    videoOutput = cam.requestOutput((640, 400), fps=30)
19    videoQueue = videoOutput.createOutputQueue()
20
21    pipeline.build()
22
23    # Optionally update internal settings
24    # Note: xlink bridges are only generated after pipeline.build() is called
25    xlinkBridge = videoOutput.getXLinkBridge()
26    assert xlinkBridge is not None
27    assert isinstance(xlinkBridge, dai.node.internal.XLinkOutBridge)
28    xlinkBridge.xLinkOut.setFpsLimit(args.fps_limit)
29
30    # Connect to device and start pipeline
31    pipeline.start()
32    while pipeline.isRunning():
33        videoIn = videoQueue.get()
34        assert isinstance(videoIn, dai.ImgFrame)
35        cv2.imshow("video", videoIn.getCvFrame())
36
37        if cv2.waitKey(1) == ord("q"):
38            break

C++

1#include <cassert>
2#include <memory>
3#include <opencv2/opencv.hpp>
4
5#include "depthai/depthai.hpp"
6
7int main() {
8    // Create device
9    std::shared_ptr<dai::Device> device = std::make_shared<dai::Device>();
10
11    // Create pipeline
12    dai::Pipeline pipeline(device);
13
14    // Create nodes
15    auto cam = pipeline.create<dai::node::Camera>()->build();
16    auto videoOutput = cam->requestOutput(std::make_pair(640, 400));
17    auto videoQueue = videoOutput->createOutputQueue();
18
19    pipeline.build();
20
21    // Optionally update internal settings
22    // Note: xlink bridges are only generated after pipeline.build() is called
23    auto xlinkBridge = videoOutput->getXLinkBridge();
24    assert(xlinkBridge != nullptr);
25    assert(xlinkBridge->xLinkOut != nullptr);
26    xlinkBridge->xLinkOut->setFpsLimit(3.0);
27
28    // Start pipeline
29    pipeline.start();
30
31    while(true) {
32        auto videoIn = videoQueue->get<dai::ImgFrame>();
33        if(videoIn == nullptr) continue;
34
35        cv::imshow("video", videoIn->getCvFrame());
36
37        if(cv::waitKey(1) == 'q') {
38            break;
39        }
40    }
41
42    return 0;
43}

Need assistance?

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