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

- **ID:** `opencv/tracker-nano-init-failed`
- **Domain:** opencv
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## 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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| opencv-4.8.0 | active | — | — |
| opencv-4.9.0 | active | — | — |
| opencv-4.10.0 | active | — | — |

## Workarounds

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);** (90% success)
   ```
   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); }** (85% success)
   ```
   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);** (75% success)
   ```
   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);
   ```

## Dead Ends

- **Reinstall OpenCV with contrib modules enabled** — TrackerNano is part of opencv_contrib, but if it's already available (error shows the class exists), recompiling won't fix initialization logic. (90% fail)
- **Call tracker->init(frame, cv::Rect()) with an empty rectangle** — An empty rectangle (0 width or height) will cause the init to fail silently, and isInitialized() will return false. (85% fail)
- **Use a different tracker type like TrackerCSRT** — This avoids the error but doesn't fix the underlying issue with TrackerNano initialization. The same mistake may occur with other trackers. (50% fail)
