# Warp

Warp node is used for image warping and dewarping, which can be used to undistort images from wide FOV cameras. The node can also
be used to apply a perspective transform to the image.

#### RVC2

Warp node uses underlying warp HW block (additional [docs
here](https://docs.luxonis.com/hardware/platform/rvc/rvc2.md#Robotics%20Vision%20Core%202%20(RVC2)-Hardware%20blocks%20and%20accelerators)),
with no extra resources (SHAVE/cmx cores). HW limitation: input and output width must be divisible by 16.

#### RVC4

Warp node is also run on Warp engine (HW block on [RVC4](https://docs.luxonis.com/hardware/platform/rvc/rvc4.md) chip). Note: at
the moment, chroma plane warping is not yet supported on RVC4, so only grayscale images can be warped (correctly). We're working
with our silicon vendor to enable this feature. The warp mesh must have at least 3 points in each direction, and `BYPASS`
(`NEAREST_NEIGHBOR`) interpolation is not supported on RVC4. Not all input sizes are supported on RVC4. With a 3x3 mesh and a
512x512 output, 640x512, 1024x768, 1280x800 and 1920x1080 inputs work, but 640x480, 800x600 and 1280x720 inputs stop the node.

## How to place it

#### Python

```python
with dai.Pipeline() as pipeline:
    warp = pipeline.create(dai.node.Warp)
```

#### C++

```cpp
dai::Pipeline pipeline;
auto warp = pipeline.create<dai::node::Warp>();
```

## Inputs and Outputs

## Usage

#### Python

```python
with dai.Pipeline() as pipeline:
    warp = pipeline.create(dai.node.Warp)
    # Create a custom warp mesh
    mesh = [
        dai.Point2f(20, 20), dai.Point2f(240, 20), dai.Point2f(460, 20),
        dai.Point2f(20, 240), dai.Point2f(240, 240), dai.Point2f(460, 240),
        dai.Point2f(20, 460), dai.Point2f(240, 460), dai.Point2f(460, 460),
    ]
    warp.setWarpMesh(mesh, 3, 3)
    warp.setOutputSize((512,512))
    warp.setMaxOutputFrameSize(512 * 512 * 3)

    # Warp interpolation mode, choose between BILINEAR, BICUBIC, BYPASS
    warp.setInterpolation(dai.Interpolation.BILINEAR)
```

#### C++

```cpp

dai::Pipeline pipeline;

auto warp = pipeline.create<dai::node::Warp>();
// Create a custom warp mesh
std::vector<dai::Point2f> mesh = {
    {20, 20}, {240, 20}, {460, 20},
    {20, 240}, {240, 240}, {460, 240},
    {20, 460}, {240, 460}, {460, 460},
};
warp->setWarpMesh(mesh, 3, 3);
warp->setOutputSize({512, 512});
warp->setMaxOutputFrameSize(512 * 512 * 3);

// Warp interpolation mode, choose between BILINEAR, BICUBIC, BYPASS
warp->setInterpolation(dai::Interpolation::BILINEAR);
```

## Examples of functionality

 * [Warp Mesh](https://docs.luxonis.com/software-v3/depthai/examples/warp/warp_mesh.md)

## Reference

### dai::node::Warp

Kind: class

Warp node. Capability to crop, resize, warp, ... incoming image frames.

#### Input inputImage

Kind: variable

Input image to be modified Default queue is blocking with size 8

#### Output out

Kind: variable

Outputs ImgFrame message that carries warped image.

#### void setOutputSize(const std::tuple< int, int > & size)

Kind: function

Sets output frame size in pixels parameters: size: width and height in pixels

#### void setOutputSize(int width, int height)

Kind: function

#### void setWarpMesh(const std::vector< Point2f > & meshData, int width, int height)

Kind: function

Set a custom warp mesh parameters: meshData: 2D plane of mesh points, starting from top left to bottom right; width: Width of
mesh; height: Height of mesh

#### void setWarpMesh(const std::vector< std::pair< float, float >> & meshData, int width, int height)

Kind: function

#### void setNumFramesPool(int numFramesPool)

Kind: function

Specify number of frames in pool. parameters: numFramesPool: How many frames should the pool have

#### void setMaxOutputFrameSize(int maxFrameSize)

Kind: function

Specify maximum size of output image. parameters: maxFrameSize: Maximum frame size in bytes

#### void setHwIds(const std::vector< int > & ids)

Kind: function

Specify which hardware warp engines to use parameters: ids: Which warp engines to use (0, 1, 2)

#### std::vector< int > getHwIds()

Kind: function

Retrieve which hardware warp engines to use.

#### void setInterpolation(dai::Interpolation interpolation)

Kind: function

Specify which interpolation method to use parameters: interpolation: type of interpolation

#### dai::Interpolation getInterpolation()

Kind: function

Retrieve which interpolation method to use.

#### DeviceNodeCRTP()

Kind: function

#### DeviceNodeCRTP(const std::shared_ptr< Device > & device)

Kind: function

#### DeviceNodeCRTP(std::unique_ptr< Properties > props)

Kind: function

#### DeviceNodeCRTP(std::unique_ptr< Properties > props, bool confMode)

Kind: function

#### DeviceNodeCRTP(const std::shared_ptr< Device > & device, std::unique_ptr< Properties > props, bool confMode)

Kind: function

### Need assistance?

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