With the advancement of technology, we now see more and more beautiful women. No other, beautiful face.

Today, a programmer wrote his girlfriend a “beauty camera” to make her happy! Let’s see how this works.

Programmers who can’t be photographers are not good men! 10 minutes get her own “beauty camera”

Do programmers earn millions per year? How can Android Programmers get paid well?

preface

Always getting teased by your girlfriend about your bad camera skills? Is not in mind, has emerged hand in hand with his girlfriend to go to Disneyland, his girlfriend happy to let you take pictures for him, but not to give you, the photos taken not only face thigh short out of focus, but also one meter and five both visual sense, instantly annoyed his girlfriend.

How does this little scene baffle our programmers? As a programmer, the product manager’s needs can be met, but your girlfriend’s needs can’t be met in a minute? Quickly create an exclusive her ** * “beauty camera”, ** easily achieve face, big eyes and other functions, let your girlfriend do what she wants, instantly achieve beauty effect.

How was the beauty camera developed? What’s the principle?

With a tap, it automatically detects the face in the photo and then enlarges the eyes and reduces the face to achieve the effect of beauty. How exactly does this work?

Principle is simple, the use of the face detection function of machine learning services, huawei to test the face up to 855 points, back face contour, eyebrows, eyes, nose, mouth, ears and other parts and the coordinates of facial information such as the deflection Angle, so that we can according to these information to quickly build a “skin care” camera, to beautify the human face, You can even add some fun elements to your face, such as cute stickers, to spice up the picture.

10 minutes get “Beauty camera” development tutorial!

 1. Development preparation

For details, see Huawei Developer Alliance. This section lists the key development steps.

1.1 Configuring Maven storehouse addresses in Project gradle

buildscript { repositories { ... maven {url 'https://developer.huawei.com/repo/'} } } dependencies { ... The classpath 'com. Huawei. Agconnect: agcp: 1.3.1.300'} allprojects {repositories {... maven {url 'https://developer.huawei.com/repo/'} } }Copy the code

1.2 Added configuration of file headers

After integrating the SDK, add the configuration in the file header

 apply plugin: 'com.android.application'	 apply plugin: 'com.android.application'
Copy the code

1.3 Configure SDK dependencies in App Gradle

Implementation 'com.huawei. HMS: mL-computer-Vision-face :2.0.1.300 Implementation 'com.huawei. HMS: mL-computer-Vision-face-shape-point-model :2.0.1.300 'com.huawei. HMS: ML-computer-Vision-face-emotion-model :2.0.1.300' // Implement feature detection model package 'com. Huawei. HMS: ml - computer vision - face feature - model: 2.0.1.300'}Copy the code

1.4 Add the following statement to the androidmanifest.xml file to automatically update the machine learning model

<manifest
    ...
    <meta-data
        android:name="com.huawei.hms.ml.DEPENDENCY" 
        android:value= "face"/>
    ...
</manifest>
Copy the code

 1.5 Applying for Camera Permission

<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
Copy the code

2. Code development

2.1 Create a face analyzer using the default parameters

analyzer =   MLAnalyzerFactory.getInstance().getFaceAnalyzer();
Copy the code

2.2 Create an MLFrame object through Android.graphics.bitmap for the analyzer to detect the image

MLFrame frame = MLFrame.fromBitmap(bitmap);
Copy the code

2.3 Call the “asyncAnalyseFrame” method for face detection

Task<List<MLFace>> task = analyzer.asyncAnalyseFrame(frame); task.addOnSuccessListener(new OnSuccessListener<List<MLFace>>() { @Override public void onSuccess(List<MLFace> faces) { // The detection succeeds, and the key information of the face is obtained. }}).addonFailureListener (new OnFailureListener() {@override public void onFailure(Exception e) {// Failed to check. }});Copy the code

2.4 Carry out different degrees of big eyes and thin face processing through the progress bar.

MagnifyEye method and smallFaceMesh method are respectively called to realize the big eyes algorithm and thin face algorithm

private SeekBar.OnSeekBarChangeListener onSeekBarChangeListener = new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, Boolean fromUser) {switch (seekbar.getid ()) {case r.id.seekbareye: // When the big eye progress bar changes... Case r.d.siekbarface: // When the progress bar changes... }}}Copy the code

2.5 * * * *Detection complete, release analyzer

try { if (analyzer ! = null) { analyzer.stop(); } } catch (IOException e) { Log.e(TAG, "e=" + e.getMessage()); }Copy the code

Take a look at the simple “beauty camera” Demo!

So, did you get it? Get a girlfriend limited edition “beauty Camera” quickly. Not only can you enlarge your eyes and slim your face, you can also add cute stickers, smile snaps and more, all of which can be achieved quickly by connecting to machine learning services! If you want to impress your girlfriend, download the GitHub source.

The last

It is really difficult for programmers to find a wife. If someone is willing to accompany you, you must cherish it. You can also use your own technology to do something to make your partner happy. First, of course, you have to have the skills.

Android learning is a long road, we have to learn things not only surface technology, but also go deep into the bottom, understand the principle below, only in this way, we can improve their competitiveness, in today’s competitive world.

A journey of a thousand miles begins with a single step. May you and I encourage each other.

I have compiled the most important and hot Android study direction materials in this period of timeMy GitHub, there are different directions of self-study programming routes, interview questions/interviews, and a series of technical articles. (Click here to view it)

The resources are constantly updated. Welcome to study and discuss together.