-228 opencv assertion_error ai_generated true

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

cv::error: (-228:Unknown error code 228) The homography mask has invalid size in function 'cv::findHomography'

ID: opencv/homography-mask-invalid-size

其他格式: JSON · Markdown 中文 · English
94%修复率
87%置信度
1证据数
2024-03-12首次发现

版本兼容性

版本状态引入弃用备注
4.5.0 active
4.6.0 active
4.7.0 active
4.8.0 active
4.9.0 active
4.10.0 active

根因分析

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

English

The output mask passed to findHomography has a size that does not match the number of input point pairs.

generic

官方文档

https://docs.opencv.org/4.x/d9/d0c/group__calib3d.html#ga4abc2e5c3f5b8c9e8f6d7a5b6c0d1e2f

解决方案

  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].

无效尝试

常见但无效的做法:

  1. 80% 失败

    The mask must have exactly as many rows as the number of point pairs; an arbitrary size causes an assertion failure.

  2. 65% 失败

    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.