Processing Android camera frames in real time -


i'm trying create android application process camera frames in real time. start off with, want display grayscale version of camera sees. i've managed extract appropriate values byte array in onpreviewframe method. below snippet of code:

byte[] pic; int pic_size; bitmap picframe; public void onpreviewframe(byte[] frame, camera c) {     pic_size = mcamera.getparameters().getpreviewsize().height * mcamera.getparameters().getpreviewsize().width;     pic = new byte[pic_size];     for(int = 0; < pic_size; i++)     {         pic[i] = frame[i];     }     picframe = bitmapfactory.decodebytearray(pic, 0, pic_size); } 

the first [width*height] values of byte[] frame array luminance (greyscale) values. once i've extracted them, how display them on screen image? not 2d array well, how specify width , height?

you can extensive guidance opencv4android sdk. available examples, tutorial 1 basic. 0 android camera

but, in case, intensive image processing, slower acceptable real-time image processing application. replacement onpreviewframe 's byte array conversion yuvimage:

yuvimage yuvimage = new yuvimage(frame, imageformat.nv21, width, height, null);

create rectangle same size image.

create bytearrayoutputstream , pass this, rectangle , compression value compresstojpeg():

bytearrayoutputstream baos = new bytearrayoutputstream(); yuvimage.compresstojpeg(imagesizerectangle, 100, baos);

byte [] imagedata = baos.tobytearray();

bitmap previewbitmap = bitmapfactory.decodebytearray(imagedata , 0, imagedata .length);

rendering these previewframes on surface , best practices involved new dimension. =)


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -