关于hms-core:Merry-Christmas集成华为HMS-ML-Kit手部关键点识别来接住圣诞老人的礼物吧

3次阅读

共计 2535 个字符,预计需要花费 7 分钟才能阅读完成。

前言

We wish you a Merry Christmas, We wish you a Merry Christmas, We wish you a Merry Christmas and Happy New Year。圣诞节降临是不是大街小巷曾经想起了这首相熟的圣诞歌曲了呢?铺天盖地的圣诞树,圣诞玩偶,和雪花都在揭示着你圣诞节的到来,一款集成了华为 HMS ML Kit 手部关键点检测的圣诞小游戏就十分应景啦,一起来体验看看吧!

利用场景

圣诞小游戏是通过手势辨认来管制雪橇车左右挪动,从而接住从天掉落下来的各类圣诞礼物,每隔 15 秒将提一次速,给玩家带来不一样的购物游戏体验,快来接住圣诞老人的礼物吧!

开发实战

1. 配置 Maven 仓地址
关上 Android Studio 我的项目级“build.gradle”文件

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/'}
    }
}

2.Full SDK 集成

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'
}

用上述形式两种办法之一集成 SDK 后,在文件头增加配置。
在 apply plugin: ‘com.android.application’ 后增加 apply plugin: ‘com.huawei.agconnect’

3. 创立手部关键点分析器

MLHandKeypointAnalyzer analyzer =MLHandKeypointAnalyzerFactory.getInstance().getHandKeypointAnalyzer();

4. 创立辨认后果解决类“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() {// 检测完结回调办法,用于开释资源等。}
}

5. 设置辨认后果处理器,实现分析器与后果处理器的绑定

analyzer.setTransactor(new HandKeypointTransactor());

6. 创立 LensEngine

LensEngine lensEngine = new LensEngine.Creator(getApplicationContext(), analyzer)
    .setLensType(LensEngine.BACK_LENS)
    .applyDisplayDimension(1280, 720)
    .applyFps(20.0f)
    .enableAutomaticFocus(true)
    .create();

7. 调用 run 办法,启动相机,读取视频流,进行辨认

// 请自行实现 SurfaceView 控件的其余逻辑。SurfaceView mSurfaceView = findViewById(R.id.surface_view);
try {lensEngine.run(mSurfaceView.getHolder());
} catch (IOException e) {// 异样解决逻辑。}
  1. 检测实现,进行分析器,开释检测资源
if (analyzer != null) {analyzer.stop();
}
if (lensEngine != null) {lensEngine.release();
}

结束语

手部关键点辨认反对辨认包含手指指尖,手段等 21 个手部关键点,并返回关键点的地位数据。这款圣诞小游戏就是通过辨认手部动静轨迹而管制雪橇车的挪动,来接住各类从天而降的礼物,减少游戏的可玩性和趣味性。手部关键点辨认还能够广泛应用在其它类别的 APP 上,大家一起来关上脑洞开发试试吧!

理解更多

欲了解更多详情,请参阅:

华为开发者联盟官网:https://developer.huawei.com/consumer/cn/hms?ha_source=hms1

获取开发领导文档:https://developer.huawei.com/consumer/cn/doc/development?ha_source=hms1

参加开发者探讨请到 Reddit 社区:https://www.reddit.com/r/HMSCore/

下载 demo 和示例代码请到 Github:https://github.com/HMS-Core

解决集成问题请到 Stack Overflow:https://stackoverflow.com/questions/tagged/huawei-mobile-services?tab=Newest


原文链接:https://developer.huawei.com/consumer/cn/forum/topic/0202442756764380482?fid=18

原作者:timer

正文完
 0