# cv::error: (-215:Assertion failed) src1.type() == CV_8UC1 && src2.type() == CV_8UC1 in function 'cv::StereoBM::compute'

- **ID:** `opencv/stereo-bm-disparity-type`
- **Domain:** opencv
- **Category:** type_error
- **Error Code:** `-215`
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

The input images to StereoBM must be single-channel 8-bit grayscale images; color images or other types cause this assertion.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 4.5.0 | active | — | — |
| 4.6.0 | active | — | — |
| 4.7.0 | active | — | — |
| 4.8.0 | active | — | — |
| 4.9.0 | active | — | — |

## Workarounds

1. **Load images as grayscale using cv2.imread with cv2.IMREAD_GRAYSCALE flag, or convert color images to grayscale using cv2.cvtColor(img_left, cv2.COLOR_BGR2GRAY).** (95% success)
   ```
   Load images as grayscale using cv2.imread with cv2.IMREAD_GRAYSCALE flag, or convert color images to grayscale using cv2.cvtColor(img_left, cv2.COLOR_BGR2GRAY).
   ```
2. **Check the image type with img.dtype and img.shape before calling compute; ensure dtype is uint8 and len(shape)==2.** (85% success)
   ```
   Check the image type with img.dtype and img.shape before calling compute; ensure dtype is uint8 and len(shape)==2.
   ```

## Dead Ends

- **Convert images to float32 before passing to StereoBM** — StereoBM requires CV_8UC1 (uint8), not float. Converting to float will cause a different type assertion error. (85% fail)
- **Resize images to be larger** — The issue is data type, not image size. (95% fail)
- **Use cv2.cvtColor with COLOR_BGR2GRAY on already grayscale images** — If the image is already single-channel, cvtColor will fail; the correct fix is to ensure the image is loaded as grayscale. (50% fail)
