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


#1

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
https://github.com/openframeworks/openFrameworks/issues/5009
but to no avail.
What should I look into to resolve the issue.
Thanks.


#2

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


#3

Can you post your code that slows down?


#4

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(){
    vidGrabber.update();
    if(vidGrabber.isFrameNew()){

    	   img.setFromPixels(vidGrabber.getPixels()) ;
    	            img.mirror(false,true);

    	            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()) ;
    	            lhColorImg.warpPerspective(ofPoint(0,points[0].y-points[1].y),
    	                                   ofPoint(lhsWidth,0),
    	                                   ofPoint(lhsWidth,lhsHeight),
    	                                   ofPoint(0,points[5].y-points[1].y));
    	            rhColorImg.warpPerspective(ofPoint(0,0),
    	                                   ofPoint(points[2].x-points[1].x,points[2].y-points[1].y),
    	                                   ofPoint(points[2].x-points[1].x,points[3].y-points[1].y),
    	                                   ofPoint(0,rhsHeight));
    	            grayLeft.allocate(lhsWidth,lhsHeight) ;
    	            grayRight.allocate(rhsWidth,rhsHeight);
    	            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) ;

    }
}

#5

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.


#6

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


#7

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


#8

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


#9

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.