Crazy Shopping Cart-Quickly integrate Huawei HMS ML Kit to detect key points of the hand and easily control your shopping cart

Preface

Double Eleven is coming soon. I wonder if your shopping is full of things? I also want to fill my shopping cart, but my wallet doesn't want to, so I can only use virtual shopping in games to satisfy my shopping desire. I didn't expect to discover a small game that integrates the key point detection of Huawei's HMS ML Kit hand-Crazy Shopping Cart. Let's take a look at how this game is implemented with the editor!

Application scenario

The shopping cart crazy game is realized by integrating Huawei's HMS ML Kit hand key point detection service. Through gesture detection, the shopping cart can be controlled to move left and right, so as to catch all kinds of products that fall. It will be picked up every 15 seconds. Speed, to bring players a different shopping game experience.

Insert picture description here

How about it, isn't it exciting for such an interesting game? Let's take a look at the development steps!

Development combat

  1. Configure the Maven warehouse address to
    open the Android Studio project-level "build.gradle" file
buildscript {
    repositories {
        google()
        jcenter()
        maven {url 'https://developer.huawei.com/repo/'}
    }
    dependencies {
        ...
        classpath 'com.huawei.agconnect:agcp:1.4.1.300'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven {url 'https://developer.huawei.com/repo/'}
    }
}
  1. Full SDK integration
dependencies{
    // 引入基础SDK
    implementation 'com.huawei.hms:ml-computer-vision-handkeypoint:2.0.4.300'
    // 引入手部关键点检测模型包
    implementation 'com.huawei.hms:ml-computer-vision-handkeypoint-model:2.0.4.300'
}

After integrating the SDK in one of the above two ways, add configuration in the file header.

Add apply plugin:'com.huawei.agconnect' after apply plugin:'com.android.application'

  1. Create a hand keypoint analyzer
MLHandKeypointAnalyzer analyzer =MLHandKeypointAnalyzerFactory.getInstance().getHandKeypointAnalyzer();
  1. Create recognition result processing class "HandKeypointTransactor"
public class HandKeypointTransactor implements MLAnalyzer.MLTransactor<List<MLHandKeypoints>> {
    @Override
    public void transactResult(MLAnalyzer.Result<List<MLHandKeypoints>> results) {
        SparseArray<List<MLHandKeypoints>> analyseList = results.getAnalyseList();
        // 开发者根据需要处理识别结果,需要注意,这里只对检测结果进行处理。
        // 不可调用ML Kit提供的其他检测相关接口。
    }
    @Override
    public void destroy() {
        // 检测结束回调方法,用于释放资源等。
    }
}
  1. Set the recognition result processor to realize the binding of the analyzer and the result processor
analyzer.setTransactor(new HandKeypointTransactor());
  1. Create LensEngine
LensEngine lensEngine = new LensEngine.Creator(getApplicationContext(), analyzer)
    .setLensType(LensEngine.BACK_LENS)
    .applyDisplayDimension(1280, 720)
    .applyFps(20.0f)
    .enableAutomaticFocus(true)
    .create();
  1. Call the run method, start the camera, read the video stream, and identify
// 请自行实现SurfaceView控件的其他逻辑。
SurfaceView mSurfaceView = findViewById(R.id.surface_view);
try {
    lensEngine.run(mSurfaceView.getHolder());
} catch (IOException e) {
    // 异常处理逻辑。
}
  1. After the detection is complete, stop the analyzer and release the detection resources
if (analyzer != null) {
    analyzer.stop();
}
if (lensEngine != null) {
    lensEngine.release();
}

Concluding remarks

After reading the main development steps, do you think the integration is simple and fast? In addition to the above crazy shopping cart game, hand key point recognition technology has many application scenarios in life. For example, after the software for shooting short videos integrates this technology, it can generate some cute or funny special effects based on the key points of the hand to increase the interest of the short video. Or in a smart home-oriented scene, you can customize some gestures as remote control instructions for smart home appliances to perform some smarter human-computer interaction methods. Come try it out and develop fun and interesting applications together!

Github Demo

For more detailed development guidelines, please refer to the official website of Huawei Developer Alliance:https://developer.huawei.com/consumer/cn/hms/huawei-mlkit


Original link:https://developer.huawei.com/consumer/cn/forum/topic/0204394603426760022?fid=18

Author: timer

Guess you like

Origin blog.51cto.com/14772288/2550367