当前位置:网站首页>MediaPipe手势(Hands)
MediaPipe手势(Hands)
2022-06-26 12:40:00 【吃骨头不吐股骨头皮】
系列文章目录
1、Ubuntu上安装MediaPipe
2、Ubuntu上构建Android的MediaPipe
3、Ubuntu上构建MediaPipe Android Archive (AAR)
文章目录
前言
最近刚好有手势识别的需求,所以就看到了MediaPipe的Hands,识别出各个手势的节点坐标,然后简单的计算手势。
这一篇主要是对上一篇编译aar库的补充,因为正式使用上我们自己编译的hands aar库。
一、使用步骤
1.克隆MediaPipe的源码
命令如下:
git clone git@github.com:google/mediapipe.git
或者
git clone https://github.com/google/mediapipe.git
2.MediaPipe的Hands例子
打开Android studio,导入Android MediaPipe例子
路径:mediapipe/mediapipe/examples/android/solutions,solutions这个就是Android的Project,将solutions导入Android studio。
运行之后的结果:
我们接下来需要进行的事情很简单,就是把build.gradle中Google Maven库中的aar替换为我们自己打包的aar。
就是将hands module中如下两个Maven库的aar替换为我们自己打包的aar。
// MediaPipe Hands Solution.
implementation 'com.google.mediapipe:solution-core:latest.release'
implementation 'com.google.mediapipe:hands:latest.release'
构建solution_core.aar
bazel build -c opt --strip=ALWAYS \
--host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
--fat_apk_cpu=arm64-v8a,armeabi-v7a \
--legacy_whole_archive=0 \
--features=-legacy_whole_archive \
--copt=-fvisibility=hidden \
--copt=-ffunction-sections \
--copt=-fdata-sections \
--copt=-fstack-protector \
--copt=-Oz \
--copt=-fomit-frame-pointer \
--copt=-DABSL_MIN_LOG_LEVEL=2 \
--linkopt=-Wl,--gc-sections,--strip-all \
--verbose_failures \
//mediapipe/java/com/google/mediapipe/solutioncore:solution_core.aar
构建hands.aar
bazel build -c opt --strip=ALWAYS \
--host_crosstool_top=@bazel_tools//tools/cpp:toolchain \
--fat_apk_cpu=arm64-v8a,armeabi-v7a \
--legacy_whole_archive=0 \
--features=-legacy_whole_archive \
--copt=-fvisibility=hidden \
--copt=-ffunction-sections \
--copt=-fdata-sections \
--copt=-fstack-protector \
--copt=-Oz \
--copt=-fomit-frame-pointer \
--copt=-DABSL_MIN_LOG_LEVEL=2 \
--linkopt=-Wl,--gc-sections,--strip-all \
--verbose_failures \
//mediapipe/java/com/google/mediapipe/solutions/hands:hands.aar
将构建成功的aar导入hands module的libs中
将aar导入libs中,并且注释掉Google官方的Maven库,如下图
接下来将如下命令写入hands module的build.gradle
// 加载libs中的jar和aar
implementation fileTree(dir: 'libs', include: ['*.jar', '*.aar'])
// MediaPipe deps
implementation 'com.google.flogger:flogger:latest.release'
implementation 'com.google.flogger:flogger-system-backend:latest.release'
implementation 'com.google.code.findbugs:jsr305:latest.release'
implementation 'com.google.guava:guava:27.0.1-android'
implementation 'com.google.protobuf:protobuf-javalite:3.19.1'
// CameraX core library
def camerax_version = "1.0.0-beta10"
implementation "androidx.camera:camera-core:$camerax_version"
implementation "androidx.camera:camera-camera2:$camerax_version"
implementation "androidx.camera:camera-lifecycle:$camerax_version"
// AutoValue
def auto_value_version = "1.8.1"
implementation "com.google.auto.value:auto-value-annotations:$auto_value_version"
annotationProcessor "com.google.auto.value:auto-value:$auto_value_version"
到这一步,我们就已经大功告成,直接运行就行了,就把Maven库替换为我们自己的aar了,以后我们自己对代码的修改都可以自己编译aar。Google也建议我们自己编译aar,因为他们没有出满足所有需求的统一的aar。
注意:此时使用的CameraX版本是"1.0.0-beta10",如果将版本更新到最新的“1.1.0-beta01”,因为最新的版本对当前项目最低兼容的minsdk有要求,会出现如下错误。
Execution failed for task ':hands:checkDebugAarMetadata'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.CheckAarMetadataWorkAction
> The minCompileSdk (31) specified in a
dependency's AAR metadata (META-INF/com/android/build/gradle/aar-metadata.properties)
is greater than this module's compileSdkVersion (android-30).
Dependency: androidx.camera:camera-camera2:1.1.0-beta01.
AAR metadata file: C:\Users\LX\.gradle\caches\transforms-3\00310ff015e50555669b323da52d8e97\transformed\camera-camera2-1.1.0-beta01\META-INF\com\android\build\gradle\aar-metadata.properties.
意思就是当前最新的CameraX最小编译版本(android-31)大于了我当前Hands module的最大编译版本(android-30)。
我们可以从build.gradle看到我们的targetSdkVersion和compileSdkVersion等于30
不想解决这个问题,就不更新CameraX,哈哈。
如果你实在是强迫症就想更新,那参考如下解决方式。
1、修改compileSdkVersion和targetSdkVersion为31
2、修改了之后,会告诉你android 12需要显视指定Activity的export属性
Manifest merger failed : Apps targeting Android 12 and higher are required to specify
an explicit value for `android:exported` when the corresponding component has an intent
filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details.
参考链接:日志中是Google的国外官网链接,不科学上网访问不了,请参考android国内官网的链接
在清单文件中,activity的节点显视指定export属性
二、参考
1、MediaPipe Hands官网文档
2、MediaPipe的GitHub地址
总结
本文仅仅是将MediaPipe Hands的demo运行起来,并且将Google编译的Maven库替换为自己编译的aar,因为如果后续自己有一些需求的变更,可以自己修改代码然后重新生成特别的aar。
边栏推荐
- Vivado error code [drc pdcn-2721] resolution
- 8、【STM32】定时器(TIM)——中断、PWM、输入捕获实验(一文精通定时器)
- Arcpy——InsertLayer()函数的使用:掺入图层到地图文档里
- Learning Processing Zoog
- Fire warning is completed within 10 seconds, and Baidu AI Cloud helps Kunming Guandu build a new benchmark of smart city
- Mysql database explanation (6)
- Electron official docs series: Processes in Electron
- 偶言佳句,孤芳自赏
- MySQL数据库讲解(三)
- map 取值
猜你喜欢

MySQL数据库常见故障——遗忘数据库密码
![[how to connect the network] Chapter 2 (middle): sending a network packet](/img/5f/602c59d3a7ee1154c7410fb2fcfc41.png)
[how to connect the network] Chapter 2 (middle): sending a network packet

Arcpy -- use of insertlayer() function: adding layers to map documents

Electron official docs series: Get Started

First pass! Baidu AI Cloud Xiling platform has obtained the authoritative certification of digital human ability evaluation from the Institute of information technology

2、并行接口、协议和相关芯片介绍(8080、8060)

MySQL explanation (II)

Mode pont

ES6 module

Chapter 01_ Installation and use of MySQL under Linux
随机推荐
Thinking caused by the error < note: candidate expectations 1 argument, 0 provided >
解中小企业之困,百度智能云打个样
scrapy——爬取漫画自定义存储路径下载到本地
MySQL数据库讲解(三)
Electron official docs series: Examples
HDU 5860
享元模式(Flyweight)
Composite mode
Electron official docs series: Contributing
装饰器(Decorator)
ES6 module
IDC报告:百度智能云AI Cloud市场份额连续六次第一
Arcpy - - utilisation de la fonction insertlayer (): ajout de calques dans un document de carte
Processsing function random
What should the software test report include? Interview must ask
HDU 3709 Balanced Number
MySQL explanation (I)
E - Apple Catching
Electron official docs series: Development
Electron official docs series: Get Started