opencv 显示摄像头+fps

#include 
#include 
#include 
#include 

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;
 
                }
 
        }
 
}


 

 

你可能感兴趣的:(openCV)