I haven’t played with ofxOpenCv much and I’m trying to figure out how to copy pixels from 3 images into a large one. I’ve started with something as basic as this:
large.setFromPixels(small.getPixels(), 320, 240);
large still remains blank.
I’ve tried calls like:
but no joy.
How can I copy pixels from multiple images into a single one with ofxOpenCv ?
not sure if this will fix your problem but try allocating to the same size as the pixels you then set (320x240).
Well, I’d use two different methods.
Less funcional one:
1.-Read the three images separatelly.
2.-For loop using the big images resolution and fill it with the other pixels.
This method is tiresome and offer little customization. Loop over images bring all sorts of output problems.
Really cool method I always use:
1.-Make and ofFBO (which is space in the memory) and allocate its size (640,480). Also load other stuff.
2.-While in the draw(), use bigImage.begin() to start drawing onto the FBO. This will not draw on screen. Now draw the other images onto there like imageA.draw(20,20) or imageA.draw(20,20,100,140) if you wish to dynamically resize every picture.
3.-End ofFbo using bigImage.end();
4.-Now draw that ofFbo anywhere you like. In your case you would need to send that ofFbo over to an ofxOpenCv image type and you will need an ofPixels as a half step in between.
Your files would have to have these parts inside them
ofImage imageA, imageB, imageC,
bigImage.allocate(640, 480, GL_LUMINANCE); // GL_LUMINANCE is greyscale
monoPixels.allocate(640, 480, OF_PIXELS_MONO); // Greyscale ofPixels that goes over a greyscale ofxOpenCv
// Load imageA, imageB, imageC
// Clear the ofFbo if you must
// Draw images where you want them and in the size you would like.
// Aquí se traspasa el FBO a OpenCV
// Do your openCV wizardry.
In order to be able to use Color you have to be consistent between the ofFbo, monoPixels and, ofxOpenCv image type.
There are other methods of course but this ofFbo one offers you far too much. I needed to write it because I also had a hard time trying to do exactly this a few months ago and I wish I had read something like this.
Hey, this is a really detailed answer !
I appreciate taking your time for this.
I did thought about copying pixels one by one with loops, but loops would get messy if I’d need to transform(translate/rotate) the image.
I was hoping there I could do all the operations using the ofxCvGrayscaleImage class, but
ofFBO looks very flexible (it’s a bit like working with PGraphics in Processing).
Glad to help.
This method is actually really fast and you can rotate and do all sorts of openGL stuff with it (rotations, shaders, homography, anything).