1

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:

enter image description here

where we have the black background.

Instead of black, I need the transparent background. Please show how it can be implemented with OpenCV.

Miki
  • 39,217
  • 13
  • 114
  • 193
alexanoid
  • 22,505
  • 46
  • 189
  • 364

0 Answers0