Android Camera Real-Time Filter (8) and androidcamera
1. What can Android Camera do?1. Functions
- Take a photo
- Video Recording
- Viewfinder (scanning applications, such as face recognition, business card recognition, and bar code recognition)
2. Implement your own Camera program based on the Camera API. There are 7 steps in total. Created with Rapha rjl 2.1.2 1. initialize SurfaceHolder 2. Camera instance SurfaceCreated 3. Callback SurfaceChanged 4. Clear SurfaceDestroyed 5. layout SurfaceView 6. Add a photo button
Ii. What is Camera Preview?
The RAW data returned by the camera is processed by the isp to form the yuv data. The android system draws the data to the framing area, and continuously draws the frame data to form the Real-Time Preview data.
3. How to obtain data in the Camera Preview?
- Camera. PreviewCallback
- SetPreviewCallback
When a new preview frame is displayed on the screen, the onPreviewFrame method is called (obtained from time to time)
- SetPreviewCallbackWithBuffer
It works in the same way as setPreviewCallback, but requires a specified number of bytes.
A group is used as a buffer to preview image data (addCallbackBuffer)
4. How does Android Camera Real-Time Filter work? Created with Rapha rjl 2.1.2 0. Set the scenic spot size to 1 pixel. 1. Obtain the preview frame data yuv from the Scenic Spot 2. The obtained YUV420SP and RGB are converted. 3. Filter Algorithm Rendering 4. Draw the processed layer on the screen.
YUV to RGB algorithm, the conversion formula is generally as follows, also linear relationship:
R = Y + 1.14 V
G = Y-0.39u- 0.58 V
B = Y + 2.03U
Problem
1. Choppy screen, low user experience
2. Low performance, affecting system performance
How to optimize it?
-Increase the stream level
Image Rendering using OpenGL ES SurfaceTexture
-Improve Performance
GPU Optimization