0
votes

I am writing a program to capture camera frames using opencv 2.49.

My problem is that the camera cap capture up to 500 FPS. But after the 5th frame capturing frames drop to 40 FPS and some times go beck to 500 FPS.

Could any one has an idea why is this happening? how I can fix capturing frames 500 FPS.

I have attached the output FPS

while(true)
{
    cout << "\nStart while loop:" << endl;
    auto t1 = chrono::high_resolution_clock::now(); 


    Mat curFrame;
    cap >> curFrame;
    if( curFrame.empty() ) break; // end of video stream

    auto t2 = chrono::high_resolution_clock::now();     

    auto cap_time = chrono::duration_cast<chrono::microseconds>( t2 - t1 ).count();
    cout << "cap_time :" << cap_time << " microseconds, " << 1000000/(float)cap_time << " FPS" << endl;

    imshow("Original", curFrame);

    if (waitKey(1) >= 27) 
    {
        cout << "esc key is pressed by user" << endl;
        break;
    }   
}
1
No, I am using Linux to build application running on Xilinx Zedboard. The code is combiled with -O2. - M.Mosab
Even a 640x480 RGB image is just about a megabyte. So 500 fps would just about saturate the very fastest USB3 connection and require 5x the bandwidth of a Gigabit Ethernet... relatively few cameras exceed 30 fps and even fewer 60 fps. - Mark Setchell

1 Answers

0
votes

You have to measure the difference to when you took the last image and not how long it takes to save the image in your variable.

pseudocode:

time = -1;
while (true)
{
    new_time = now();
    if (time != -1)
    {
        time_diff = new_time - time;
        if (time_diff == 0) // avoid null pointer exception
            cout << "infinite FPS";
        else
            cout << 1000000.d / double(time_diff) << "FPS";
    }
    time = new_time;
    ...
}

Another improvements would be:

  1. print the FPS every second instead of every time you took a photo.
  2. use the period property of the clock instead of 1000000.
  3. I think you want "== 27" and not ">= 27"