{
  "id": "opencv/undistort-empty-map",
  "signature": "cv::error: (-215:Assertion failed) map1.size().area() > 0 in function 'cv::undistort'",
  "signature_zh": "cv::error: (-215：断言失败) map1.size().area() > 0 在函数 'cv::undistort' 中",
  "regex": "cv::error:\\s*\\(-215:Assertion failed\\) map1\\.size\\(\\)\\.area\\(\\) > 0 in function 'cv::undistort'",
  "domain": "opencv",
  "category": "assertion_error",
  "subcategory": null,
  "root_cause": "undistort received an empty or uninitialized map (map1) because initUndistortRectifyMap was not called or produced an empty output due to invalid camera matrix parameters.",
  "root_cause_type": "generic",
  "root_cause_zh": "undistort 接收到空或未初始化的 map（map1），因为 initUndistortRectifyMap 未被调用，或由于相机矩阵参数无效而产生了空输出。",
  "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": "Re-running calibrateCamera with different flags without verifying that the camera matrix is finite and non-zero",
      "fail_rate": 0.35,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Assuming the error is from the image size and resizing the image without recalculating the map",
      "fail_rate": 0.25,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Using a pre-computed map from a different camera or resolution without checking its dimensions",
      "fail_rate": 0.3,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Always call initUndistortRectifyMap before undistort. Example: newcameramtx, roi = cv2.getOptimalNewCameraMatrix(mtx, dist, (w,h), 1, (w,h)); mapx, mapy = cv2.initUndistortRectifyMap(mtx, dist, None, newcameramtx, (w,h), 5); dst = cv2.remap(img, mapx, mapy, cv2.INTER_LINEAR). Check mapx.size > 0.",
      "success_rate": 0.95,
      "how": "Always call initUndistortRectifyMap before undistort. Example: newcameramtx, roi = cv2.getOptimalNewCameraMatrix(mtx, dist, (w,h), 1, (w,h)); mapx, mapy = cv2.initUndistortRectifyMap(mtx, dist, None, newcameramtx, (w,h), 5); dst = cv2.remap(img, mapx, mapy, cv2.INTER_LINEAR). Check mapx.size > 0.",
      "condition": "",
      "sources": []
    },
    {
      "action": "If using cv2.undistort directly, ensure the camera matrix and distortion coefficients are not None and have correct shape: mtx must be 3x3 float64, dist must be 1xN or Nx1.",
      "success_rate": 0.9,
      "how": "If using cv2.undistort directly, ensure the camera matrix and distortion coefficients are not None and have correct shape: mtx must be 3x3 float64, dist must be 1xN or Nx1.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Verify camera matrix validity: if np.any(np.isnan(mtx)) or np.any(np.isinf(mtx)): raise ValueError('Invalid camera matrix'). Recalibrate if needed.",
      "success_rate": 0.85,
      "how": "Verify camera matrix validity: if np.any(np.isnan(mtx)) or np.any(np.isinf(mtx)): raise ValueError('Invalid camera matrix'). Recalibrate if needed.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "在 undistort 之前始终调用 initUndistortRectifyMap。示例：newcameramtx, roi = cv2.getOptimalNewCameraMatrix(mtx, dist, (w,h), 1, (w,h)); mapx, mapy = cv2.initUndistortRectifyMap(mtx, dist, None, newcameramtx, (w,h), 5); dst = cv2.remap(img, mapx, mapy, cv2.INTER_LINEAR)。检查 mapx.size > 0。",
    "如果直接使用 cv2.undistort，确保相机矩阵和畸变系数不为 None 且形状正确：mtx 必须是 3x3 float64，dist 必须是 1xN 或 Nx1。",
    "验证相机矩阵有效性：if np.any(np.isnan(mtx)) or np.any(np.isinf(mtx)): raise ValueError('Invalid camera matrix')。必要时重新标定。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.opencv.org/4.x/da/d54/group__imgproc__transform.html#ga55c716492470bfe86b0ee9bf3a1f0f7e",
  "official_doc_section": null,
  "error_code": "-215",
  "verification_tier": "ai_generated",
  "confidence": 0.84,
  "fix_success_rate": 0.89,
  "resolvable": "true",
  "first_seen": "2023-06-30",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}