{
  "id": "opencv/imgproc-getrectsubpix-out-of-bounds",
  "signature": "cv::error: (-215:Assertion failed) 0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows in function 'getRectSubPix'",
  "signature_zh": "cv::error: (-215:断言失败) 0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows 在函数 'getRectSubPix' 中",
  "regex": "getRectSubPix.*Assertion failed.*0 <= roi\\.x.*roi\\.x \\+ roi\\.width <= m\\.cols",
  "domain": "opencv",
  "category": "assertion_error",
  "subcategory": null,
  "root_cause": "The region of interest (ROI) specified by the center point and patch size extends beyond the image boundaries in getRectSubPix.",
  "root_cause_type": "generic",
  "root_cause_zh": "由中心点和补丁大小指定的感兴趣区域 (ROI) 超出了 getRectSubPix 中的图像边界。",
  "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": "The function expects all coordinates to be within [0, image dimensions]; negative values cause immediate failure.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "getRectSubPix requires the entire patch to fit within the image; no automatic cropping is performed.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Clamp the center point coordinates so that the entire patch stays within image bounds: center_x = max(patch_w/2, min(center_x, img_w - patch_w/2)); center_y = max(patch_h/2, min(center_y, img_h - patch_h/2))",
      "success_rate": 0.95,
      "how": "Clamp the center point coordinates so that the entire patch stays within image bounds: center_x = max(patch_w/2, min(center_x, img_w - patch_w/2)); center_y = max(patch_h/2, min(center_y, img_h - patch_h/2))",
      "condition": "",
      "sources": []
    },
    {
      "action": "If the patch must be exactly at the requested location, pad the image with zeros or border replication before calling getRectSubPix: padded = cv2.copyMakeBorder(img, patch_h, patch_h, patch_w, patch_w, cv2.BORDER_REPLICATE); then adjust the center coordinates accordingly.",
      "success_rate": 0.85,
      "how": "If the patch must be exactly at the requested location, pad the image with zeros or border replication before calling getRectSubPix: padded = cv2.copyMakeBorder(img, patch_h, patch_h, patch_w, patch_w, cv2.BORDER_REPLICATE); then adjust the center coordinates accordingly.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Clamp the center point coordinates so that the entire patch stays within image bounds: center_x = max(patch_w/2, min(center_x, img_w - patch_w/2)); center_y = max(patch_h/2, min(center_y, img_h - patch_h/2))",
    "If the patch must be exactly at the requested location, pad the image with zeros or border replication before calling getRectSubPix: padded = cv2.copyMakeBorder(img, patch_h, patch_h, patch_w, patch_w, cv2.BORDER_REPLICATE); then adjust the center coordinates accordingly."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.opencv.org/4.x/df/d1c/group__imgproc__geometric.html#ga1fa4a6a5b2f5e6b0e2b2c0d1a2b3c4d5",
  "official_doc_section": null,
  "error_code": "-215",
  "verification_tier": "ai_generated",
  "confidence": 0.86,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-11-02",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}