Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

What is the most efficient way to read the frame rate from a camera ?

I need to process real time images using my laptop camera and a Logitech C270 USB, and I need to determine the frame rate. For video files the solution is very trivial, just use

VideoCapture capture;
capture.get(CV_CAP_PROP_FPS)

for cameras, seems to be not as easy. The program I am writing will run on a Linux platform and the solution I wrote and testing is this one (resumed):

bool initTimeout;
bool fpsTimeout;

void AlarmHandler(int sig)
{
    if (initTimeout)
        initTimeout = false;
    else
        fpsTimeout = false;
}

int main(int argc, char *argv[])
{    
    // frame rate variable
    uint32_t fps = 0;

    VideoCapture capture;
    capture.open(argv[1]);

    if (inputFilename.find("/dev/video") != std::string::npos) 
    {
        fps = 0;
        initTimeout = true;
        fpsTimeout = true;

        cout << "Data input from a camera. Initialisation timeout" << endl;
        alarm(5);
        while (initTimeout)
            capture >> currentFrame;

        cout << "Calculating framerate ... " << endl;
        alarm(1);
        while (fpsTimeout)
        {
            capture >> currentFrame;
            if(! currentFrame.empty())
                fps++;
        }
    }
}

I implemented the initialisation timeout becuase I noticed that the camera need a frames fflush before the timeout used for frame rate.

Comparing the results with VLC player, it gives 30 frames per second for the laptop camera and 25 for the USB camera. The program sometimes agrees with VLC, sometimes it doesn't, returning different results (16 for the USB camera, 31 for the laptop camera etc.).

Do you know a more efficient way to read the frame rate from a video camera ?

What is the most efficient way to read the frame rate from a camera ?

I need to process real time images using my laptop camera and a Logitech C270 USB, and I need to determine the frame rate. For video files the solution is very trivial, just use

VideoCapture capture;
capture.get(CV_CAP_PROP_FPS)

for cameras, seems to be not as easy. The program I am writing will run on a Linux platform and the solution I wrote and testing is this one (resumed):

bool initTimeout;
bool fpsTimeout;

void AlarmHandler(int sig)
{
    if (initTimeout)
        initTimeout = false;
    else
        fpsTimeout = false;
}

int main(int argc, char *argv[])
{    
    // frame rate variable
    uint32_t fps = 0;

    VideoCapture capture;
    capture.open(argv[1]);

    if (inputFilename.find("/dev/video") != std::string::npos) 
    {
        fps = 0;
        initTimeout = true;
        fpsTimeout = true;

        cout << "Data input from a camera. Initialisation timeout" << endl;
        alarm(5);
        while (initTimeout)
            capture >> currentFrame;

        cout << "Calculating framerate ... " << endl;
        alarm(1);
        while (fpsTimeout)
        {
            capture >> currentFrame;
            if(! currentFrame.empty())
                fps++;
        }
    }
}

I implemented the initialisation timeout becuase I noticed that the camera need a frames fflush before the timeout used for frame rate.

Comparing the results with VLC player, it gives 30 frames per second for the laptop camera and 25 for the USB camera. The camera.

My program sometimes agrees with VLC, sometimes it doesn't, returning different results (16 for the USB camera, 31 for the laptop camera etc.).

Do you know a more efficient way to read the frame rate from a video camera ?