-215 opencv assertion_error ai_generated true

cv::error: (-215:断言失败) !boundingBox.empty() 在函数 'init' 中

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

ID: opencv/tracker-init-no-bbox

其他格式: JSON · Markdown 中文 · English
90%修复率
84%置信度
1证据数
2024-02-12首次发现

版本兼容性

版本状态引入弃用备注
4.5.0 active
4.7.0 active
4.10.0 active

根因分析

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

English

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

generic

官方文档

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

解决方案

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

无效尝试

常见但无效的做法:

  1. 60% 失败

    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% 失败

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