Ask Your Question
1

Android jpeg byte array to mat

asked 2014-07-03 06:30:31 -0600

borjaevo gravatar image

updated 2014-07-10 12:31:34 -0600

berak gravatar image

Hi everyone,

i'm new on opencv android development. I'm receiving a jpeg byte array on android client by sockets. On server side, a c++ program encodes a mat frame to jpeg before send. I'm receiving at 18fps on android phone with encoding. it's good, but i only have a byte array. I don't know how to decode jpeg to Mat object. I'm looking for a function like c++ Highgui.imdecode(inbuf, IMREAD_UNCHANGED). Can i use this using jni? If yes, how can i use byte[] frame from java in jni function? and, how can i return the mat objet?

Thanks!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-07-10 11:13:51 -0600

borjaevo gravatar image

i found a solution by myself, i dont know if is the best but is working

MatOfByte raw=new MatOfByte(imageStream); Mat A = Highgui.imdecode(raw, 2); // mat to bitmap: //Imgproc.cvtColor(A, B, Imgproc.COLOR_BGR2RGB); Utils.matToBitmap(B, bm);

where bm is an android Bitmap object.

I still have a problem, color of image is bgr and i need rgb. I dont know how can i convert to rgb. I tried Imgproc.cvtColor(A, B, Imgproc.COLOR_BGR2RGB); but fails.

Thanks.

edit flag offensive delete link more

Comments

fails like what ? did you use : Mat B = new Mat(); ? (ppl often forget the 'new' part)

berak gravatar imageberak ( 2014-07-10 12:29:35 -0600 )edit

Question Tools

Stats

Asked: 2014-07-03 06:30:31 -0600

Seen: 2,635 times

Last updated: Jul 10 '14