Processing camera frames on Android
i want to use my android phone to process image, for example, make any operation with de frame and show it with the change (show the image in black/white, grayscale, sepia, etc). This is my code:
public class CameraPreview extends SurfaceView implements SurfaceHolder.Callback,PreviewCallback {
SurfaceHolder mHolder;
Camera mCamera;
private Parameters parameters;
private Size previewSize;
private int[] pixels;
public CameraPreview(Context context) {
super(context);
SurfaceHolder mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_NORMAL);
this.setFocusable(true);
this.requestFocus();
}
public void surfaceCreated(SurfaceHolder holder) {
mCamera = Camera.open();
}
public void surfaceDestroyed(SurfaceHolder holder) {
mCamera.stopPreview();
mCamera.release();
mCamera = null;
}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
setImageSize();
mCamera.startPre开发者_StackOverflow社区view();
mCamera.setPreviewCallback(this);
}
public void onPreviewFrame(byte[] data, Camera camera) {
// transforms NV21 pixel data into RGB pixels
decodeYUV420SP(pixels, data, previewSize.width, previewSize.height);
//here process the image
}
}
the problem is that i don't know how to show the new image processed. In onPreviewFrame I convert yuv to rgb, then I process the image i.e. convert in grayscale, but what i do for show the new image? I need help, thanks!!!!!!!!!!!
You may want to consider using OpenCV or looking at one of their samples for image manipulations:
http://opencv.itseez.com/doc/tutorials/introduction/android_binary_package/android_binary_package.html
I read an article at: http://nhenze.net/?p=107 From what I read in the post, it's not very easy to do, because the onPreviewFrame is not synced with displaying the frames.
Instead, they use a trick to set another view on top of the SurfaceView. On that new View, they render images on an OpenGL texture with OpenGL ES.
I haven't played with it myself, but hope this will put you in the right direction.
精彩评论