#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <stdlib.h>
#include <iostream>

using namespace cv;
 
using namespace std;
 

void main()
 
{
 
        Mat frame;
 
        VideoCapture capture(0);
 
        double fps;
 
        char str[5];
 
        namedWindow("webCam");
 
        double t = 0;
 

        while (1)
 
        {
 
                t = (double)getTickCount();
 

                if (waitKey(50) == 27)
 
                {
 
                        break;
 
                }
 

                if (capture.isOpened())
 
                {
 
                        capture >> frame;
 
                        // do something ...
 
                        t = ((double)getTickCount() - t) / getTickFrequency();
 
                        fps = 1.0 / t;
 

                        sprintf(str, "%5f", fps);
 
                        string fpsStr("FPS:");
 
                        fpsStr += str;
 
                        putText(frame, fpsStr, Point(0,30), FONT_HERSHEY_SIMPLEX, 1.0, Scalar(0,0,255));
 

                        imshow("webCam", frame);
 
                }
 
                else
 
                {
 
                        cout << "capture device failed to open!" << endl;
 
                        break;
 
                }
 
        }
 
}