# 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 underlyting warp HW block (additional [docs here](https://docs.luxonis.com/hardware/platform/rvc/rvc2.md)), with no
extra resources (SHAVE/cmx cores). HW limitation: 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.

## 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
    p1 = dai.Point2f(20, 20)
    p2 = dai.Point2f(460, 20)
    p3 = dai.Point2f(20, 460)
    p4 = dai.Point2f(460, 460)
    warp.setWarpMesh([p1,p2,p3,p4], 2, 2)
    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
dai::Point2f p1(20, 20);
dai::Point2f p2(460, 20);
dai::Point2f p3(20, 460);
dai::Point2f p4(460, 460);
warp->setWarpMesh({p1,p2,p3,p4}, 2, 2);
warp->setOutputSize({512, 512});
warp->setMaxOutputFrameSize(512 * 512 * 3);

// Warp interpolation mode, choose between BILINEAR, BICUBIC, BYPASS
warp->setInterpolation(dai::node::Warp::Properties::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(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(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.
