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() ?