# cv::error: (-228:未知错误码228) 单应性矩阵掩码尺寸无效 在函数 'cv::findHomography' 中

- **ID:** `opencv/homography-mask-invalid-size`
- **领域:** opencv
- **类别:** assertion_error
- **错误码:** `-228`
- **验证级别:** ai_generated
- **修复率:** 94%

## 根因

传递给findHomography的输出掩码尺寸与输入点对数量不匹配。

## 版本兼容性

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

## 解决方案

1. ```
   Ensure the mask has the correct size: cv::Mat mask; cv::findHomography(srcPoints, dstPoints, cv::RANSAC, 3.0, mask); The mask is automatically resized by the function if passed as an output Mat. Do not pre-allocate it. Example: std::vector<cv::Point2f> src, dst; cv::Mat mask; cv::findHomography(src, dst, cv::RANSAC, 3.0, mask);
   ```
2. ```
   If using Python, simply call mask = None and let the function handle it: mask = cv.findHomography(src_pts, dst_pts, cv.RANSAC, 3.0, mask=None)[1].
   ```

## 无效尝试

- **** — The mask must have exactly as many rows as the number of point pairs; an arbitrary size causes an assertion failure. (80% 失败率)
- **** — In certain overloads, omitting the mask is allowed, but if a mask is provided, it must be correctly sized; using an empty Mat can still trigger this error if the function expects a non-empty mask. (65% 失败率)
