OpenCV: unable to get frame rate from video

I want to get the frame rate for the video, but I always get -nan on linux.

VideoCapture video(input);
if (!video.isOpened())  // zakoncz program w przypadku, problemu z otwarciem
{
    exit(0);
}

double fps = video.get(CV_CAP_PROP_FPS);

My version of openCv is 2.4.7. The same code works fine on windows.

+4
source share
3 answers

I guess it depends on the camera. Some (API) functions are sometimes not implemented in OpenCV and / or are supported by your camera. It would be best if you check the code on github.

Regarding your problem: I can get the frame rate with a regular webcam and a XIMEA camera with your code.

Tested:

  • Ubuntu 15.04 64bit
  • OpenCV 3.0.0, compiled with Qt and XIMEA camera support

You can measure the frame rate yourself:

double t1 = (double)cv::getTickCount();
// do something
t1 = ((double)cv::getTickCount() - t1)/cv::getTickFrequency();

Gives you time spent on //do something.

+1

, .

VideoCapture video("name_of_video.format");
int frameCount = (int)video.get(CV_CAP_PROP_FRAME_COUNT) ;
//some times frame count is wrong, so you can verify
video.set(CV_CAP_PROP_POS_FRAMES , frameCount-1);

//try to read the last frame, if not decrement frame count
    while(!(video.read(nextFrame))){

    frameCount--;

    video.set(CV_CAP_PROP_POS_FRAMES , frameCount-1);
}

//it is already set above, but just for clarity
      video.set(CV_CAP_PROP_POS_FRAMES , frameCount-1);
      double fps = (double)(1000*frameCount)/( video.get(CV_CAP_PROP_POS_MSEC));
      cout << "fps: " << fps << endl;

CV_CAP_PROP_FPS

+1

, (-) .

, OpenCV , . 0 NaN.

, fps , , . , @holzkohlengrill's, , , 300 (YMMV), .

0

All Articles