# cv::error: (-215：断言失败) nfeatures > 0 在函数 'cv::goodFeaturesToTrack' 中

- **ID:** `opencv/good-features-to-track-empty`
- **领域:** opencv
- **类别:** assertion_error
- **错误码:** `-215`
- **验证级别:** ai_generated
- **修复率:** 92%

## 根因

goodFeaturesToTrack 被调用时 maxCorners 设置为 0 或负值，这是无效的，因为该函数至少需要检测一个角点。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 4.5.5 | active | — | — |
| 4.6.0 | active | — | — |
| 4.7.0 | active | — | — |
| 4.8.0 | active | — | — |
| 4.9.0 | active | — | — |

## 解决方案

1. ```
   将 maxCorners 设置为正整数，例如：corners = cv2.goodFeaturesToTrack(gray, maxCorners=100, qualityLevel=0.01, minDistance=10)。确保 maxCorners > 0。
   ```
2. ```
   如果未知要检测的角点数量，使用合理的默认值如 1000，然后后续过滤：corners = cv2.goodFeaturesToTrack(gray, maxCorners=1000, qualityLevel=0.01, minDistance=10)。
   ```
3. ```
   在调用前验证 maxCorners：if max_corners <= 0: raise ValueError('maxCorners must be positive')。同时确保图像是灰度且非空。
   ```

## 无效尝试

- **** — Increasing the qualityLevel parameter to a very high value (e.g., 0.99) hoping to find more corners but maxCorners is still 0 (30% 失败率)
- **** — Assuming the error is from the image being too dark and applying histogram equalization without fixing maxCorners (25% 失败率)
- **** — Passing maxCorners as a float (e.g., 0.5) which gets truncated to 0 in some language bindings (20% 失败率)
