# 特征跟踪器

特征跟踪器用于检测帧上的关键点（特征）并在下一帧中对其进行跟踪。 有效特征通过Harris评分或Shi-Tomasi方法获取。 默认的目标特征数量为320，默认的最大特征数量为480。 它支持720p和480p分辨率。

## 如何放置

#### Python

```python
pipeline = dai.Pipeline()
featureTracker = pipeline.create(dai.node.FeatureTracker)
```

#### C++

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

## 输入与输出

## 使用方法

#### Python

```python
pipeline = dai.Pipeline()
featureTracker = pipeline.create(dai.node.FeatureTracker)

# 设置SHAVE数量和内存切片数量为最大值
featureTracker.setHardwareResources(2, 2)
# 指定等待配置消息到达inputConfig输入
featureTracker.setWaitForConfigInput(True)

# 必须将特征跟踪器与图像帧源（单目/彩色相机或XLinkIn节点）结合使用
```

#### C++

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

// 设置SHAVE数量和内存切片数量为最大值
featureTracker->setHardwareResources(2, 2);
// 指定等待配置消息到达inputConfig输入
featureTracker->setWaitForConfigInput(true);

// 必须将特征跟踪器与图像帧源（单目/彩色相机或XLinkIn节点）结合使用
```

## 功能示例

 * [特征检测器](https://docs.luxonis.com/software/depthai/examples/feature_detector.md)
 * [特征跟踪器](https://docs.luxonis.com/software/depthai/examples/feature_tracker.md)

### 图像网格

为了使特征分布在整幅图像上，图像被划分为若干网格，每个网格独立处理。 每个网格有一个 目标特征数量 = 帧目标特征数 / 网格总数。 网格数量可在水平和垂直方向上配置。默认网格数量为 4（水平）× 4（垂直）。这意味着每个网格的默认目标特征数量为： 320 /
(4 * 4) = 20。注意：如果已跟踪点的新坐标恰好位于一个已满的网格中，该点不会被移除，因此特征数量可能超过此限制。

### 初始Harris阈值

该阈值控制将被检测的特征的最小强度。将此值设为0 启用自动阈值，用于适应不同场景。如果纹理丰富， 需要增大此值以限制检测到的点数。每个网格有自己的阈值。

### 新特征准入条件

新特征的准入条件如下：

 * 特征之间不能相距太近（最小距离准则 - 默认值为50，单位为像素的平方欧氏距离），
 * 特征的Harris评分足够高，
 * 网格中有足够的空间容纳该特征（尚未达到目标特征数）。

### 已跟踪特征的Harris阈值

一旦检测到特征并开始跟踪，需要在每帧上更新其Harris评分。 此阈值定义了移除此类特征的点。目标是尽可能长时间地跟踪点， 因此准入点的条件高于已跟踪点的条件。这就是该值通常小于检测阈值的原因。

### 特征维护

算法需要决定在后续帧中移除哪些特征以及保留哪些特征。注意，已跟踪特征优先于新特征。 它将移除以下特征：

 * 跟踪误差过大（未正确跟踪），
 * Harris评分过小（可配置阈值）。

### 新位置计算

前一帧特征在当前帧的新位置可通过两种方式计算：

 1. 使用金字塔Lucas-Kanade光流法。
 2. 使用密集运动估计硬件模块（块匹配器）。

## 参考

### depthai.node.FeatureTracker(depthai.Node)

Kind: Class

FeatureTracker node. Performs feature tracking and reidentification using motion
estimation between 2 consecutive frames.

#### getWaitForConfigInput(self) -> bool: bool

Kind: Method

See also:
setWaitForConfigInput

Returns:
True if wait for inputConfig message, false otherwise

#### setHardwareResources(self, numShaves: typing.SupportsInt, numMemorySlices: typing.SupportsInt)

Kind: Method

Specify allocated hardware resources for feature tracking. 2 shaves/memory
slices are required for optical flow, 1 for corner detection only.

Parameter ``numShaves``:
Number of shaves. Maximum 2.

Parameter ``numMemorySlices``:
Number of memory slices. Maximum 2.

#### setWaitForConfigInput(self, wait: bool)

Kind: Method

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

Parameter ``wait``:
True to wait for configuration message, false otherwise.

#### initialConfig

Kind: Property

Initial config to use for feature tracking.

#### inputConfig

Kind: Property

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

#### inputImage

Kind: Property

Input message with frame data on which feature tracking is performed. Default
queue is non-blocking with size 4.

#### outputFeatures

Kind: Property

Outputs TrackedFeatures message that carries tracked features results.

#### passthroughInputImage

Kind: Property

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

### 需要帮助？

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