开发者

Processing video from the camera in the background

Is it possible to process (get the pixels from the camera and apply some algorithms) video in the background? That is, without actually displaying the video on the screen.

If it is possible, what are s开发者_如何学Pythonome good tutorials/examples?


This might work. Assuming you already have a code that currently displays camerapreview on screen, find the line that reads something like:

camera.setPreviewDisplay(nameofsurface);

and change it to

camera.setPreviewDisplay(null);

All the camera frames will still be available in your public void onPreviewFrame(byte[] data, Camera camera) method.

Incase you do not already know how to, add the following lines to that method in the beginning to cast the byte array as bitmap for your processing purposes.

Camera.Parameters parameters = camera.getParameters();

                    int width = parameters.getPreviewSize().width;
                    int height = parameters.getPreviewSize().height;

                    ByteArrayOutputStream outstr = new ByteArrayOutputStream();
                    Rect rect = new Rect(0,0, width, height); 
                    YuvImage yuvimage=new YuvImage(data,ImageFormat.NV21,width,height,null);
                    yuvimage.compressToJpeg(rect, 100, outstr);
                    Bitmap bmp = BitmapFactory.decodeByteArray(outstr.toByteArray(), 0, outstr.size());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜