How to reset or update KCF tracking ROI when it loses target

I use the KCF tracking algorithm, my problem is when the target exit from the window, the tracker will not reset and does not correctly display the rectangle on the edge of the window. In perfect condition, the tracker should remove the rectangle when it loses its target.

These are my codes:

int main(int argc, char** argv) {
        Rect2d roi;
        Mat frame;

        // create a tracker object
        Ptr<Tracker> tracker = Tracker::create("KCF");

        VideoCapture cap("C2_0002.mp4");

        cap >> frame;
        resize(frame, frame, Size(frame.cols / 2, frame.rows / 2));
        roi = selectROI("tracker", frame);
        //quit if ROI was not selected
        if (roi.width == 0 || roi.height == 0)
            return 0;
        // initialize the tracker
        tracker->init(frame, roi);
        // perform the tracking process
        printf("Start the tracking process, press ESC to quit.\n");
        for (;; ) {

                // get frame from the video
            cap >> frame;
            resize(frame, frame, Size(frame.cols / 2, frame.rows / 2));
            // stop the program if no more images
            if (frame.rows == 0 || frame.cols == 0)
                break;
            // update the tracking result
            tracker->update(frame, roi);

            rectangle(frame, roi, Scalar(255, 0, 0), 2, 1);

            imshow("tracker", frame);
            if (waitKey(1) == 27)break;
        }
}

You can also see a short video of my simulation and see the problem: http://www.0up.ir/do.php?downf=4_e2aa9.mp4

+4
source share
1 answer

?
a)
b) ,

, , ( ), , :

: tracker->update(frame, roi) false 0, tracker->update(frame, roi) true. () rectangle(frame, roi, Scalar(255, 0, 0), 2, 1) / ( , , , , - : )

fyi- > : http://www.robots.ox.ac.uk/~joao/publications/henriques_eccv2012.pdf)

0

Source: https://habr.com/ru/post/1659951/


All Articles