Huawei Developers
Published in

Huawei Developers

How HUAWEI ML Kit’s Face Detection and Hand Keypoint Detection Capabilities Helped with Creating the Game Crazy Rockets

Introduction

Application Scenarios

Development Practice

Preparations

1. Face Detection

allprojects {repositories {google()jcenter()maven {url 'https://developer.huawei.com/repo/'}}}
buildscript {repositories {google()jcenter()maven {url 'https://developer.huawei.com/repo/'}}}
dependencies {...classpath 'com.huawei.agconnect:agcp:1.3.1.300'}}
public class FaceAnalyzerTransactor implements MLAnalyzer.MLTransactor<MLFace> {@Overridepublic void transactResult(MLAnalyzer.Result<MLFace> results) {SparseArray<MLFace> items = results.getAnalyseList();// Process detection results as required. Note that only the detection results are processed.// Other detection-related APIs provided by ML Kit cannot be called.}@Overridepublic void destroy() {// Callback method used to release resources when the detection ends.}}
LensEngine lensEngine = new LensEngine.Creator(getApplicationContext(), analyzer).setLensType(LensEngine.BACK_LENS).applyDisplayDimension(1440, 1080).applyFps(30.0f).enableAutomaticFocus(true).create();
// Implement other logic of the SurfaceView control by yourself.SurfaceView mSurfaceView = findViewById(R.id.surface_view);try {lensEngine.run(mSurfaceView.getHolder());} catch (IOException e) {// Exception handling logic.}

1.7 Release Detection Resources

if (analyzer != null) {try {analyzer.stop();} catch (IOException e) {// Exception handling.}}if (lensEngine != null) {lensEngine.release();}

2. Hand Keypoint Detection

allprojects {repositories {google()jcenter()maven {url 'https://developer.huawei.com/repo/'}}}
buildscript {repositories {google()jcenter()maven {url 'https://developer.huawei.com/repo/'}}}
dependencies {...classpath 'com.huawei.agconnect:agcp:1.3.1.300'}}
// Import the base SDK.implementation 'com.huawei.hms:ml-computer-vision-handkeypoint:2.0.4.300'// Import the hand keypoint detection model package.implementation 'com.huawei.hms:ml-computer-vision-handkeypoint-model:2.0.4.300'
MLHandKeypointAnalyzer analyzer =MLHandKeypointAnalyzerFactory.getInstance().getHandKeypointAnalyzer();
public class HandKeypointTransactor implements MLAnalyzer.MLTransactor<List<MLHandKeypoints>> {@Overridepublic void transactResult(MLAnalyzer.Result<List<MLHandKeypoints>> results) {SparseArray<List<MLHandKeypoints>> analyseList = results.getAnalyseList();// Process detection results as required. Note that only the detection results are processed.// Other detection-related APIs provided by ML Kit cannot be called.}@Overridepublic void destroy() {// Callback method used to release resources when the detection ends.}}
LensEngine lensEngine = new LensEngine.Creator(getApplicationContext(), analyzer).setLensType(LensEngine.BACK_LENS).applyDisplayDimension(1280, 720).applyFps(20.0f).enableAutomaticFocus(true).create();
// Implement other logic of the SurfaceView control by yourself.SurfaceView mSurfaceView = findViewById(R.id.surface_view);try {lensEngine.run(mSurfaceView.getHolder());} catch (IOException e) {// Exception handling logic.}
if (analyzer != null) {analyzer.stop();}if (lensEngine != null) {lensEngine.release();}

Learn More

--

--

As Huawei Developers, our Medium publication where we share information about the use of Huawei Ecosystem

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store