Does ofxCv::drawMat() support RGBA?

Hello all,

I’m internally storing my images as cv::Mats because I’m doing lots of opencv processing on them.

I’ve switched to RGB from BGR (the opencv default) to facilitate this.

I can render a RGBA image by converting to ofImage:

  
  
// Apply the mask as an alpha channel  
cv::Mat testApp::applyAlpha(cv::Mat image, cv::Mat mask) {  
	vector<cv::Mat> channels;  
	cv::Mat alphaImage;  
	if (image.rows == mask.rows and image.cols == mask.cols) {  
		cv::split(image,channels); // break image into channels  
		channels.push_back(mask); // append alpha channel  
	  
		cv::merge(channels,alphaImage); // combine channels  
	}  
  
	return(alphaImage);  
}  
  
void  testApp::setup() {  
  
ofImage tmpImage;  
cv::Mat testMat, matMask, alphaMat;  
  
testMat = cv::imread("/home/bbogart/tmp/test_5.jpg");  
cv::cvtColor(testMat, RGBMat, CV_BGR2RGB);  
matMask = cv::imread("/home/bbogart/tmp/test_5-mask.png");  
cv::cvtColor(matMask, matMask, CV_BGR2GRAY);  
  
alphaMat = applyAlpha(RGBMat, matMask);  
ofxCv::toOf(alphaMat, tmpImage);  
tmpImage.setImageType(OF_IMAGE_COLOR_ALPHA);  
}  
  
void testApp::draw() {  
tmpImage.draw(0,0);  
}  
  

But If I draw alphaMat directly with drawMat() the channels are visually garbled:

  
ofxCv::drawMat(alphaMat,0,0);  

Is there something like setImageType() I can use with drawMat() ?

1 Like

It looks like it doesn’t right now, no, just checking here https://github.com/kylemcdonald/ofxCv/blob/master/libs/ofxCv/src/Helpers.cpp it seems like only 3 and 1 channel images are supported.

I think I’ve had problems using cv::imread before.

Assuming the Open CV processing you’re using doesn’t depend on knowing which channel is which then you can just load images using ofImage and then convert them directly to RGB openCV using toCv() then convert them back to ofImage when drawing.