I use KCF tracking in OpenCV. everything is fine, and I can also track the object, but I have a problem: I set the ROI and the algorithm works fine, sometimes I need to change my ROI. there for the tracker should reset and track my new ROI, but it will not. in fact, the last ROI will remain in history, and this will affect the new location.
This is also a summary of my codes, I wrote important lines:
Rect2d roi;
Mat frame;
Ptr<Tracker> tracker = Tracker::create("KCF");
VideoCapture cap("C1_0001.mp4");
cap >> frame;
roi = selectROI("tracker", frame);
if (Condition = true)
{
roi = selectROI("tracker", frame);
}
tracker->init(frame, roi);
for (;; )
{
cap >> frame;
tracker->update(frame, roi);
}
I need to change roi when Condition is true.
source
share