# ImageManip resize

This example showcases how to use
[ImageManip](https://docs.luxonis.com/software-v3/depthai/depthai-components/nodes/image_manip.md) 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](https://docs.luxonis.com/software-v3/depthai/tutorials/resolution-techniques.md).

## Demo

This example requires the DepthAI v3 API, see [installation instructions](https://docs.luxonis.com/software-v3/depthai.md).

## Pipeline

## Source code

#### Python

```python
import depthai as dai
import cv2

pipeline = dai.Pipeline()
device = pipeline.getDefaultDevice()

camRgb = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_A)
manip = pipeline.create(dai.node.ImageManip)

# GPU is not available on RVC2 and some RVC4 devices
manip.setBackend(dai.node.ImageManip.Backend.GPU if device.hasGPU() else
                 dai.node.ImageManip.Backend.CPU)

manip.initialConfig.setOutputSize(300, 300, dai.ImageManipConfig.ResizeMode.STRETCH)

camOut = camRgb.requestOutput((1920, 1080))
camOut.link(manip.inputImage)

manipQ = manip.out.createOutputQueue()
camQ = camOut.createOutputQueue()

pipeline.start()

while True:
    if manipQ.has():
        cv2.imshow("Manip frame", manipQ.get().getCvFrame())
    if camQ.has():
        cv2.imshow("Camera frame", camQ.get().getCvFrame())
    key = cv2.waitKey(1)
    if key == ord('q'):
        break
```

#### C++

```cpp
#include <atomic>
#include <csignal>

#include "depthai/depthai.hpp"
#include "depthai/pipeline/datatype/ImgFrame.hpp"
#include "depthai/pipeline/node/Camera.hpp"
#include "depthai/pipeline/node/ImageManip.hpp"

std::atomic<bool> quitEvent(false);

void signalHandler(int) {
    quitEvent = true;
}

int main(int argc, char** argv) {
    signal(SIGTERM, signalHandler);
    signal(SIGINT, signalHandler);

    std::shared_ptr<dai::Device> device = nullptr;
    if(argc <= 1) {
        device = std::make_shared<dai::Device>();
    } else {
        device = std::make_shared<dai::Device>(argv[1]);
    }
    dai::Pipeline pipeline(device);

    auto camRgb = pipeline.create<dai::node::Camera>()->build(dai::CameraBoardSocket::CAM_A);
    auto manip = pipeline.create<dai::node::ImageManip>();

    // GPU is not available on RVC2 and some RVC4 devices
    manip->setBackend(device->hasGPU() ? dai::node::ImageManip::Backend::GPU : dai::node::ImageManip::Backend::CPU);

    // Resize to 400x400 and avoid stretching by cropping from the center
    manip->initialConfig->setOutputSize(400, 400, dai::ImageManipConfig::ResizeMode::CENTER_CROP);
    // Set output frame type
    manip->initialConfig->setFrameType(dai::ImgFrame::Type::RGB888i);

    camRgb->requestOutput((std::make_pair(1920, 1080)))->link(manip->inputImage);
    auto outputQueue = manip->out.createOutputQueue();

    pipeline.start();
    while(pipeline.isRunning() && !quitEvent) {
        auto imgFrame = outputQueue->get<dai::ImgFrame>();
        cv::imshow("Resized Frame", imgFrame->getCvFrame());
        int key = cv::waitKey(1);
        if(key == 'q') {
            break;
        }
    }

    pipeline.stop();
    pipeline.wait();

    return 0;
}
```

### Need assistance?

Head over to [Discussion Forum](https://discuss.luxonis.com/) for technical support or any other questions you might have.
