/************************************************************************
* Copyright(c) 2011 Yang Xian
* All rights reserved.
*
* File: main.cpp
* Brief: 读取摄像头,并且显示当前fps
* Version: 1.0
* Author: Yang Xian
* Email: xyang2011@sinano.ac.cn
* Date: 2011/12/22
* History:
************************************************************************/
#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;
}
}
}
- 1
- 2
- 3
- 4
- 5
- 6
前往页