java - Bitmap to Mat gives wrong colors back -
so make bitmap blob next code:
byte[] blob = contact.getmp(); bytearrayinputstream inputstream = new bytearrayinputstream(blob); bitmap bitmap = bitmapfactory.decodestream(inputstream); bitmap scalen = bitmap.createscaledbitmap(bitmap, 320, 240, false);
and gives next output, good
then following make bitmap mat, colors change...
//mat imagemat = new mat(); mat imagemat = new mat(320, 240, cvtype.cv_32f); utils.bitmaptomat(scalen, imagemat);
i have no idea why, nor way make bitmap mat. wrong?
the format of color channels in android bitmap bgr in opencv mat, channels rgb default.
so when utils.bitmaptomat(), [b,g,r] values stored in [r,g,b] channels. red , blue channels interchanged.
one possible solution apply cvtcolor on opencv mat got below: imgproc.cvtcolor(imagemat, imagemat, imgproc.color_bgr2rgb);
it worked me.
Comments
Post a Comment