Frame rate drop in linux and windows while using opencv find contours


I have an interactive floor installation, working on linux ubuntu 12.04. and of_v0.8.4
While porting it to linux ubuntu 16.04 and of_v0.9.8 I find the frame rate dropping remarkably to as low as 4 on linux,
Also, just to test out any hardware issues, I tried the same code on windows i5/8gb system with windows 10, the frame rate was ~1.
On linux I have tried using openbox and tried changing the compiz settings as suggested in
but to no avail.
What should I look into to resolve the issue.


Are you able to determine if the slowdown comes from the drawing code or from the cv calculations?


Can you post your code that slows down?


This is the piece of code which is slowing down the entire frame rate. I have a fish-eye camera, which gives me a single image. The image is first mirrored then divided the image in two parts. Both the parts are then warped to select only the region of interest. Subsequently blobs are being found. The reference images were also created using the same procedure.

void blobFinder::update(){

    	   img.setFromPixels(vidGrabber.getPixels()) ;

    	            lhs.cropFrom(img,points[0].x,points[1].y,lhsWidth,lhsHeight) ;
    	            rhs.cropFrom(img,points[1].x,points[1].y,rhsWidth,rhsHeight) ;
    	            lhColorImg.allocate(lhs.getWidth(),lhs.getHeight()) ;
    	            rhColorImg.allocate(rhs.getWidth(),rhs.getHeight()) ;
    	            lhColorImg.setFromPixels(lhs.getPixels()) ;
    	            rhColorImg.setFromPixels(rhs.getPixels()) ;
    	            grayLeft.allocate(lhsWidth,lhsHeight) ;
    	            grayLeft = lhColorImg ;
    	            grayRight = rhColorImg ;
    	            lcontourFinder.findContours(leftDiff,100,left.getWidth()*left.getHeight()/4, 4,false, true) ;
    	            rcontourFinder.findContours(rightDiff,100,right.getWidth()*right.getHeight()/4, 4,false, true) ;



it looks like you are allocating 4 images every time you call this update function – if the images don’t change in size maybe it would help speed wise to allocate outside of this function.


Thanks, I did move that out to setup, but very insignificant improvement has resulted, from ~4.2 to ~5.1 fps.


So if you only remove the code in update(), does it work properly with the correct frame rate?


yes indeed, it does.
as an aside, I would like to mention that I am working with 1920x1080 resolution for the images


I’m not really sure but I think It could be one of your methods internally calling ofGetScreenWidth() or ofGetScreenHeight() which causes slow down on Linux.