Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

step1: (shave off the original alpha channel, and keep it for later)

Mat image = ... // 4 channels bgra

Mat channels[4];
split(image, channels);

Mat alpha = channels[3];

step2: (when you're done with your canny or whatever, make a new Mat with alpha)

Mat canny = ... // 1 channel grayscale !

Mat newchan[4] = { canny, canny, canny, alpha };
Mat final;
merge(newchan, 4, final);

first note, that alpha is irrelevant to computer vision, so opencv won't ever use or try to display it.

step1: (shave off the original alpha channel, and keep it for later)

Mat image = ... // 4 channels bgra

Mat channels[4];
split(image, channels);

Mat alpha = channels[3];

step2: (when you're done with your canny or whatever, make a new Mat with alpha)

Mat canny = ... // 1 channel grayscale !

Mat newchan[4] = { canny, canny, canny, alpha };
Mat final;
merge(newchan, 4, final);

step3: (save it to disk):

imwrite("glasses.png", final);