DepthAI
Software Stack

ON THIS PAGE

  • Pipeline
  • Source code

Camera output

Supported on:RVC2RVC4
Example showcases DepthAIv3's functionality to request an output stream directly from the Camera node, instead of having to create and configure an ImageManip node.
Python
1output = camera_node.requestOutput(
2    size=(640, 480),
3    type=dai.ImgFrame.Type.BGR888p,
4    resize_mode=dai.ImgResizeMode.CROP,
5    fps=15
6)
Resize mode can be either CROP, STRETCH, or LETTERBOX, which come into play if there's a missmatch between sensor aspect ratio (AR) and requested aspect ratio. For more information (pros/cons of each) check Input frame AR missmatch documentation.Camera Multiple Outputs example showcases how to request multiple outputs from the Camera node.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
7with dai.Pipeline() as pipeline:
8    # Define source and output
9    cam = pipeline.create(dai.node.Camera).build()
10    videoQueue = cam.requestOutput((640,400)).createOutputQueue()
11
12    # Connect to device and start pipeline
13    pipeline.start()
14    while pipeline.isRunning():
15        videoIn = videoQueue.get()
16        assert isinstance(videoIn, dai.ImgFrame)
17        cv2.imshow("video", videoIn.getCvFrame())
18
19        if cv2.waitKey(1) == ord("q"):
20            break

C++

1#include <atomic>
2#include <csignal>
3#include <iostream>
4#include <memory>
5#include <opencv2/opencv.hpp>
6
7#include "depthai/depthai.hpp"
8
9std::atomic<bool> quitEvent(false);
10
11void signalHandler(int) {
12    quitEvent = true;
13}
14
15int main() {
16    signal(SIGTERM, signalHandler);
17    signal(SIGINT, signalHandler);
18
19    // Create device
20    std::shared_ptr<dai::Device> device = std::make_shared<dai::Device>();
21
22    // Create pipeline
23    dai::Pipeline pipeline(device);
24
25    // Create nodes
26    auto cam = pipeline.create<dai::node::Camera>()->build();
27    auto videoQueue = cam->requestOutput(std::make_pair(640, 400))->createOutputQueue();
28
29    // Start pipeline
30    pipeline.start();
31
32    while(pipeline.isRunning() && !quitEvent) {
33        auto videoIn = videoQueue->get<dai::ImgFrame>();
34        if(videoIn == nullptr) continue;
35
36        cv::imshow("video", videoIn->getCvFrame());
37
38        if(cv::waitKey(1) == 'q') {
39            break;
40        }
41    }
42
43    pipeline.stop();
44    pipeline.wait();
45
46    return 0;
47}

Need assistance?

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