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;
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);
if (roi.width == 0 || roi.height == 0)
return 0;
tracker->init(frame, roi);
printf("Start the tracking process, press ESC to quit.\n");
for (;; ) {
cap >> frame;
resize(frame, frame, Size(frame.cols / 2, frame.rows / 2));
if (frame.rows == 0 || frame.cols == 0)
break;
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
source
share