# 转换节点

转换节点 用于将 NNData 消息转换为 ImgFrame。这在应用需要将 NeuralNetwork 节点的输出输入到仅接受 ImgFrame 的节点时非常有用。

## 节点属性

 * outputFrameType - 输出帧的类型。该类型应与 NN 输出帧类型相同。

 * offset - 应用于输出帧的偏移量。默认为 0。

 * scale - 应用于输出帧的比例因子。默认为 1。

偏移量和比例因子用于定义像素值的线性变换。公式为 output = input * scale + offset。

## 如何放置

#### Python

```python
pipeline = dai.Pipeline()
cast = pipeline.create(dai.node.Cast)
```

#### C++

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

## 输入和输出

## 使用方法

#### Python

```python
pipeline = dai.Pipeline()

nn = pipeline.create(dai.node.NeuralNetwork)
# 加载自定义 blob
nn.setBlobPath("path_to_blob")

cast = pipeline.create(dai.node.Cast)
cast.setOutputFrameType(dai.ImgFrame.Type.BGR888p)
cast.setScale(1)

# 将 NN 的输出连接到 Cast 的输入
nn.out.link(cast.input)

# 通过 XLink 将转换后的输出发送到主机
xout = pipeline.create(dai.node.XLinkOut)
xout.setStreamName("castOut")
cast.output.link(xout.input)
```

#### C++

```cpp
dai::Pipeline pipeline;

auto nn = pipeline.create<dai::node::NeuralNetwork>();
// 加载自定义 blob
nn->setBlobPath("path_to_blob");

auto cast = pipeline.create<dai::node::Cast>();
cast->setOutputFrameType(dai::ImgFrame::Type::BGR888p);
cast->setScale(1);

// 将 NN 的输出连接到 Cast 的输入
nn->out.link(cast->input);

// 通过 XLink 将转换后的输出发送到主机
auto xout = pipeline.create<dai::node::XLinkOut>();
xout->setStreamName("castOut");
cast->output.link(xout->input);
```

## 功能示例

 * [NN 模糊转换](https://docs.luxonis.com/software/depthai/examples/cast_blur.md)
 * [NN 拼接转换](https://docs.luxonis.com/software/depthai/examples/cast_concat.md)
 * [NN 差分转换](https://docs.luxonis.com/software/depthai/examples/cast_diff.md)

## 参考

### depthai.node.Cast(depthai.Node)

Kind: Class

Cast node.

#### setNumFramesPool(self, arg0: typing.SupportsInt) -> Cast: Cast

Kind: Method

Set number of frames in pool

Parameter ``numFramesPool``:
Number of frames in pool

#### setOffset(self, arg0: typing.SupportsFloat) -> Cast: Cast

Kind: Method

Set offset

Parameter ``offset``:
Offset

#### setOutputFrameType(self, arg0: depthai.RawImgFrame.Type) -> Cast: Cast

Kind: Method

Set output frame type

Parameter ``outputType``:
Output frame type

#### setScale(self, arg0: typing.SupportsFloat) -> Cast: Cast

Kind: Method

Set scale

Parameter ``scale``:
Scale

#### input

Kind: Property

Input NNData or ImgFrame message.

#### output

Kind: Property

Output ImgFrame message.

#### passthroughInput

Kind: Property

Passthrough input message.

### 需要帮助？

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