#include <opencv2/opencv.hpp>
#include <opencv2/tracking.hpp>
using namespace cv;
using namespace std;
#define SSTR( x ) static_cast< std::ostringstream & >( \
( std::ostringstream() << std::dec << x ) ).str()
int main(int argc, char **argv)
{
Ptr<Tracker> tracker = TrackerGOTURN::create();
VideoCapture video("chaplin.mp4");
if(!video.isOpened())
{
cout << "Could not read video file" << endl;
return EXIT_FAILURE;
}
Mat frame;
if (!video.read(frame))
{
cout << "Cannot read video file" << endl;
return EXIT_FAILURE;
}
Rect2d bbox(287, 23, 86, 320);
tracker->init(frame, bbox);
while(video.read(frame))
{
double timer = (double)getTickCount();
bool ok = tracker->update(frame, bbox);
float fps = getTickFrequency() / ((double)getTickCount() - timer);
if (ok)
{
rectangle(frame, bbox, Scalar( 255, 0, 0 ), 2, 1 );
}
else
{
putText(frame, "Tracking failure detected", Point(100,80), FONT_HERSHEY_SIMPLEX, 0.75, Scalar(0,0,255),2);
}
putText(frame, "GOTURN Tracker", Point(100,20), FONT_HERSHEY_SIMPLEX, 0.75, Scalar(50,170,50),2);
putText(frame, "FPS : " + SSTR(int(fps)), Point(100,50), FONT_HERSHEY_SIMPLEX, 0.75, Scalar(50,170,50), 2);
imshow("Tracking", frame);
if(waitKey(1) == 27) break;
}
return EXIT_SUCCESS;
}