#include “opencv2/imgproc/imgproc.hpp”
int main(int argc, const char** argv)
{
cv::Mat frame;
// 可从摄像头输入视频流或直接播放视频文件
cv::VideoCapture capture(0);
//cv::VideoCapture capture(“vedio1.avi”);
double fps;
char string[10]; // 帧率字符串
cv::namedWindow(“Camera FPS”);
double t = 0;
while (1)
{
t = (double)cv::getTickCount();
if (cv::waitKey(1) == 1) { break; }
if (capture.isOpened())
{
capture >> frame;
// getTickcount函数:返回从操作系统启动到当前所经过的毫秒数
// getTickFrequency函数:返回每秒的计时周期数
// t为该处代码执行所耗的时间,单位为秒,fps为其倒数
t = ((double)cv::getTickCount() - t) / cv::getTickFrequency();
fps = 1.0 / t;
sprintf_s(string, “%.2f”, fps); // 帧率保留两位小数
std::string fpsString(“FPS:”);
fpsString += string; // 在"FPS:"后加入帧率数值字符串
printf(“fps: %