readToPixels very slow

Hi ,

I hope someone can help or point me in the right direction.

The aim of this is to capture 3d objects in a scene and pass the 2d data from the drawn scren through to OpenCV contourFinder to get out the blobs. This works fine but in the routine below readToPixels has a huge impact on the FPS 300 fps down to 30. Is there a faster way to do this?

Definitions:

  
  
ofTexture tex3D;  
ofPixels tex3DPixels;  
ofxCvGrayscaleImage grayImg;  
  

Inside draw:

  
  
  
    glEnable(GL_DEPTH_TEST);  
  
    camera.begin();  
  
        ofPushMatrix();  
        //---------------------------------------------------------------------------  
  
        ofSetColor(255,255,255);  
  
        ofTranslate(-models.getPosition().x, -models.getPosition().y, -models.getPosition().z);  
        models.drawFaces();  
  
        ofPopMatrix();  
     
    camera.end();  
  
    tex3D.loadScreenData(0,0,textW,textH);  
    tex3D.readToPixels(tex3DPixels);  
    tex3DPixels.resize(textW/2,textH/2);   
    grayImg.setFromPixels(tex3DPixels);  
    grayImg.mirror(true,false); // costs 5fps  
     contourFinder.findContours( grayImg, minArea, maxArea, maxBlobs, true);	// find holes  
  

Thanks in advance

im also very interested in how to do this for a project that i am working on currently.
Really hope that there is a quicker way of doing this as there are some cool techniques you can use with this technique but when you start adding this onto of other CPU intensive techniques the limits to what you can do are quickly reached.

Hopefully someone here knows a work around.

Check for PBO , pixel buffer objects. That should be helpful. you can get bitmap data async.

Hi Victor,

Thanks PBOs look really useful.

http://www.songho.ca/opengl/gl-pbo.html#create

If anyone is looking to use openCV with screen data I have had a five fold performance increase with Kyle McDonalds ofxCV - http://github.com/kylemcdonald/ofxCv