Ask Your Question
2

clear ROI history from kcf tracking in opencv

asked 2016-11-05 11:39:02 -0500

alireza.kenarang gravatar image

I am using KCF tracking in OpenCV. everything is okay 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.

if need i can upload a video clip for more explanation.

edit retag flag offensive close merge delete

Comments

afaik, you have to re-init the tracker with the new ROI.

LorenaGdL gravatar imageLorenaGdL ( 2016-11-06 11:06:35 -0500 )edit

i think you can use roi.clear() to erase the old values

ManuVISION gravatar imageManuVISION ( 2016-11-10 01:06:00 -0500 )edit

@ManuVISION that won't clear tracker history

LorenaGdL gravatar imageLorenaGdL ( 2016-11-10 03:09:00 -0500 )edit

yes, that won't clear, i solved it. i use Ptr<tracker> tracker = Tracker::create("KCF") every where need to reset.

alireza.kenarang gravatar imagealireza.kenarang ( 2016-11-10 23:12:02 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-09-11 19:06:27 -0500

mhaghighat gravatar image

updated 2018-07-12 17:44:14 -0500

You can release the old tracker and create a new tracker and initiate it with your new ROI. That is:

tracker.release(); 
tracker = cv::TrackerKCF::create();
tracker->init(frame, newRoi);

It may not be the right or the prettiest way to do it, but it does the job.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-11-05 11:39:02 -0500

Seen: 1,221 times

Last updated: Jul 12