# cv::error: (-215:断言失败) _src.type() == CV_8UC1 在函数 'cv::findContours' 中

- **ID:** `opencv/contours-not-found-in-binary-image`
- **领域:** opencv
- **类别:** type_error
- **错误码:** `-215`
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

findContours 需要8位单通道二值图像，但输入图像是多通道或非8位类型。

## 版本兼容性

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

## 解决方案

1. ```
   img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
_, img_bin = cv2.threshold(img_gray, 127, 255, cv2.THRESH_BINARY)
contours, _ = cv2.findContours(img_bin, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
   ```
2. ```
   edges = cv2.Canny(img_gray, 50, 150)
contours, _ = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
   ```

## 无效尝试

- **** — Grayscale may still have multiple channels (e.g., 3-channel grayscale) or be 16-bit. findContours explicitly needs CV_8UC1. (60% 失败率)
- **** — Canny output is binary but may still have non-zero values outside 0-255 if not properly normalized; thresholding ensures binary. (40% 失败率)
- **** — Resize does not change channel count; the image remains 3-channel. (70% 失败率)
