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

本页目录

  • 演示
  • 设置
  • 源代码
  • 流图

ImageManip 瓦片

帧瓦片(Frame tiling)在某些场景下可能很有用,例如将一个大型帧输入到一个输入尺寸不那么大的 NeuralNetwork 中。在这种情况下, 您可以将大型帧瓦片化为多个较小的帧,然后将这些较小的帧输入到 NeuralNetwork 中。在此示例中,我们使用 2 个 ImageManip 将原始的 1000x500 预览帧分割成两个 500x500 的帧。

演示

将预览瓦片化为 2 个帧/瓦片

设置

请运行 安装脚本 以下载所有必需的依赖项。请注意,此脚本必须在 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
9camRgb = pipeline.create(dai.node.ColorCamera)
10camRgb.setPreviewSize(1000, 500)
11camRgb.setInterleaved(False)
12maxFrameSize = camRgb.getPreviewHeight() * camRgb.getPreviewWidth() * 3
13
14# In this example we use 2 imageManips for splitting the original 1000x500
15# preview frame into 2 500x500 frames
16manip1 = pipeline.create(dai.node.ImageManip)
17manip1.initialConfig.setCropRect(0, 0, 0.5, 1)
18manip1.setMaxOutputFrameSize(maxFrameSize)
19camRgb.preview.link(manip1.inputImage)
20
21manip2 = pipeline.create(dai.node.ImageManip)
22manip2.initialConfig.setCropRect(0.5, 0, 1, 1)
23manip2.setMaxOutputFrameSize(maxFrameSize)
24camRgb.preview.link(manip2.inputImage)
25
26xout1 = pipeline.create(dai.node.XLinkOut)
27xout1.setStreamName('out1')
28manip1.out.link(xout1.input)
29
30xout2 = pipeline.create(dai.node.XLinkOut)
31xout2.setStreamName('out2')
32manip2.out.link(xout2.input)
33
34# Connect to device and start pipeline
35with dai.Device(pipeline) as device:
36    # Output queue will be used to get the rgb frames from the output defined above
37    q1 = device.getOutputQueue(name="out1", maxSize=4, blocking=False)
38    q2 = device.getOutputQueue(name="out2", maxSize=4, blocking=False)
39
40    while True:
41        if q1.has():
42            cv2.imshow("Tile 1", q1.get().getCvFrame())
43
44        if q2.has():
45            cv2.imshow("Tile 2", q2.get().getCvFrame())
46
47        if cv2.waitKey(1) == ord('q'):
48            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    using namespace std;
8
9    // Create pipeline
10    dai::Pipeline pipeline;
11
12    auto camRgb = pipeline.create<dai::node::ColorCamera>();
13    camRgb->setPreviewSize(1000, 500);
14    camRgb->setInterleaved(false);
15    auto maxFrameSize = camRgb->getPreviewHeight() * camRgb->getPreviewHeight() * 3;
16
17    // In this example we use 2 imageManips for splitting the original 1000x500
18    // preview frame into 2 500x500 frames
19    auto manip1 = pipeline.create<dai::node::ImageManip>();
20    manip1->initialConfig.setCropRect(0, 0, 0.5, 1);
21    // Flip functionality
22    manip1->initialConfig.setHorizontalFlip(true);
23    manip1->setMaxOutputFrameSize(maxFrameSize);
24    camRgb->preview.link(manip1->inputImage);
25
26    auto manip2 = pipeline.create<dai::node::ImageManip>();
27    manip2->initialConfig.setCropRect(0.5, 0, 1, 1);
28    // Flip functionality
29    manip1->initialConfig.setVerticalFlip(true);
30    manip2->setMaxOutputFrameSize(maxFrameSize);
31    camRgb->preview.link(manip2->inputImage);
32
33    auto xout1 = pipeline.create<dai::node::XLinkOut>();
34    xout1->setStreamName("out1");
35    manip1->out.link(xout1->input);
36
37    auto xout2 = pipeline.create<dai::node::XLinkOut>();
38    xout2->setStreamName("out2");
39    manip2->out.link(xout2->input);
40
41    dai::Device device(pipeline);
42
43    auto q1 = device.getOutputQueue("out1", 8, false);
44    auto q2 = device.getOutputQueue("out2", 8, false);
45
46    while(true) {
47        auto in1 = q1->tryGet<dai::ImgFrame>();
48        if(in1) {
49            cv::imshow("Tile 1", in1->getCvFrame());
50        }
51
52        auto in2 = q2->tryGet<dai::ImgFrame>();
53        if(in2) {
54            cv::imshow("Tile 2", in2->getCvFrame());
55        }
56
57        int key = cv::waitKey(1);
58        if(key == 'q' || key == 'Q') return 0;
59    }
60    return 0;
61}

流图

需要帮助?

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