clear ROI history from kcf tracking in opencv

送分小仙女□ 提交于 2020-01-05 05:46:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!