# Warp

Warp 节点用于图像扭曲和去扭曲，可用来校正广角相机拍摄的图像。 该节点还可用于对图像应用透视变换。

#### RVC2

Warp 节点使用底层的 Warp 硬件模块（另外参考 [本文档](https://docs.luxonis.com/hardware/platform/rvc/rvc2.md)），无需额外资源（SHAVE/CMX 内核）。硬件限制：宽度必须能被 16 整除。

#### RVC4

Warp 节点也运行在 Warp 引擎上（[RVC4](https://docs.luxonis.com/hardware/platform/rvc/rvc4.md) 芯片上的硬件模块）。注意：目前 RVC4
尚不支持色度平面扭曲，因此只能（正确）扭曲灰度图像。我们正与芯片供应商合作以启用此功能。

## 如何放置

#### 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>();
```

## 输入与输出

## 使用方式

#### Python

```python
with dai.Pipeline() as pipeline:
    warp = pipeline.create(dai.node.Warp)
    # 创建自定义扭曲网格
    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)

    # 扭曲插值模式，可选 BILINEAR、BICUBIC、BYPASS
    warp.setInterpolation(dai.Interpolation.BILINEAR)
```

#### C++

```cpp
dai::Pipeline pipeline;

auto warp = pipeline.create<dai::node::Warp>();
// 创建自定义扭曲网格
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);

// 扭曲插值模式，可选 BILINEAR、BICUBIC、BYPASS
warp->setInterpolation(dai::node::Warp::Properties::Interpolation::BILINEAR);
```

## 功能示例

 * [扭曲网格](https://docs.luxonis.com/software-v3/depthai/examples/warp/warp_mesh.md)

## 参考

### 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

### 需要帮助？

请前往 [OAKChina 官网](https://www.oakchina.cn/) 获取技术支持或解答您的任何疑问。
