0

Actually,I am trying detect and track the vehicles from a video using C++ opencv 2.4.10.I did so.Now,I want to find the frame rate of the output video.I want to know if there is any way to find out.Can anyone suggest me any blog or tutorial about this?

Thank you.

Avijit
  • 687
  • 2
  • 8
  • 18
  • As far as I know there is not a god calculator out of the box but It's pretty easy to implement one, just estimate the time between frames. You can do this in a frame per frame basis or each n frames. Then output the number on the screen / console. Do you need help in doing the estimation ? – Dredok Nov 06 '16 at 08:12
  • Do you mean a) you want to measure the rate at which your code acquires a video stream from a camera, or b) you want to measure the rate at which your code writes frames from a video camera to a disk file, or c) you have a video file (say `mp4`) already recorded and you want to know its frame rate? – Mark Setchell Nov 06 '16 at 11:29
  • @markSetchell I have tracked vehicles in a video.I want the frame rate of that output video. – Avijit Nov 06 '16 at 11:33
  • If you have `ffmpeg` installed, you can use `ffprobe video.mp4`, or `exiftool video.mp4`. – Mark Setchell Nov 06 '16 at 11:40

2 Answers2

3

Something like this may help.

#include <iostream>
#include <opencv2/opencv.hpp> //for opencv3
#include <opencv/cv.hpp> //for opencv2

int main(int argc, const char * argv[]) {
    cv::VideoCapture video("video.mp4");
    double fps = video.get(cv::CAP_PROP_FPS);
    std::cout << "Frames per second : " << fps << std::endl;
    video.release();
    return 0;
}
Murad
  • 155
  • 2
  • 6
  • Thank you for comment.I have tried this but not working.some .dll files can not find or open the PDB file.Do you know any solution for that? – Avijit Nov 06 '16 at 10:34
  • @user4692891, I am not familiar with windows, so i can't help you. – Murad Nov 06 '16 at 11:14
  • @Murad This is the correct answer to your question. You have either not installed OpenCV correctly or you have not told your `IDE` (Visual Studio?) where to find the OpenCV include files (headers), libraries (linker settings) or DLLs. – Mark Setchell Nov 06 '16 at 11:38
0

You must have a loop in your code where you are doing all the video processing.

Let's say you have something similar to this pseudocode:

//code initialization
cv::VideoCapture cap("some-video-uri");

//video capture/processing loop
while (1)
{
        //here we take the timestamp
        auto start = std::chrono::system_clock::now();
        //capture the frame
        cap >> frame;
        //do whatever frame processing you are doing...
        do_frame_processing();
        //measure timestamp again
        auto end = std::chrono::system_clock::now();
        //end - start is the time taken to process 1 frame, output it:
        std::chrono::duration<double> diff = end-start;
        std::cout << "Time to process last frame (seconds): " << diff.count() 
                  << " FPS: " << 1.0 / diff.count() << "\n";
}

thats it ... take into account that calculating FPS in a frame-per-frame basis will likely produce a highly variant result. You should average this result for several frames in order to get a less variant FPS.

ns19
  • 3
  • 3
Dredok
  • 807
  • 1
  • 9
  • 30