Merging two ofVideoGrabbers

Hi all!

I need to merge two images from two different ofVideoGrabbers. I know that i must use Fbo but i cant get this working. This is what i have;

setup():

fbo.allocate(320, 240);
fbo.begin();
ofClear(255,255,255, 0);
fbo.end();

update():

fbo.begin();  
videoGrabber2.draw(0, 0, 320, 240);  
videoGrabber1.draw(320,0,320,240);  
fbo.end();  

ofTexture tex = fbo.getTextureReference(); // from FBO to Texture  
tex.readToPixels(pix); // from texture to pixels  
colorImg.setFromPixels(pix); // from pixels to ofxCvImage  
colorImg.flagImageChanged(); // update the iplm image 

grayImage = colorImg;	//Convert to grayscale image

draw():

grayImage.draw(0,0);

but nothing appears. Im i missing something important? Thanks!

lets see:

  1. you are allocating the fbo with 320,240 but you are drawing the videoGrabber1 at the position 320 wich its out of fbo size.

    I think you want
    fbo.allocate(640,240);

  2. why are you using a texture??? Seems like you want to pass the fb0 pixels to an ofImage

    ofPixels pxs;
    fbo.readToPixels(pxs);
    colorImg.setFromPixels(pxs);

    if you want to turn colorImg to grayscale
    colorImg.setImageType(OF_IMAGE_GRAYSCALE);

Thanks @pandereto!
Still not getting any image… The webcams are on, i dont have any errros, but no image at all.
On my output window i have this:

[notice] ofFbo: checkGLSupport(): maxColorAttachments: 8, maxDrawBuffers: 8, maxSamples: 4

Any idea?
I need to convert the two videoGrabbers to an ofxCvGrayscaleImage to make some blob detention on it.

You should have more errors in the code, post here the project or a small sample of what its not working (all the code not snippets).

The console output its ok

The errors must be on the fbo part, since everything else is working. But here is my code:

setup():

video.setDeviceID(0);
video.initGrabber(320,240);
	
video2.setDeviceID(1);
video2.initGrabber(320,240);

colorImg.allocate(640, 240);
grayImg.allocate(640, 240);

fbo.allocate(640,240);
fbo.begin();
ofClear(255,255,255, 0);
fbo.end();

update():

video.update();	
video2.update();
    	
if ( video.isFrameNew() ) {

    image.setFromPixels( video.getPixelsRef() );
    image2.setFromPixels( video2.getPixelsRef() );

    fbo.begin();  
    image.draw(0, 0, 320, 240);  
    image2.draw(320,0,320,240);
    fbo.end();  

    ofPixels pxs;
    fbo.readToPixels(pxs);
    colorImg.setFromPixels(pxs);

    grayImg = colorImg;

    if (bLearnBackground == true) {
       grayBg = grayImg;
	   bLearnBackground = false;
	}
	
	grayDiff.absDiff(grayBg, grayImg);

   contourFinder.findContours(grayDiff,minBlobSize, maxBlobSize, blobNum, false);
   blobTracker.trackBlobs(contourFinder.blobs);
}

draw():

grayImg.draw(0,0);
blobTracker.draw(0,240);

can you draw the fbo to see if its right ??

fbo.draw(0,0);`

also not use alpha it don’t need

fbo.allocate(640,240);
fbo.begin();
ofClear(255);
fbo.end();`

I’ve already tried that, and nothing…

what its nothing?

when you draw the fbo can you see something?

omg, sorry!! i had the fbo.draw() inside of an if that i wasnt using (i commented it to try this, so stupid!!).
Ok, it is working!!! thank you so muuuch! Now i have a different problem.

when i have colorImg.draw() or the grayImg.draw(), the image looks like this:

and with the fbo.draw():

Do you know why this is happening?

Ok, problem solved:

setup():

fbo.allocate(640,240, GL_RGB);
fbo.begin();
ofClear(255);
fbo.end();

pix.allocate(640,240, 3);

thanks @pandereto for all the help! :smiley: