Difficulty getting ofTexture into ofxCvImage


#1

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

What am I missing?


#2

Hello autr,

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):

ofxCvColorImage cvColorimage;
ofxCvGrayscaleImage cvGrayimage;

...

cvGrayimage = cvColorimage;

Does this help or did I miss the point?

greetings & have a great day!
oe

P.S.: I do not see where you use your fbo. It’s probably from earlier tries or because there is missing a part in the code?


#3

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…


#4

Dropping this here in case anyone stumbles on this post with same problem - Raspberry Pi shader examples working by changing GL version; https://github.com/openframeworks/openFrameworks/issues/5056