Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can also use mixChannels function:

cv::Mat percepUnit::applyAlpha(const cv::Mat& image, const cv::Mat& mask) 
{
    cv::Mat alphaImage;
    cv::Mat src[] = {image, mask};
    int from_to[] = {0,0, 1,1, 2,2, 3,3};
    cv::mixChannels(src, 2, &alphaImage, 1, from_to, 4);
    return alphaImage;
}

You can also use mixChannels function:function (it must be faster than split/merge approach, because it doesn't require additional buffers):

cv::Mat percepUnit::applyAlpha(const cv::Mat& image, const cv::Mat& mask) 
{
    cv::Mat alphaImage;
    cv::Mat src[] = {image, mask};
    int from_to[] = {0,0, 1,1, 2,2, 3,3};
    cv::mixChannels(src, 2, &alphaImage, 1, from_to, 4);
    return alphaImage;
}