Programmers who cannot be photographers are not good men! Get her "beauty camera" in 10 minutes

Always complained by your girlfriend about poor photo taking skills? In my mind, it has emerged that when I went to Disneyland with my girlfriend holding hands, my girlfriend happily asked you to take a photo of him, but you didn’t know how to do it. The photos you took were not only short of your face and thighs but not in focus, but also a five-meter vision. Annoyed his girlfriend instantly.

How can this little scene stump our programmers? As a programmer, the product manager's needs can be met, but the girlfriend's needs can be settled within minutes? Quickly create a "beauty camera" exclusively for her , easily achieve thin face, big eyes and other functions, let your girlfriend operate as you wish, and instantly realize the beauty effect.

1

How was the "beauty camera" developed? What is the principle?

A single tap can automatically detect the face in the photo, and then enlarge the eyes and slim the face to achieve the effect of beautifying. How is this achieved?

The principle is very simple, use Huawei machine learning service face detection function , to face up to 855 key points for testing, part of the return face contour, eyebrows, eyes, nose, mouth, ears and other coordinates and face deflection Angle and other information, so that we can quickly build a "beauty camera" based on this information, beautify the face, and even add some interesting elements, such as cute stickers, to increase the interest of the picture.

10 minutes get "beauty camera" development tutorial!

 1.  Development preparation

The detailed preparation steps can refer to the Huawei Developer Alliance , here are the key development steps.

1.1  Configure Maven warehouse address in project-level gradle

buildscript {
    repositories {
            ...
        maven {url 'https://developer.huawei.com/repo/'}
    }
}
 dependencies {
                              ...
        classpath 'com.huawei.agconnect:agcp:1.3.1.300'
    }
allprojects {
    repositories {
            ...
        maven {url 'https://developer.huawei.com/repo/'}
    }
}

1.2  File header increase configuration

After integrating the SDK , add configuration to the file header

 apply plugin: 'com.android.application'	 apply plugin: 'com.android.application'

1.3  Configure SDK dependencies in application-level gradle

dependencies{ 
    // 引入基础SDK
    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'
    // 引入表情检测模型包
    implementation 'com.huawei.hms:ml-computer-vision-face-emotion-model:2.0.1.300'
    // 引入特征检测模型包
    implementation 'com.huawei.hms:ml-computer-vision-face-feature-model:2.0.1.300'
}

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>

 1.5  Apply for camera permission

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

2.  Code development

2.1   Use the default parameter configuration to create a face analyzer

analyzer =   MLAnalyzerFactory.getInstance().getFaceAnalyzer();

2.2   Create an MLFrame object through android.graphics.Bitmap for the analyzer to detect pictures

MLFrame frame = MLFrame.fromBitmap(bitmap);

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) {
         // 检测成功,获取脸部关键点信息。
     }
 }).addOnFailureListener(new OnFailureListener() {
     @Override
     public void onFailure(Exception e) {
         // 检测失败。
    }
 });

2.4   Through the progress bar for different degrees of big eyes and face-lifting treatment.

Call the magnifyEye method and the smallFaceMesh method to implement the big eye algorithm and the thin face algorithm respectively

private SeekBar.OnSeekBarChangeListener onSeekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {
    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        switch (seekBar.getId()) {
            case R.id.seekbareye: // 当大眼进度条变化时,…
            case R.id.seekbarface: // 当瘦脸进度条变化时,…
        }
    }
}

2.5 After the  test is complete, release the analyzer

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

Let's take a look at the demo of the simple "beauty camera" first!

2

How is it, have you learned it? Quickly get a girlfriend limited edition "beauty camera", not only can realize the big eyes and face-lifting function, you can also add the cute little sticker function, smile capture function, etc., all of which can be quickly realized by connecting to the machine learning service! If you also want to show off successfully in front of your girlfriend, please download the GitHub source code .

>>Visit the official website of Huawei Developer Alliance to learn more about it

>>Get development guidance documents

>>Huawei mobile service open source warehouse address: GitHub , Gitee

Follow us and learn about the latest technical information of Huawei Mobile Services for the first time~

 

Guess you like

Origin blog.csdn.net/HUAWEI_HMSCore/article/details/113857313