An approach to the implementation of camera real-time filter on Android platform (11)--real-time beauty filter

Source: Internet
Author: User

The last chapter finishes the processing of the image. The process is optimized by simple algorithm, which can achieve very fast speed. But not for real-time beauty. Experiments have been made using a scheme that only processes the Y signal. The radius limit is about 5-10, and more than 10 is noticeable. But for 1920x1080 's preview resolution. Taking 10 as a radius is very difficult to get the ideal result. Even reducing the resolution to 1280x720 is passable. So it is very difficult to simply apply directly to the mobile real-time processing.
On the one hand, the character's normal skin, the color should be red. So it causes the red channel of the character image to light up, so that the red channel retains less detail components, in contrast. The green channel retains many other details, so. Under normal circumstances, we can only use the filter green channel to achieve real-time grinding skin. The following is a brief introduction to ideas:
1. Remove the green channel and blur the green channel, such as Gaussian blur. Get the Blur value after Samplecolor:
Create an array of length 20~25 in the vertex shader as a point where the fragment shader needs to fetch data
  
 varying VEC2 blurcoordinates[20]; 
blurcoordinates[0] = inputtexturecoordinate.xy + singlestepoffset * VEC2 (0.0,-10.0); ..... blurcoordinates[19] = inputtexturecoordinate.xy + Singlestepoffset * VEC2 (4.0, -4.0); </span> 
The fragment shader sequentially takes the green channel values of these points, multiplied by the weights. The last divided by the total weight. The green channel value after the blur is obtained
2. Subtract samplecolor with the original green channel value. Plus 0.5 (i.e. 128), the 1+2 Two step is the high contrast retention in PS:
VEC3 Centralcolor = texture2d (Inputimagetexture, texturecoordinate). rgb;float highpass = centralcolor.g-samplecolor + 0 .5;

3. The above-mentioned result value is 3-5 times strong light processing (see Chapter seventh, "overlay" mixed mode). This step can make the noise more prominent:
        if (color <= 0.5) {color = color * color * 2.0;} Else{color = 1.0-((1.0-color) * (1.0-color) * 2.0);
After the 1-3 figure:

Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /southeast ">

4. Calculate the grayscale value of the original, the formula is 0.299*r + 0.587*g + 0.114*b:
       Const HIGHP VEC3 W = VEC3 (0.299,0.587,0.114);       float lumance = dot (Centralcolor, W);
To get a grayscale image:

Watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqv/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity /southeast ">

5. Use grayscale values as thresholds to exclude non-skin parts. Based on the gray value calculation, the original image and the result graph after 1-3 are synthesized:
float alpha = POW (lumance, 0.333333); VEC3 Smoothcolor = Centralcolor + (CENTRALCOLOR-VEC3 (highpass)) *alpha*0.1;</ Span>
The original RGB value compared with the result of high contrast, the greater the noise, the greater the result after subtracting the two, adding a certain value on the basis of the original result, to improve the brightness and eliminate the noise.
The second parameter in the POW function is adjustable (1/3~1), the smaller the value, the larger the alpha, the more obvious the grinding effect. Change this value to be a beauty level
6. Add brightness to the blend result:
7. Use grayscale values as transparency to mix the original and mixed results, and adjust the saturation:
Original and result diagram:
Above with pictures to give examples, the rest is to turn on the camera to switch to the front to see the effect of the ~
Code address: (20160108 Japanese will be uploaded at a later date)
Below the address in the magiccamera/magicfilter/res/raw/folder
BEAUTIFY_FRAGMENT.GLSL and BEAUTIFY_VERTEX.GLSL
Other than that:
---------------------------------------------- ------------------------------------------------------
magiccamera address  
40+ filters and real-time beauty features are implemented using GLSL
Achieve a photo peeling and whitening function
Welcome to the link click on the top right corner star

An approach to the implementation of camera real-time filter on Android platform (11)--real-time beauty filter

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.