{
  "id": "opencv/contour-not-found-in-hierarchy",
  "signature": "cv::error: (-215:Assertion failed) hierarchy.checkVector(3, 4) >= 0 in function 'drawContours'",
  "signature_zh": "cv::error: (-215:断言失败) hierarchy.checkVector(3, 4) >= 0 在函数 'drawContours' 中",
  "regex": "hierarchy\\.checkVector\\(3, 4\\) >= 0.*drawContours",
  "domain": "opencv",
  "category": "assertion_error",
  "subcategory": null,
  "root_cause": "Contour hierarchy vector is empty or malformed when calling drawContours with RETR_TREE or RETR_CCOMP mode after findContours.",
  "root_cause_type": "generic",
  "root_cause_zh": "在调用 findContours 后使用 RETR_TREE 或 RETR_CCOMP 模式调用 drawContours 时，轮廓层次向量为空或格式错误。",
  "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"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Setting RETR_EXTERNAL only retrieves outer contours, but hierarchy is still required for drawing with RETR_TREE. The error persists because hierarchy is empty.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Changing CHAIN_APPROX_NONE to other approximations doesn't fix hierarchy emptiness; it only changes point storage.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Increasing threshold values may reduce contour count but doesn't guarantee hierarchy is non-empty.",
      "fail_rate": 0.4,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Check if hierarchy is not None and has at least 4 elements before calling drawContours. Example: `if hierarchy is not None and len(hierarchy) > 0: cv2.drawContours(img, contours, -1, (0,255,0), 2)`",
      "success_rate": 0.85,
      "how": "Check if hierarchy is not None and has at least 4 elements before calling drawContours. Example: `if hierarchy is not None and len(hierarchy) > 0: cv2.drawContours(img, contours, -1, (0,255,0), 2)`",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use RETR_LIST mode which returns no hierarchy, then draw without hierarchy parameter.",
      "success_rate": 0.75,
      "how": "Use RETR_LIST mode which returns no hierarchy, then draw without hierarchy parameter.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Ensure contours list is non-empty before drawing: `if len(contours) > 0: cv2.drawContours(img, contours, -1, (0,255,0), 2, hierarchy=hierarchy)`",
      "success_rate": 0.9,
      "how": "Ensure contours list is non-empty before drawing: `if len(contours) > 0: cv2.drawContours(img, contours, -1, (0,255,0), 2, hierarchy=hierarchy)`",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Check if hierarchy is not None and has at least 4 elements before calling drawContours. Example: `if hierarchy is not None and len(hierarchy) > 0: cv2.drawContours(img, contours, -1, (0,255,0), 2)`",
    "Use RETR_LIST mode which returns no hierarchy, then draw without hierarchy parameter.",
    "Ensure contours list is non-empty before drawing: `if len(contours) > 0: cv2.drawContours(img, contours, -1, (0,255,0), 2, hierarchy=hierarchy)`"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.opencv.org/4.x/d3/dc0/group__imgproc__shape.html#ga17ed9f5d79ae97bd4c7cf18403e1689a",
  "official_doc_section": null,
  "error_code": "-215",
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2023-04-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}