{
  "id": "opencv/homography-invalid-mask",
  "signature": "cv::error: (-228:Unknown error code 228) The homography mask has invalid size in function 'findHomography'",
  "signature_zh": "cv::error: (-228：未知错误码 228) 在函数 'findHomography' 中，单应性掩码尺寸无效",
  "regex": "cv::error:\\s*\\(-228:.*?\\)\\s+The homography mask has invalid size in function 'findHomography'",
  "domain": "opencv",
  "category": "assertion_error",
  "subcategory": null,
  "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.",
  "root_cause_type": "generic",
  "root_cause_zh": "传递给 findHomography 的掩码参数的行数与输入点对数量不一致，导致尺寸不匹配断言失败。",
  "versions": [
    {
      "version": "4.5.5",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "4.6.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "4.7.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "4.8.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "4.9.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Assuming the mask must be a list of booleans instead of a numpy array of type uint8 or int32",
      "fail_rate": 0.35,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Resizing the mask to match the number of points without checking that the mask was generated from the correct matching step",
      "fail_rate": 0.25,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Using np.ones((n,1)) instead of np.ones((n,1), dtype=np.uint8) — OpenCV expects specific dtype",
      "fail_rate": 0.2,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "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)",
      "success_rate": 0.9,
      "how": "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)",
      "condition": "",
      "sources": []
    },
    {
      "action": "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)",
      "success_rate": 0.95,
      "how": "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)",
      "condition": "",
      "sources": []
    },
    {
      "action": "When manually constructing a mask from matching results, flatten the mask to 1D: mask = matches_mask.flatten().astype(np.uint8)",
      "success_rate": 0.85,
      "how": "When manually constructing a mask from matching results, flatten the mask to 1D: mask = matches_mask.flatten().astype(np.uint8)",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "确保掩码是一个 np.uint8 类型的 1D 或 2D numpy 数组，长度等于点对数量。示例：mask = np.ones(len(src_points), dtype=np.uint8)",
    "如果使用 RANSAC，让 OpenCV 自动生成掩码，将 mask 参数设为 None：H, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC, 5.0)",
    "手动从匹配结果构建掩码时，先展平为 1D：mask = matches_mask.flatten().astype(np.uint8)"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.opencv.org/4.x/d9/d0c/group__calib3d.html#ga4abc2ece9fab9398f2e560d53c8c9780",
  "official_doc_section": null,
  "error_code": "-228",
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.88,
  "resolvable": "true",
  "first_seen": "2023-08-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}