zoukankan      html  css  js  c++  java
  • Opencv4获取FPS并显示在左上角

    //opencv4获取FPS
    /*
    两种计算时间方法:
    GetTickcount函数:它返回从操作系统启动到当前所经的计时周期数。
    getTickFrequency函数:返回每秒的计时周期数。
    */
    #include<opencv2/opencv.hpp>
    #include<iostream>
    #include<vector>
    #include "opencv2/video/tracking.hpp"
    #include "opencv2/imgproc/imgproc.hpp"
    #include "opencv2/highgui/highgui.hpp"
    #include <opencv2/core/core.hpp>
    #include <iostream>
    #include <ctype.h>
    #include <stdlib.h>
    
    using namespace std;
    using namespace cv;
    
    
    int 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;
    
            }
    
        }
        return 0;
    }
    

      

  • 相关阅读:
    EL表达式
    使用Cookie保存用户信息
    GUI学习之二——PyQt控件初识
    GUI学习之一——PyQt5初识
    HTML学习总结
    centos7 mysql的安装与配置
    Python之RabbitMQ的使用
    python之模块的导入
    Python之ftp服务器
    GUI学习之〇——PyQt5安装
  • 原文地址:https://www.cnblogs.com/Loving-Q/p/13669762.html
Copyright © 2011-2022 走看看