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

本页目录

  • 演示
  • 管道
  • 源代码
Claude CodeCodexCursor
Luxonis 智能体工具包为你常用的编程智能体加载 Luxonis 上下文与技能,更快地基于 OAK 开发应用。
安装工具包

ImageManip 多重操作

最后更新
Supported on:RVC2RVC4
此示例展示了多个 ImageManip 操作的连续执行(一个接一个):所有这些都在管道中的单个 ImageManip 节点内完成。请注意,操作顺序很重要,因为操作是按照它们设置的顺序应用的。

演示

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

管道

源代码

Python

Python
GitHub
1import depthai as dai
2import cv2
3
4with dai.Pipeline() as pipeline:
5
6    camRgb = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_A)
7    manip = pipeline.create(dai.node.ImageManip)
8
9
10    manip.initialConfig.setOutputSize(1270, 710, dai.ImageManipConfig.ResizeMode.LETTERBOX)
11    manip.initialConfig.addCrop(50, 100, 500, 500)
12    manip.initialConfig.addFlipVertical()
13    manip.initialConfig.setFrameType(dai.ImgFrame.Type.NV12)
14    manip.setMaxOutputFrameSize(2709360)
15
16    camRgb.requestOutput((1920, 1080)).link(manip.inputImage)
17
18    out = manip.out.createOutputQueue()
19
20    pipeline.start()
21
22    print(manip.initialConfig)
23
24    while 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}

需要帮助?

请访问讨论论坛以获取技术支持或您可能有的任何其他问题。