I am using KCF tracking in OpenCV. everything is ok and i can track an object as well, but i have a problem:
i set a ROI and algorithm work fine, sometimes i need change my ROI. there for tracker should reset and track my new ROI but it won't. in fact last ROI will remain in history and it effect on new location.
also this is my codes summary, i wrote important lines:
Rect2d roi;
Mat frame;
Ptr 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 want change roi when Condition is true.
解决方案
you need to call:
tracker->clear();
tracker = cv::Tracker::create("KCF");
tracker->init(frame, roi);