Bitmap to Mat gives wrong colors back

前端 未结 1 479
独厮守ぢ
独厮守ぢ 2020-12-18 06:46

So I make a bitmap from a blob with the next code:

byte[] blob = contact.getMP();
ByteArrayInputStream inputStream = new ByteArrayInputStream(blob);
Bitmap b         


        
相关标签:
1条回答
  • 2020-12-18 07:20

    The format of color channels in Android Bitmap are RGB But in opencv Mat, the channels are BGR by default.

    So when you do Utils.bitmapToMat(), [B,G,R] values are stored in [R,G,B] channels. The red and blue channels are interchanged.

    One possible solution is to apply cvtcolor on the opencv Mat you got as below: Imgproc.cvtColor(ImageMat, ImageMat, Imgproc.COLOR_BGR2RGB);

    It worked for me.

    0 讨论(0)
提交回复
热议问题