此页面由 AI 自动翻译。查看英文原版
DepthAI
软件栈

本页目录

  • 演示
  • 管道
  • 源代码

ImageManip 多重操作

Supported on:RVC2RVC4
此示例展示了在单个 ImageManip 节点中连续执行多个操作:请注意,操作的顺序很重要,因为它们是按设置的顺序应用的。

演示

此示例需要 DepthAI v3 API,请参阅 安装说明

管道

源代码

Python

Python
GitHub
1import depthai as dai
2import cv2
3
4pipeline = dai.Pipeline()
5
6camRgb = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_A)
7manip = pipeline.create(dai.node.ImageManip)
8
9
10manip.initialConfig.setOutputSize(1270, 710, dai.ImageManipConfig.ResizeMode.LETTERBOX)
11manip.initialConfig.addCrop(50, 100, 500, 500)
12manip.initialConfig.addFlipVertical()
13manip.initialConfig.setFrameType(dai.ImgFrame.Type.NV12)
14manip.setMaxOutputFrameSize(2709360)
15
16camRgb.requestOutput((1920, 1080)).link(manip.inputImage)
17
18out = manip.out.createOutputQueue()
19
20pipeline.start()
21
22print(manip.initialConfig)
23
24while True:
25    inFrame = out.get()
26    if inFrame is not None:
27        cv2.imshow("Show frame", inFrame.getCvFrame())
28        key = cv2.waitKey(1)
29        if key == ord('q'):
30            break

C++

1#include <atomic>
2#include <csignal>
3#include <memory>
4
5#include "depthai/depthai.hpp"
6#include "depthai/pipeline/datatype/ImgFrame.hpp"
7#include "depthai/pipeline/node/host/Display.hpp"
8
9std::atomic<bool> quitEvent(false);
10
11void signalHandler(int) {
12    quitEvent = true;
13}
14
15int main(int argc, char** argv) {
16    signal(SIGTERM, signalHandler);
17    signal(SIGINT, signalHandler);
18
19    std::shared_ptr<dai::Device> device = nullptr;
20    if(argc <= 1) {
21        device = std::make_shared<dai::Device>();
22    } else {
23        device = std::make_shared<dai::Device>(argv[1]);
24    }
25    dai::Pipeline pipeline(device);
26
27    auto camRgb = pipeline.create<dai::node::Camera>()->build(dai::CameraBoardSocket::CAM_A);
28    auto manip = pipeline.create<dai::node::ImageManip>();
29
30    manip->setMaxOutputFrameSize(4000000);
31    manip->initialConfig->setOutputSize(1280, 720, dai::ImageManipConfig::ResizeMode::LETTERBOX);
32    manip->initialConfig->setBackgroundColor(100, 100, 100);
33    manip->initialConfig->addRotateDeg(45);
34    manip->initialConfig->addCrop(100, 100, 800, 600);
35    manip->initialConfig->addFlipVertical();
36    manip->initialConfig->setFrameType(dai::ImgFrame::Type::RGB888p);
37
38    auto* rgbOut = camRgb->requestOutput({1920, 1080});
39    rgbOut->link(manip->inputImage);
40    auto outputQueue = manip->out.createOutputQueue();
41    pipeline.start();
42    while(pipeline.isRunning() && !quitEvent) {
43        auto imgFrame = outputQueue->get<dai::ImgFrame>();
44        cv::imshow("Manipulated Frame", imgFrame->getCvFrame());
45        int key = cv::waitKey(1);
46        if(key == 'q') {
47            break;
48        }
49    }
50
51    pipeline.stop();
52    pipeline.wait();
53
54    return 0;
55}

需要帮助?

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