{
  "id": "opencv/tracker-nano-init-failed",
  "signature": "cv::error: (-215:Assertion failed) !_tracker.empty() && _tracker->isInitialized() in function 'cv::TrackerNano::update'",
  "signature_zh": "cv::error: (-215:断言失败) !_tracker.empty() && _tracker->isInitialized() 在函数 'cv::TrackerNano::update' 中",
  "regex": "TrackerNano.*isInitialized",
  "domain": "opencv",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "The TrackerNano object was not properly initialized with a bounding box before calling the update method, or the tracker was destroyed after initialization.",
  "root_cause_type": "generic",
  "root_cause_zh": "在调用 update 方法之前，TrackerNano 对象未使用边界框正确初始化，或者跟踪器在初始化后被销毁。",
  "versions": [
    {
      "version": "opencv-4.8.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "opencv-4.9.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "opencv-4.10.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Reinstall OpenCV with contrib modules enabled",
      "why_fails": "TrackerNano is part of opencv_contrib, but if it's already available (error shows the class exists), recompiling won't fix initialization logic.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Call tracker->init(frame, cv::Rect()) with an empty rectangle",
      "why_fails": "An empty rectangle (0 width or height) will cause the init to fail silently, and isInitialized() will return false.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "Use a different tracker type like TrackerCSRT",
      "why_fails": "This avoids the error but doesn't fix the underlying issue with TrackerNano initialization. The same mistake may occur with other trackers.",
      "fail_rate": 0.5,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Initialize the tracker with a valid bounding box before update: cv::Ptr<cv::TrackerNano> tracker = cv::TrackerNano::create(); cv::Rect2d bbox = cv::selectROI(frame); tracker->init(frame, bbox); Then in the loop: tracker->update(frame, bbox);",
      "success_rate": 0.9,
      "how": "Initialize the tracker with a valid bounding box before update: cv::Ptr<cv::TrackerNano> tracker = cv::TrackerNano::create(); cv::Rect2d bbox = cv::selectROI(frame); tracker->init(frame, bbox); Then in the loop: tracker->update(frame, bbox);",
      "condition": "",
      "sources": []
    },
    {
      "action": "Check if the tracker is initialized before update: if (tracker->isInitialized()) { tracker->update(frame, bbox); } else { tracker->init(frame, bbox); }",
      "success_rate": 0.85,
      "how": "Check if the tracker is initialized before update: if (tracker->isInitialized()) { tracker->update(frame, bbox); } else { tracker->init(frame, bbox); }",
      "condition": "",
      "sources": []
    },
    {
      "action": "Ensure the frame passed to init is the same size and type as subsequent frames. Convert all frames to CV_8UC3: frame.convertTo(frame, CV_8UC3);",
      "success_rate": 0.75,
      "how": "Ensure the frame passed to init is the same size and type as subsequent frames. Convert all frames to CV_8UC3: frame.convertTo(frame, CV_8UC3);",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Initialize the tracker with a valid bounding box before update: cv::Ptr<cv::TrackerNano> tracker = cv::TrackerNano::create(); cv::Rect2d bbox = cv::selectROI(frame); tracker->init(frame, bbox); Then in the loop: tracker->update(frame, bbox);",
    "Check if the tracker is initialized before update: if (tracker->isInitialized()) { tracker->update(frame, bbox); } else { tracker->init(frame, bbox); }",
    "Ensure the frame passed to init is the same size and type as subsequent frames. Convert all frames to CV_8UC3: frame.convertTo(frame, CV_8UC3);"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.opencv.org/4.x/d0/d0a/classcv_1_1TrackerNano.html",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.81,
  "fix_success_rate": 0.85,
  "resolvable": "true",
  "first_seen": "2024-06-01",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}