FPS slowdown with newer OF release

Hi,

I haven’t used OF for quite a while, so most of my apps were made using the 0.4 - 0.6 prerelease versions. I had the need for some of the code from one of my old test apps (I had added some extra tracking stuff to some Optical flow code that was posted on the forums a while ago) and decided to move it to the latest release of OF.

The code originally ran at 80+ FPS without using ofSetFramerate, but with the latest version of OF, the framerate starts at 80 and drops to 40-50fps after about 10 seconds. I’ve used XCode’s performance tools to check if anything noticable was happening at that point, but I can’t see anything unusual. Just wondering if anyone has any ideas as to why this may be happening. I have tried it both with an iSight and a PS3 Eye using macam. I am using OS X 10.6

You can grab the code here http://andybest.net/content/cvApp.zip

Cheers,

Andy

Hmm it runs at 78 fps for me until I move and then stop. It then drops to 30fps.

commenting out

  
            //fade the motion history image  
            motion *= fadeAmnt;  

stops this issue - which suggests part of the performance issue is a float rounding issue ( when float values get super small and close to zero the calculation time of operations is a lot longer ) .

I replaced that line with this:

  
            //fade the motion history image  
            motion /= 2;  

and it runs now 70-80fps.

I wonder if that works for you?

Awesome, that solves it, thanks :wink: . Thanks Theo!

Derp. Seems that I was looking at the wrong source for the older version of ofxOpenCV. The older version that ran faster had a threshold value that would make it equal to 0 if the float was too small. I modified the code in ofxCvFloatImage to that shown below, and I no longer have the speed decrease.

  
  
void ofxCvFloatImage::operator *= ( float scalar ){  
    ofRectangle roi = getROI();  
	int thisWidth = roi.width;  
	int thisHeight = roi.height;  
	int thisX = roi.x;  
	int thisY = roi.y;  
	  
    for( int i=0; i<thisHeight; i++ ) {  
        float* ptr = (float*)(cvImage->imageData + (i+thisY)*cvImage->widthStep);  
        for( int j=0; j<thisWidth; j++ ) {  
			float* thisPtr = &ptr[(j+thisX)];  
			float thisFloat = *thisPtr;  
			(*thisPtr) = (thisFloat  < 0.00001 )? 0: (*thisPtr) * scalar;  
        }  
    }  
}  
  

You could probably just leave the accesses to the width, height, x and y of the roi in the loop. I took them out when I was testing since they were being cast to ints.

Ahh good catch - this shouldn’t have been removed as far as I can tell.
Hmm I will put this back on the bug list.

I can send you a patch for the latest svn version if you want :slight_smile: