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
  • 40,887
  • 13
  • 123
  • 202
alexanoid
  • 24,051
  • 54
  • 210
  • 410

0 Answers0