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  
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);  
void testApp::draw() {  

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


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

1 Like

It looks like it doesn’t right now, no, just checking here 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.