Revision history [back]

In this particular case I would suggest to draw the shapeContour directly on the resulting image with 0. Something like:

cv::fillPoly(retImage, shapeContour, 0);


It takes much less time (no need to recopy) and uses less memory (no need for mask image).

Otherwise if you already got the mask image (0=delete, otherwise 255), you could use the per element matrix operations:

Result = Image & Mask;


where Result, Image and Mask are matrices.

To use an alpha channel, use the matrix multiplication with Mask values between 0 and 1:

Result = Image.mul(Mask);


This way you can even combine two images using a mask:

Result = Image1 & Mask + Image2 & ~Mask;