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

Need assistance?

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