-228
opencv
assertion_error
ai_generated
true
cv::error: (-228:Unknown error code 228) The homography mask has invalid size in function 'cv::findHomography'
ID: opencv/homography-mask-invalid-size
94%Fix Rate
87%Confidence
1Evidence
2024-03-12First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 4.5.0 | active | — | — | — |
| 4.6.0 | active | — | — | — |
| 4.7.0 | active | — | — | — |
| 4.8.0 | active | — | — | — |
| 4.9.0 | active | — | — | — |
| 4.10.0 | active | — | — | — |
Root Cause
The output mask passed to findHomography has a size that does not match the number of input point pairs.
generic中文
传递给findHomography的输出掩码尺寸与输入点对数量不匹配。
Official Documentation
https://docs.opencv.org/4.x/d9/d0c/group__calib3d.html#ga4abc2e5c3f5b8c9e8f6d7a5b6c0d1e2fWorkarounds
-
95% success 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);
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);
-
90% success 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].
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].
中文步骤
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);
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].
Dead Ends
Common approaches that don't work:
-
80% fail
The mask must have exactly as many rows as the number of point pairs; an arbitrary size causes an assertion failure.
-
65% fail
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.