DepthAI
Software Stack

ON THIS PAGE

  • Pipeline
  • Source code

Display all cameras

Supported on:RVC2RVC4
Display all camera streams on the host using OpenCV. It uses the Camera node to get camera streams in highest resolution available (using cam.requestFullResolutionOutput()).This example requires the DepthAI v3 API, see installation instructions.

Pipeline

Source code

Python

Python
GitHub
1#!/usr/bin/env python3
2
3import cv2
4import depthai as dai
5
6# Create pipeline
7device = dai.Device()
8with dai.Pipeline(device) as pipeline:
9    outputQueues = {}
10    sockets = device.getConnectedCameras()
11    for socket in sockets:
12        cam = pipeline.create(dai.node.Camera).build(socket)
13        outputQueues[str(socket)] = cam.requestFullResolutionOutput().createOutputQueue()
14
15    pipeline.start()
16    while pipeline.isRunning():
17        for name in outputQueues.keys():
18            queue = outputQueues[name]
19            videoIn = queue.get()
20            assert isinstance(videoIn, dai.ImgFrame)
21            # Visualizing the frame on slower hosts might have overhead
22            cv2.imshow(name, videoIn.getCvFrame())
23
24        if cv2.waitKey(1) == ord("q"):
25            break

C++

1#include <iostream>
2#include <map>
3#include <memory>
4#include <opencv2/opencv.hpp>
5#include <string>
6
7#include "depthai/depthai.hpp"
8
9int main() {
10    // Create device
11    std::shared_ptr<dai::Device> device = std::make_shared<dai::Device>();
12
13    // Create pipeline
14    dai::Pipeline pipeline(device);
15
16    // Map to store output queues
17    std::map<std::string, std::shared_ptr<dai::MessageQueue>> outputQueues;
18
19    // Get connected cameras
20    auto sockets = device->getConnectedCameras();
21    for(const auto& socket : sockets) {
22        auto cam = pipeline.create<dai::node::Camera>();
23        cam->build(socket);
24        auto output = cam->requestFullResolutionOutput();
25        outputQueues[dai::toString(socket)] = output->createOutputQueue();
26    }
27
28    pipeline.start();
29    while(true) {
30        for(const auto& [name, queue] : outputQueues) {
31            auto videoIn = queue->get<dai::ImgFrame>();
32            if(videoIn != nullptr) {
33                // Visualizing the frame on slower hosts might have overhead
34                cv::imshow(name, videoIn->getCvFrame());
35            }
36        }
37
38        if(cv::waitKey(1) == 'q') {
39            break;
40        }
41    }
42
43    return 0;
44}

Need assistance?

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