Watch camera framerate

#1

How can i see the framerate of my camera in my application? Is there any variable like ofCameraFramerate or something like that so i can print it?
Thanks

#2

Thanks uglytv.
I love open source community.

#3

Just a comment as I don’t know better:

I think that the ofGetFrameRate gets you the overall Framerate (as set with ofSetFrameRate()) not just the Framerate of your camera.

Maybe you could make a simple counter that you increment after you grab a new frame and which is set to 0 every new second.

The function you could use here is ofGetElapsedTimef() or ofGetSeconds()

#4

Yes you’re right. ofGetFrameRate only returns the overall frame rate of your app.
If you want the camera FPS you need to add something like this:

  
  
void testApp::calculateCaptureFramerate()  
{  
    mytimeNow = ofGetElapsedTimef();  
    if( (mytimeNow-mytimeThen) > 0.05f || myframes == 0 ) {  
        myfps = myframes / (mytimeNow-mytimeThen);  
        mytimeThen = mytimeNow;  
        myframes = 0;  
        myframeRate = 0.9f * myframeRate + 0.1f * myfps;  
        sprintf(buf,"Capture framerate : %f",myframeRate);  
    }  
    myframes++;  
}  
  

with the following variables declared:

  
  
		char buf[255];  
		float mytimeNow, mytimeThen, myframeRate;  
		float myfps;  
		float myframes;  
  

In setup() you make sure to clear the variables:

  
  
	mytimeThen = 0.0f;  
	myframeRate = 0.0f;  
	myframes = 0.0f;  
  

In the update() function you would put this:

  
	if (vidGrabber.isFrameNew()){  
           calculateCaptureFramerate();  
	}  

Then in the main draw() function just add something like this:

  
  
    /* Camera framerate display */  
	ofDrawBitmapString(buf,10,10);  
  

#5

Hiii :smiley: , serching for the way to display the webcam framerate i found the Grimu’s code.
But dont work for me. I think the problem is the myframes variable because Codeblocks tells: error ‘myframes’ was not declared in this scope

what represents the “myframes” variable?
Can anyone help me to undestand this function?

Thanks!

#6

Hi, the code I posted was incomplete…I’ve edited to make it clearer, hope that helps.

Just to clarify, the line

  
myframeRate = 0.9f * myframeRate + 0.1f * myfps;  

combines the current frame rate with the most recent fps calculation, in order to ensure smoother changes in the actual frame rate (so that it’s less jittery).

If you are interested, there’s a forum post here about calculating frame rates…with different examples:
http://www.idevgames.com/forum/showthread.php?t=12774

#7

here’s my quick and dirty method for looking at the camera speed:

Define the float variable camSpeed in testapp.h and initialize it to 1.0 in setup().

then modify your frame grabbing code to be like this:

  
  
vidGrabber.grabFrame();  
    if(vidGrabber.isFrameNew()) {  
          
        ... do somthing with camera data  
  
        camSpeed += 1.1;  
    }  
  
    camSpeed /= 1.1;  
  

Basically what you end up with is a value from 0 to 1 which you can then multiply by ofGetFrameRate() to get the camera’s frame rate:

  
  
cameraFrameRate = camSpeed * ofGetFrameRate();  
  

Webcam in high resolution lags