DepthAI
Software Stack

ON THIS PAGE

  • Demo
  • Pipeline
  • Source code

ImageManip resize

Supported on:RVC2RVC4
This example showcases how to use ImageManip node to resize the input image. Because aspect ratio isn't the same (input image: 16:9, output image: 1:1), the ResizeMode takes an effect and the output image is stretched. You can find more information about resize modes here.

Demo

This example requires the DepthAI v3 API, see installation instructions.

Pipeline

Source code

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
9manip.initialConfig.setOutputSize(300, 300, dai.ImageManipConfig.ResizeMode.STRETCH)
10
11camOut = camRgb.requestOutput((1920, 1080))
12camOut.link(manip.inputImage)
13
14manipQ = manip.out.createOutputQueue()
15camQ = camOut.createOutputQueue()
16
17pipeline.start()
18
19while True:
20    if manipQ.has():
21        cv2.imshow("Manip frame", manipQ.get().getCvFrame())
22    if camQ.has():
23        cv2.imshow("Camera frame", camQ.get().getCvFrame())
24    key = cv2.waitKey(1)
25    if key == ord('q'):
26        break

C++

1#include "depthai/depthai.hpp"
2#include "depthai/pipeline/datatype/ImgFrame.hpp"
3#include "depthai/pipeline/node/Camera.hpp"
4#include "depthai/pipeline/node/ImageManip.hpp"
5
6int main(int argc, char** argv) {
7    std::shared_ptr<dai::Device> device = nullptr;
8    if(argc <= 1) {
9        device = std::make_shared<dai::Device>();
10    } else {
11        device = std::make_shared<dai::Device>(argv[1]);
12    }
13    dai::Pipeline pipeline(device);
14
15    auto camRgb = pipeline.create<dai::node::Camera>()->build(dai::CameraBoardSocket::CAM_A);
16    auto manip = pipeline.create<dai::node::ImageManip>();
17
18    // Resize to 400x400 and avoid stretching by cropping from the center
19    manip->initialConfig->setOutputSize(400, 400, dai::ImageManipConfig::ResizeMode::CENTER_CROP);
20    // Set output frame type
21    manip->initialConfig->setFrameType(dai::ImgFrame::Type::RGB888i);
22
23    camRgb->requestOutput((std::make_pair(1920, 1080)))->link(manip->inputImage);
24    auto outputQueue = manip->out.createOutputQueue();
25
26    pipeline.start();
27    while(pipeline.isRunning()) {
28        auto imgFrame = outputQueue->get<dai::ImgFrame>();
29        cv::imshow("Resized Frame", imgFrame->getCvFrame());
30        int key = cv::waitKey(1);
31        if(key == 'q') {
32            break;
33        }
34    }
35}

Need assistance?

Head over to Discussion Forum for technical support or any other questions you might have.