ofxCVGrayScaleImage to ofImage

I’m trying to convert an ofXCVGrayScaleImage into an ofImage so that I can save it out, as ofxCVImage has no method for doing this.

I’ve tried all manner of snippets on these boards, but am unable to achieve this.

I’m using the following to grab the pixels, but when I try to set them it bombs out. I’m assuming that getPixels in the 1st instance returns something less like a continuous block of grayscale values.

  
  
... // from setup  
myImage.allocate(640, 480,OF_IMAGE_GRAYSCALE);  
...  
// from update  
unsigned char * pixels = grayScaleImage.getPixels();   
myImage.setFromPixels(pixels, 640,480);  
  

I appreciate any help.

can you check this forum thread - I think there is definitely a bug with grayscale setFromPixels –

http://www.openframeworks.cc/forum/view-…-frompixels

do those changes fix things? I’ve noticed this bug recently again and will take a look.

an alternative is to convert the ofxCvGrayscaleImage to color, and use setfrompixels with a color image…

take care,
zach

Hi Zach,

Thanks for the quick reply. Yes, those changes fix the problem.

I also tried your other suggestion as an alternative, and that works fine too.

all the best,

Mark.