DepthAI v2 has been superseded by DepthAI v3. You are viewing legacy documentation.
此页面由 AI 自动翻译。查看英文原版
DepthAI 教程
DepthAI API 参考

本页目录

  • 演示
  • 设置
  • 源代码
  • 管道

RGB 视频

此示例演示了如何以低延迟使用高分辨率视频。与 RGB 预览 相比,此演示输出 NV12 帧,而 预览帧是 BGR 格式,不适合更大的分辨率(例如 1920x1080)。预览更适合 NN 或可视化目的。

类似示例:

演示

设置

请运行 安装脚本 以下载所有必需的依赖项。请注意,此脚本必须在 git 上下文中运行,因此您必须先下载 depthai-python 存储库,然后运行脚本
Command Line
1git clone https://github.com/luxonis/depthai-python.git
2cd depthai-python/examples
3python3 install_requirements.py
有关更多信息,请遵循 安装指南

源代码

Python

Python
GitHub
1#!/usr/bin/env python3
2
3import cv2
4import depthai as dai
5
6# Create pipeline
7pipeline = dai.Pipeline()
8
9# Define source and output
10camRgb = pipeline.create(dai.node.ColorCamera)
11xoutVideo = pipeline.create(dai.node.XLinkOut)
12
13xoutVideo.setStreamName("video")
14
15# Properties
16camRgb.setBoardSocket(dai.CameraBoardSocket.CAM_A)
17camRgb.setResolution(dai.ColorCameraProperties.SensorResolution.THE_1080_P)
18camRgb.setVideoSize(1920, 1080)
19
20xoutVideo.input.setBlocking(False)
21xoutVideo.input.setQueueSize(1)
22
23# Linking
24camRgb.video.link(xoutVideo.input)
25
26# Connect to device and start pipeline
27with dai.Device(pipeline) as device:
28
29    video = device.getOutputQueue(name="video", maxSize=1, blocking=False)
30
31    while True:
32        videoIn = video.get()
33
34        # Get BGR frame from NV12 encoded video frame to show with opencv
35        # Visualizing the frame on slower hosts might have overhead
36        cv2.imshow("video", videoIn.getCvFrame())
37
38        if cv2.waitKey(1) == ord('q'):
39            break

C++

1#include <iostream>
2
3// Includes common necessary includes for development using depthai library
4#include "depthai/depthai.hpp"
5
6int main() {
7    // Create pipeline
8    dai::Pipeline pipeline;
9
10    // Define source and output
11    auto camRgb = pipeline.create<dai::node::ColorCamera>();
12    auto xoutVideo = pipeline.create<dai::node::XLinkOut>();
13
14    xoutVideo->setStreamName("video");
15
16    // Properties
17    camRgb->setBoardSocket(dai::CameraBoardSocket::CAM_A);
18    camRgb->setResolution(dai::ColorCameraProperties::SensorResolution::THE_1080_P);
19    camRgb->setVideoSize(1920, 1080);
20
21    xoutVideo->input.setBlocking(false);
22    xoutVideo->input.setQueueSize(1);
23
24    // Linking
25    camRgb->video.link(xoutVideo->input);
26
27    // Connect to device and start pipeline
28    dai::Device device(pipeline);
29
30    auto video = device.getOutputQueue("video");
31
32    while(true) {
33        auto videoIn = video->get<dai::ImgFrame>();
34
35        // Get BGR frame from NV12 encoded video frame to show with opencv
36        // Visualizing the frame on slower hosts might have overhead
37        cv::imshow("video", videoIn->getCvFrame());
38
39        int key = cv::waitKey(1);
40        if(key == 'q' || key == 'Q') {
41            return 0;
42        }
43    }
44    return 0;
45}

管道

需要帮助?

请前往 Discussion Forum 获取技术支持或提出您可能有的任何其他问题。