Reputation: 559
I'm loading a Mat from a Bitmap using Utils.bitmapToMat(). This produces a matrix with 4 channels. How do I get a matrix with 3 channels, with the alpha channel simply removed?
In other words, I would like the python equivalent of mat[:,:,0:3] in opencv java on android.
Upvotes: 1
Views: 1483
Reputation: 32144
Assuming the alpha channel is the last color channel (BGRA or RGBA color format), you may use Imgproc.cvtColor
with Imgproc.COLOR_BGRA2BGR
argument:
// Creating the empty destination matrix
Mat dst_mat = new Mat();
// Converting the image from BGRA to BGR and saving it in the dst_mat matrix
Imgproc.cvtColor(mat, dst_mat, Imgproc.COLOR_BGRA2BGR);
Note:
Upvotes: 1