Pascal
Pascal

Reputation: 2299

OpenCV: What is the limitation for the poor framerate?

Using OpenCV 2.4.3.2 on Ubuntu 12.10 with a PS3-Eye camera I'm not able to capture more than ~60 frames per second (FPS). The camera itself delivers up to 125 FPS. I would like to know what limits the framerate in OpenCV. So here is what I did so far:

#include <sys/time.h>
#include <time.h>
#include <iostream> // for standard I/O

using cv;
using std;

long time_diff( const timespec &t1, const timespec &t2 ) {
  return (long)(t2.tv_sec-t1.tv_sec)*1000000000 + (t2.tv_nsec-t1.tv_nsec);
}

int main(int argc, char *argv[]) {
  VideoCapture cap(0); // open the default camera
  cap.set(CV_CAP_PROP_EXPOSURE, 0);
  cap.set(CV_CAP_PROP_FPS, 125);
  cap.set(CV_CAP_PROP_FRAME_WIDTH, 320);
  cap.set(CV_CAP_PROP_FRAME_HEIGHT, 240);
  if(!cap.isOpened())  // check if we succeeded
    return -1;
  Mat frame;
  timespec t_start, t_end;
  for(int i=1;;++i) {
    cap >> frame;
    clock_gettime(CLOCK_REALTIME, &t_end);
    if( i%20==0 )
      std::cout << "FPS ~= " << time_diff(t_start, t_end) << std::endl;
    clock_gettime(CLOCK_REALTIME, &t_start);
  }
}

This outputs the framerate every 20 frames to stdout. Note that I had to patch the source to be able to set the framerate correctly for the PS3-Eye camera.

First I set the framerate to 30 (cap.set(CV_CAP_PROP_FPS, 30);) to verify that my measurement is correct. Then using higher framerates the reported framerate is capped at ~60 FPS.

The USB is not the problem because I can get the full 120 FPS with guvcview.

I modified the code above to use grab() and retrieve() like this:

clock_gettime(ClOCK_REALTIME, &t_start);
cap->grab();
clock_gettime(ClOCK_REALTIME, &t_end);
cap->retrieve(frame);

but the framerate is capped again at ~60 FPS.

So how can I tell what is limiting the framerate?

Upvotes: 0

Views: 1666

Answers (2)

phat
phat

Reputation: 1

I have same issue with 65 FPS limit in win7 x64 with OpenCV and Delphi X6. Founded problem is in cvWaitKey or/and Windows message queue, which limits redraws in 65 Hz. The solution - to call cvWaitKey less frequently, less 65 times per second.

Upvotes: 0

Pascal
Pascal

Reputation: 2299

After switching to a desktop machine (from laptop) I was able to capture the full framerate. It seems OpenCVs capture implementation is not as efficient as the one in guvcview.

Upvotes: 1

Related Questions