DepthAI
软件栈

本页目录

  • 流水线
  • 源代码

相机输出

Supported on:RVC2RVC4
该示例展示了DepthAIv3的功能,可以直接从Camera节点请求输出流,而无需创建和配置ImageManip节点。
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)
调整大小模式可以是 CROPSTRETCHLETTERBOX,当传感器宽高比(AR)与请求的宽高比不匹配时,这些模式就会发挥作用。更多信息(各模式的优缺点)请查看 输入帧宽高比不匹配文档。相机多输出示例展示了如何从Camera节点请求多个输出。这个示例需要DepthAI v3 API,参见安装说明

流水线

源代码

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}

需要帮助?

请前往 OAKChina 官网 获取技术支持或解答您的任何疑问。