# ImageAlign

ImageAlign 节点 用于对齐传感器帧，例如将深度图（来自 ToF/立体视觉）对齐到彩色帧（RGB-D），或在指定深度平面时将温度/热成像帧对齐到彩色帧（RGB-Thermal）。

## 如何放置

#### Python

```python
with dai.Pipeline() as pipeline:
    img_align = pipeline.create(dai.node.ImageAlign)
```

#### C++

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

## 输入与输出

## 工作原理

ImageAlign 将 input 帧对齐到 inputAlignTo 帧。inputAlignTo 仅被读取一次以提取帧元数据，然后根据两个传感器之间的外参标定，对 input 帧进行重投影并对齐。

## 用法

#### Python

```python
with dai.Pipeline() as pipeline:
    rgb_cam = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_A)
    video_stream = rgb_cam.requestOutput(size=(1280, 960))

    # 创建左/右立体相机及 StereoDepth 节点
    left = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_B)
    right = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_C)
    stereo = pipeline.create(dai.node.StereoDepth)

    left.requestOutput(size=(640, 400)).link(stereo.left)
    right.requestOutput(size=(640, 400)).link(stereo.right)

    # 创建 ImageAlign 节点并将立体深度对齐到 RGB 流
    img_align = pipeline.create(dai.node.ImageAlign)
    stereo.depth.link(align.input)
    video_stream.link(align.inputAlignTo)

    # 如果需要同步对齐后的深度和彩色流，可以使用 Sync 节点
    sync = pipeline.create(dai.node.Sync)
    img_align.outputAligned.link(sync.inputs['aligned_depth'])
    video_stream.link(sync.inputs["color"])

    # 创建输出队列，以便将同步帧传送到主机
    queue = sync.out.createOutputQueue()

    # ...
```

#### C++

```cpp
dai::Pipeline pipeline;

// 创建 RGB 相机
auto rgbCam = pipeline.create<dai::node::Camera>()->build(dai::CameraBoardSocket::CAM_A);
auto videoStream = rgbCam->requestOutput({1280, 960});

// 创建左、右立体相机
auto left = pipeline.create<dai::node::Camera>()->build(dai::CameraBoardSocket::CAM_B);
auto right = pipeline.create<dai::node::Camera>()->build(dai::CameraBoardSocket::CAM_C);
auto stereo = pipeline.create<dai::node::StereoDepth>();

left->requestOutput({640, 400})->link(stereo->left);
right->requestOutput({640, 400})->link(stereo->right);

// 创建 ImageAlign 节点
auto imgAlign = pipeline.create<dai::node::ImageAlign>();
stereo->depth.link(imgAlign->input);
videoStream.link(imgAlign->inputAlignTo);

// 创建 Sync 节点
auto sync = pipeline.create<dai::node::Sync>();
imgAlign->outputAligned.link(sync->inputs["aligned_depth"]);
videoStream.link(sync->inputs["color"]);

// 创建输出队列
auto queue = sync->out.createOutputQueue();
// ...
```

## 功能示例

 * [深度对齐](https://docs.luxonis.com/software-v3/depthai/examples/image_align/depth_align.md) - 对齐并混合 RGB 和深度帧。

## 参考

### dai::node::ImageAlign

Kind: class

ImageAlign node. Calculates spatial location data on a set of ROIs on depth map.

#### std::shared_ptr< ImageAlignConfig > initialConfig

Kind: variable

Initial config to use when calculating spatial location data.

#### Input inputConfig

Kind: variable

Input message with ability to modify parameters in runtime. Default queue is non-blocking with size 4.

#### Input input

Kind: variable

Input message. Default queue is non-blocking with size 4.

#### Input inputAlignTo

Kind: variable

Input align to message. Default queue is non-blocking with size 1.

#### Output outputAligned

Kind: variable

Outputs ImgFrame message that is aligned to inputAlignTo.

#### Output passthroughInput

Kind: variable

Passthrough message on which the calculation was performed. Suitable for when input queue is set to non-blocking behavior.

#### ImageAlign & setOutputSize(int alignWidth, int alignHeight)

Kind: function

Specify the output size of the aligned image

#### ImageAlign & setOutKeepAspectRatio(bool keep)

Kind: function

Specify whether to keep aspect ratio when resizing

#### ImageAlign & setInterpolation(Interpolation interp)

Kind: function

Specify interpolation method to use when resizing

#### ImageAlign & setNumShaves(int numShaves)

Kind: function

Specify number of shaves to use for this node

#### ImageAlign & setNumFramesPool(int numFramesPool)

Kind: function

Specify number of frames in the pool

#### void setRunOnHost(bool runOnHost)

Kind: function

Specify whether to run on host or device By default, the node will run on device.

#### bool runOnHost()

Kind: function

Check if the node is set to run on host

#### void run()

Kind: function

#### 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/) 获取技术支持或解答您的任何疑问。
