Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to find frame per second of a dynamic movement?

Here is my code..i am able to extract frames, but how to extract the frames per second for a dynamic movement??

#include "opencv2/opencv.hpp"
#include <time.h>
 #include <stdio.h>
 #include<string>
  #include<ctime>

  using namespace cv;
using namespace std;


  const char* videofilename = "(online-video-cutter.com).mp4";
  VideoCapture cap(videofilename); // open a video file
 int main(int argc, char** argv)
{

if (!cap.isOpened())  // check if succeeded
{
    cout << "file " << videofilename << " not found or could not be opened" << endl;
    return -1;
}

namedWindow("output");

unsigned long counter = 0;

Mat frame;
// read frames until end of video:
while (cap.read(frame))
{

    // display frame
    imshow("output", frame);
    waitKey(25);   // remove this line if you don't need the live output


                   // adjust the filename by incrementing a counter
    std::stringstream filename(std::stringstream::in | std::stringstream::out);
    filename << "image" << counter++ << ".jpg";

    std::cout << "writing " << filename.str().c_str() << " to disk" << std::endl;

    // save frame to file: image0.jpg, image1.jpg, and so on...
    imwrite(filename.str().c_str(), frame);

}
return 0;
   }