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

- **ID:** `opencv/opticalflow-calcopticalflowfarneback-input-type-mismatch`
- **领域:** opencv
- **类别:** type_error
- **错误码:** `-215`
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

calcOpticalFlowFarneback 要求输入图像为单通道 8 位（灰度图），但提供了多通道或不同深度的图像。

## 版本兼容性

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

## 解决方案

1. ```
   Convert the input image to grayscale before calling calcOpticalFlowFarneback: gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY); ensure gray is a single-channel 8-bit image.
   ```
2. ```
   If the input is already grayscale but has a different depth (e.g., 16-bit), use cv2.convertScaleAbs to convert to CV_8U: gray = cv2.convertScaleAbs(gray, alpha=(255.0/65535.0)).
   ```

## 无效尝试

- **** — The function signature expects a single channel; a 3-channel input will still trigger the assertion. (90% 失败率)
- **** — The original multi-channel image remains unchanged, causing the assertion to fail again. (80% 失败率)
