-215 opencv assertion_error ai_generated true

cv::error: (-215:Assertion failed) !boundingBox.empty() in function 'init'

ID: opencv/tracker-init-no-bbox

Also available as: JSON · Markdown · 中文
90%Fix Rate
84%Confidence
1Evidence
2024-02-12First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
4.5.0 active
4.7.0 active
4.10.0 active

Root Cause

The bounding box passed to cv::Tracker::init is empty (width or height is zero), often due to invalid detection or user input.

generic

中文

传递给 cv::Tracker::init 的边界框为空(宽度或高度为零),通常是由于无效的检测或用户输入。

Official Documentation

https://docs.opencv.org/4.x/d0/d0a/classcv_1_1Tracker.html#a5b5c5d5e5f5a5b5c5d5e5f5a5b5c5d5

Workarounds

  1. 100% success Validate bounding box before init: if (bbox.width > 0 && bbox.height > 0) { tracker->init(frame, bbox); } else { /* handle error */ }
    Validate bounding box before init: if (bbox.width > 0 && bbox.height > 0) { tracker->init(frame, bbox); } else { /* handle error */ }
  2. 90% success Ensure bbox is computed correctly from detection; for example, if using cv::selectROI, check that the user actually selected a region.
    Ensure bbox is computed correctly from detection; for example, if using cv::selectROI, check that the user actually selected a region.

中文步骤

  1. 在 init 之前验证边界框:if (bbox.width > 0 && bbox.height > 0) { tracker->init(frame, bbox); } else { /* 处理错误 */ }
  2. 确保从检测中正确计算边界框;例如,如果使用 cv::selectROI,检查用户是否实际选择了区域。

Dead Ends

Common approaches that don't work:

  1. 60% fail

    The empty() check only verifies width and height are zero; negative coordinates are allowed but may cause later issues; however, the assertion still passes if width/height > 0.

  2. 100% fail

    empty() returns true if width <= 0 or height <= 0; both must be positive for the assertion to pass.