Hi, I’m pulling my hair out trying to get ofTexture into ofxCvImage (either ofxCvColorImage or ofxCvGrayscaleImage) without unsynchronised output. I’ve tried permutations of cv::Mat, IplImage, ofImage etc.
It seems the fourth parameter on ofxCvImage seems to be depreciated?
// Setup ...
int w = 640;
int h = 480;
ofxCvGrayscaleImage cvimage;
ofFbo fbo;
ofPixels pixels;
ofImage img;
fbo.allocate(w,h);
pixels.allocate(w,h,1); // I've tried 0 - 4
cvimage.allocate(w, h); // There is no third parameter available?
// Draw ...
img.setFromPixels(pixels);
img.draw(0,0,w,h); // This is fine
fbo.readToPixels(pixels);
cvimage.setFromPixels(pixels);
cvimage.draw(0,0,w,h); // Here the channels are unsynchronised
Without checking your code deeply: in case your pixel image is of color (what ofImage usually is - or even always?) you run into problems because your CV image is grayscale. That makes 3 channels vs. 1 channel.
I don’t know what you do with pixels before, so can’t say if the channel in pixels.allocate() is even taken into account (depending on how you generate your pixels they might get re-allocated). So I’d suggest you try the same using an ofxCvColorImage first. If this works, you can most easily copy ofxCvColorImage to ofxCvGrayscaleImage easily (because openCV takes care of the channels for you):
Hey Dasoe, thanks kindly - the code is spread across multiple addons so hard to copy/paste here, but I think it’s solved now.
You’re right I was missing typing out another section which was ofFbo origin readToPixels to the ofPixels pixels … so allocating the original ofFbo to .allocate(w, h, GL_RGB) fixed the problem.
This is all part of a rather hacky process trying to alpha mask layers without using shaders, and using OF_BLENDING_MULTIPLY twice. It seems shader examples aren’t working on Raspberry Pi on 0.9.3, but I will check on 0.9.8 now…