Best Way To Spped Things Up?


I’m writing an application that uses face tracking as a means of interaction. The aim of the app is that the user will try to keep an openGL sphere in the air, like if you were playing football and keeping the ball in the air with your head. The tracking works fine and the physics works fine, but its really slow. Does anyone have any suggestions for optimisation? I’m calling the findHaarObjects() function every frame, which is crippling it…should I try threading it?


hey there,

i’m no pro, but looking at the source code,…-er.h?r=198
you could try using the counterfinder instead for head tracking

OpenGL also has the advantage of being able to use hardware acceleration, ie: a graphics card. I don;t know what your setup is, but maybe if you tried your app on someone else’s computer with a simple graphics card, it could make all the difference.

if that doesn’t work, well, it’s hard to say without looking at your source code…

it would also help if you could find out which part of the code is slowing you down? the head tracking? or the combination of head tracking + physics + opengl.

alright, sorry i couldn’t help more.

Im working on a similar project and i need fast facetracking too. What speedes up is:
if your tracker found a face then do the next search in a neigbour pixel area not whole screen -> so actually if theres nobody to detect my threaded facetracker is running with 7fps, when theres a found face it goes up to 30fps. second thing: use a thread


In addition to putting the face detector on a thread… in your video settings, try manually setting the frame rate to 60 fps (instead of “best”) … I’ve found that if you manually set it, you will get better results than if you just use “best”.

Try only searching for a face in the area where you found one last, look into the functions:

void  cvSetImageROI(IplImage* image, CvRect rect);  
void  cvResetImageROI(IplImage* image);  
vRect cvGetImageROI(const IplImage* image);  

They are not wrapped in OF yet, but I know there is a version of the opencv addon that supports it coming up. (might be in the svn already?).

You can easily just use the functions on the image you get from the getCvImage() function, but remember to set the ROI back when you are done or you’ll get som odd behaviour.



I noticed that you can improve as well a lot the performance fixing the min size of the cvHaarDetectObjects() method.

Really useful if you can control the depth of what you’re recording !

For example, for a 320x240 video I have quite good result with :

cvHaarDetectObjects( inputCopy.getCvImage(), cascade, storage,  
                                            scaleHaar, 2, CV_HAAR_DO_CANNY_PRUNING, cvSize(40,40));  

On other hand, I don’t know what’s a thread ?
Did some one of you has simple examples of how it works ?