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

- **ID:** `opencv/homography-invalid-mask`
- **Domain:** opencv
- **Category:** assertion_error
- **Error Code:** `-228`
- **Verification:** ai_generated
- **Fix Rate:** 88%

## Root Cause

The mask parameter passed to findHomography has a different number of rows than the number of input point pairs, causing a size mismatch assertion.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 4.5.5 | active | — | — |
| 4.6.0 | active | — | — |
| 4.7.0 | active | — | — |
| 4.8.0 | active | — | — |
| 4.9.0 | active | — | — |

## Workarounds

1. **Ensure the mask is a 1D or 2D numpy array of type np.uint8 with length equal to the number of point pairs. Example: mask = np.ones(len(src_points), dtype=np.uint8)** (90% success)
   ```
   Ensure the mask is a 1D or 2D numpy array of type np.uint8 with length equal to the number of point pairs. Example: mask = np.ones(len(src_points), dtype=np.uint8)
   ```
2. **If using RANSAC, let OpenCV generate the mask automatically by passing None for the mask parameter: H, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC, 5.0)** (95% success)
   ```
   If using RANSAC, let OpenCV generate the mask automatically by passing None for the mask parameter: H, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC, 5.0)
   ```
3. **When manually constructing a mask from matching results, flatten the mask to 1D: mask = matches_mask.flatten().astype(np.uint8)** (85% success)
   ```
   When manually constructing a mask from matching results, flatten the mask to 1D: mask = matches_mask.flatten().astype(np.uint8)
   ```

## Dead Ends

- **** — Assuming the mask must be a list of booleans instead of a numpy array of type uint8 or int32 (35% fail)
- **** — Resizing the mask to match the number of points without checking that the mask was generated from the correct matching step (25% fail)
- **** — Using np.ones((n,1)) instead of np.ones((n,1), dtype=np.uint8) — OpenCV expects specific dtype (20% fail)
