opencv runtime_error ai_generated true

cv::error: (-215:断言失败) !_tracker.empty() && _tracker->isInitialized() 在函数 'cv::TrackerNano::update' 中

cv::error: (-215:Assertion failed) !_tracker.empty() && _tracker->isInitialized() in function 'cv::TrackerNano::update'

ID: opencv/tracker-nano-init-failed

其他格式: JSON · Markdown 中文 · English
85%修复率
81%置信度
1证据数
2024-06-01首次发现

版本兼容性

版本状态引入弃用备注
opencv-4.8.0 active
opencv-4.9.0 active
opencv-4.10.0 active

根因分析

在调用 update 方法之前,TrackerNano 对象未使用边界框正确初始化,或者跟踪器在初始化后被销毁。

English

The TrackerNano object was not properly initialized with a bounding box before calling the update method, or the tracker was destroyed after initialization.

generic

官方文档

https://docs.opencv.org/4.x/d0/d0a/classcv_1_1TrackerNano.html

解决方案

  1. 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);
  2. Check if the tracker is initialized before update: if (tracker->isInitialized()) { tracker->update(frame, bbox); } else { tracker->init(frame, bbox); }
  3. 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);

无效尝试

常见但无效的做法:

  1. Reinstall OpenCV with contrib modules enabled 90% 失败

    TrackerNano is part of opencv_contrib, but if it's already available (error shows the class exists), recompiling won't fix initialization logic.

  2. Call tracker->init(frame, cv::Rect()) with an empty rectangle 85% 失败

    An empty rectangle (0 width or height) will cause the init to fail silently, and isInitialized() will return false.

  3. Use a different tracker type like TrackerCSRT 50% 失败

    This avoids the error but doesn't fix the underlying issue with TrackerNano initialization. The same mistake may occur with other trackers.