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

enter image description here

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? enter image description here

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

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -