# AprilTag

AprilTag 节点接收 [ImgFrame](https://docs.luxonis.com/software-v3/depthai/depthai-components/messages/img_frame.md) 作为输入，并输出检测到的
AprilTag 标记（[AprilTags](https://docs.luxonis.com/software-v3/depthai/depthai-components/messages/april_tags.md) 消息）。它基于
[AprilRobotics/apriltag](https://github.com/AprilRobotics/apriltag) 仓库，并在 CPU 上运行优化后的检测算法（在
[RVC4](https://docs.luxonis.com/hardware/platform/rvc/rvc4.md) 八核设备上本地运行，或者在基于
[RVC2](https://docs.luxonis.com/hardware/platform/rvc/rvc2.md) 的设备上运行于主机端）。

AprilTag 标记是一种视觉 [fiducial marker](https://en.wikipedia.org/wiki/Fiducial_marker)，因此与 ArUco、ARTag 和 ARToolKit 标记类似。

## 如何放置

#### Python

```python
pipeline = dai.Pipeline()
hostCamera = pipeline.create(dai.node.Camera).build()
aprilTagNode = pipeline.create(dai.node.AprilTag)
# Link 1920x1080 output to AprilTag input
hostCamera.requestOutput((1920, 1080)).link(aprilTagNode.inputImage)
# Create output queue for passthrough frames
passthroughOutputQueue = aprilTagNode.passthroughInputImage.createOutputQueue()
# Create output queue for detected AprilTags
outQueue = aprilTagNode.out.createOutputQueue()
```

#### C++

```cpp
dai::Pipeline pipeline;
auto cameraNode = pipeline.create<dai::node::Camera>()->build();
auto aprilTagNode = pipeline.create<dai::node::AprilTag>();
// Link 1920x1080 output to AprilTag input
auto outputCam = cameraNode->requestOutput(std::make_pair(1920, 1080));
outputCam->link(aprilTagNode->inputImage);
// Create output queue for passthrough frames
auto passthroughOutputQueue = aprilTagNode->passthroughInputImage.createOutputQueue();
// Create output queue for detected AprilTags
auto outQueue = aprilTagNode->out.createOutputQueue();
```

## 输入和输出

## 限制

#### RVC2

在 [RVC2](https://docs.luxonis.com/hardware/platform/rvc/rvc2.md) 设备上，AprilTag 节点运行于主机计算机，因此性能受限于主机 CPU。

#### RVC4

[RVC4](https://docs.luxonis.com/hardware/platform/rvc/rvc4.md) 可以处理 1080P 帧 约 190FPS，同时占用 25% 的 CPU。我们使用
[这个脚本](https://gist.github.com/Erol444/ede0301758156ef0e457f744954d3137) 进行了性能基准测试，结果如下：

```bash
[441340706] [10.12.101.114] [1725552371.591] [BenchmarkIn(3)] [warning] FPS: 191.80461
[441340706] [10.12.101.114] [1725552371.592] [BenchmarkIn(3)] [warning] Messages took 52.13639 s
[441340706] [10.12.101.114] [1725552371.593] [BenchmarkIn(3)] [warning] Average latency is 0 s
```

## 功能示例

 * [从摄像头获取 AprilTags](https://docs.luxonis.com/software-v3/depthai/examples/april_tags/april_tags.md)
 * [从摄像头获取 AprilTags（12MP）](https://docs.luxonis.com/software-v3/depthai/examples/april_tags/april_tags_12mp.md)
 * [在图像回放上获取 AprilTags](https://docs.luxonis.com/software-v3/depthai/examples/april_tags/april_tags_replay.md)

## 参考

### dai::node::AprilTag

Kind: class

AprilTag node.

#### std::shared_ptr< AprilTagConfig > initialConfig

Kind: variable

Initial config to use when calculating spatial location data.

#### Input inputConfig

Kind: variable

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

#### Input inputImage

Kind: variable

Input message with depth data used to retrieve spatial information about detected object. Default queue is non-blocking with size
4.

#### Output out

Kind: variable

Outputs AprilTags message that carries spatial location results.

#### Output outConfig

Kind: variable

Outputs AprilTagConfig message that contains current configuration.

#### Output passthroughInputImage

Kind: variable

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

#### AprilTag()

Kind: function

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

Kind: function

#### void setWaitForConfigInput(bool wait)

Kind: function

Specify whether or not wait until configuration message arrives to inputConfig Input. parameters: wait: True to wait for
configuration message, false otherwise.

#### bool getWaitForConfigInput()

Kind: function

Get whether or not wait until configuration message arrives to inputConfig Input.

#### void setNumThreads(int numThreads)

Kind: function

Set number of threads to use for AprilTag detection. parameters: numThreads: Number of threads to use.

#### int getNumThreads()

Kind: function

Get number of threads to use for AprilTag detection. return: Number of threads to use.

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

#### void buildInternal()

Kind: function

Function called from within the

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