# cv::error: (-215:Assertion failed) _src.type() == CV_8UC1 in function 'cv::findContours'

- **ID:** `opencv/contours-not-found-in-binary-image`
- **Domain:** opencv
- **Category:** type_error
- **Error Code:** `-215`
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

findContours requires an 8-bit single-channel binary image, but the input is multi-channel or non-8-bit.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 4.5.5 | active | — | — |
| 4.8.0 | active | — | — |
| 4.9.0 | active | — | — |

## Workarounds

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)** (95% success)
   ```
   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)** (85% success)
   ```
   edges = cv2.Canny(img_gray, 50, 150)
contours, _ = cv2.findContours(edges, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
   ```

## Dead Ends

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