Image processing with Android Camera

2019-01-22 10:06发布

问题:

I want to use the onPreviewFrame to post-process the image before displaying it to the user (i.e. apply a color tint, sepia, etc). As I understand, the byte[] data returned to the callback is encoded in YUV420sp. Have people been decoding this to RGB in Java or using NDK (native code)? Does anyone have an example of a function that decodes this to RGB and how the RGB values are used afterwards?

Thanks.

回答1:

I found a sample application that translates the YUV420 into RGB and displays (sort of) real time histograms over the preview image.

http://www.stanford.edu/class/ee368/Android/index.html



回答2:

This helps?

Parameters params = mCamera.getParameters();

param.setPreviewFormat(ImageFormat.RGB_565);

mCamera.setParameters(param);

First check if rgb is supported

http://developer.android.com/reference/android/hardware/Camera.Parameters.html#getPreviewFormat%28%29

and then set preview format to rgb

http://developer.android.com/reference/android/hardware/Camera.Parameters.html#setPreviewFormat%28int%29