I have OpenCV mask and I need to extract the region from the original image by this mask into the new Mat object.
This is my current code:
Mat tmp = input.clone(); //original image
Core.bitwise_not(mask, mask); // invert mask
tmp.setTo(new Scalar(0, 0, 0, 0), mask);
right now the following line tmp.setTo(new Scalar(0, 0, 0, 0), mask)
produces the following output:
where we have the black background.
Instead of black, I need the transparent background. Please show how it can be implemented with OpenCV.