-215
opencv
type_error
ai_generated
true
cv::error: (-215:断言失败) src1.type() == CV_8UC1 在函数 'calcOpticalFlowFarneback' 中
cv::error: (-215:Assertion failed) src1.type() == CV_8UC1 in function 'calcOpticalFlowFarneback'
ID: opencv/opticalflow-calcopticalflowfarneback-input-type-mismatch
90%修复率
88%置信度
1证据数
2023-03-12首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| 4.5.5 | active | — | — | — |
| 4.6.0 | active | — | — | — |
| 4.7.0 | active | — | — | — |
| 4.8.0 | active | — | — | — |
| 4.9.0 | active | — | — | — |
根因分析
calcOpticalFlowFarneback 要求输入图像为单通道 8 位(灰度图),但提供了多通道或不同深度的图像。
English
calcOpticalFlowFarneback requires the input image to be single-channel 8-bit (grayscale), but a multi-channel or different depth image was provided.
官方文档
https://docs.opencv.org/4.x/dc/d6b/group__video__track.html#ga5d10ebbd59fe09c1f0f8e3c9d0d2c5b9解决方案
-
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.
-
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)).
无效尝试
常见但无效的做法:
-
90% 失败
The function signature expects a single channel; a 3-channel input will still trigger the assertion.
-
80% 失败
The original multi-channel image remains unchanged, causing the assertion to fail again.