问题
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 = 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.
回答1:
you need to call:
tracker->clear();
tracker = cv::Tracker::create("KCF");
tracker->init(frame, roi);
Problem was already solved here: OpenCV 3 Tracker won't work after reinitialization
来源:https://stackoverflow.com/questions/40408616/clear-roi-history-from-kcf-tracking-in-opencv