OpenCV 3.4+ Introduce different single object tracking algorithm such as CSRT, MIL, KCF, TLD, GOTURN, MEDIANFLOW, MOSSE and BOOSTING
Below is the C++ code which will give the idea how the Tracking API can be used to track single Object. Here I have used TrackerCSRT
Below is the C++ code which will give the idea how the Tracking API can be used to track single Object. Here I have used TrackerCSRT
C++ Code
Rect2d roi;
Mat frame;
namedWindow("tracker",1);
// create a tracker object
Ptr tracker = TrackerCSRT::create();
std::string video = "track.mp4";
VideoCapture cap(video);
cap >> frame;
resize(frame,frame,Size(1080,720));
roi=selectROI("tracker",frame);
//quit if ROI was not selected
if(roi.width==0 || roi.height==0)
return;
//initialize the tracker
tracker->init(frame,roi);
printf("Press ESC to quit.\n");
for ( ;; ){
cap >> frame;
resize(frame,frame,Size(1080,720));
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;
}
No comments:
Post a Comment