A recent thing to do is to display the frame rate, or FPS, in real time on the video. FPS is the abbreviation for frame per second, in Chinese meaning the number of frames per second. The development platform is vs2013+opencv2.4.9.
FPS is the measurement of the amount of information used to save and display dynamic video. In layman's terms, it refers to the number of images changing per second.
The main functions that need to be used when calculating fps are GetTickCount, gettickfrequency. The display of the FPS watermark on the output image is using the function Puttext, whose simple declaration is as follows:
GetTickCount(void); 在Debug版本中,设备启动后便从计时器中减去180秒。这样方便测试使用该函数的代码的正确溢出处理。在Release版本中,该函数从0开始计时,返回自设备启动后的毫秒数(不含系统暂停时间)。
getTickFrequency函数:返回每秒的计时周期数,GetTickCount / getTickFrequency就得到一个周期的时间。
voidPuttext (mat& img,//Image Matrix Const string& Text,//string-type contentPoint org,//string coordinates, with the lower left corner as the Origin intFontface,//font type DoubleFontscale,//font sizeScalar Color,//Font Color intThickness =1,//font weight intLinetype =8,//Line type BOOLBottomleftorigin =false)//I don't know what the function is yet .
If you want to run a program, you can apply the following example:
= (double)cv::getTickCount();if (capture.isOpened()){ >> frame; // getTickcount函数:返回从操作系统启动到当前所经过的毫秒数 // getTickFrequency函数:返回每秒的计时周期数 // t为该处代码执行所耗的时间,单位为秒,fps为其倒数 = ((double)cv::getTickCount-/ cv::getTickFrequency(); =1.0/ t;
To implement a simple code that shows the video frame rate:
#include <stdlib.h>#include <iostream>#include <opencv2/core/core.hpp>#include <opencv2/highgui/highgui.hpp>voidMain () {Cv::mat frame;//can input video stream from camera or play video file directly //cv::videocapture Capture (0);Cv::videocapture Capture ("E:/video0002.mp4");DoublefpsChar string[Ten];//String to hold the frame rateCv::namedwindow ("Camera FPS");Doublet =0; while(1) {T = (Double) Cv::gettickcount ();if(Cv::waitkey ( -) == -){ Break; }if(Capture.isopened ()) {Capture >> frame;//GetTickCount function: Returns the number of milliseconds that have elapsed from the operating system startup to the current //Gettickfrequency function: Returns the number of ticks per second //T for the time it takes to execute the code, in seconds, FPS as its countdownT = ((Double) Cv::gettickcount ()-T)/cv::gettickfrequency (); fps =1.0/t;sprintf(string,"%.2f", FPS);//Frame rate reserved two decimal places STD::stringFpsstring ("FPS:"); Fpsstring + =string;//Add a frame rate value string after "FPS:" //write the frame rate information on the output framePuttext (Frame,//Image MatrixFpsstring,//String type text contentCV::P oint (5, -),//text coordinates, in the lower left corner as the origin pointCv::font_hershey_simplex,//font type 0.5,//font sizeCv::scalar (0,0,0));//Font ColorCv::imshow ("Camera FPS", frame); }Else{STD::cout<<"No Camera input!"<<STD:: Endl; Break; } }}
The above procedure can roughly test the time consumption of the video processing algorithm. The main process is to use the above two main functions to get the time between each frame, and then use Puttext to display the value of FPS to the screen.
Reference: http://www.cnblogs.com/jxsoft/archive/2011/10/17/2215366.html
http://blog.csdn.net/boksic/article/details/7017837
OpenCV2 Study Notes (18): Display the frame rate of the video stream