当前位置:网站首页>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。
边栏推荐
- Map value
- F - Charm Bracelet
- System tasks (display / print class) in Verilog - $display, $write, $strobe, $monitor
- MariaDB study notes
- Beifu realizes the control of time slice size and quantity through CTU and ton
- Vivado error code [drc pdcn-2721] resolution
- Processing polyhedron change
- 装饰器(Decorator)
- Here Document免交互及Expect自动化交互
- Beifu cx5130 card replacement and transfer of existing authorization files
猜你喜欢
解中小企业之困,百度智能云打个样
Electron official docs series: Processes in Electron
Summary of wechat applet test points
Beifu realizes the control of time slice size and quantity through CTU and ton
10秒内完成火灾预警,百度智能云助力昆明官渡打造智慧城市新标杆
2、并行接口、协议和相关芯片介绍(8080、8060)
Chapter 10 setting up structured logging (2)
Vivado error code [drc pdcn-2721] resolution
享元模式(Flyweight)
【Spark】. Explanation of several icons of scala file in idea
随机推荐
QT . Establishment and use of pri
Explain C language 10 in detail (C language series)
sql 将数据表b字段值赋值到数据表a中某一列
HDU 3709 Balanced Number
tauri vs electron
H5视频自动播放和循环播放
May product upgrade observation station
Beifu PLC realizes data power-off maintenance based on cx5130
Map value
MySQL讲解(二)
Electron official docs series: Get Started
MySQL explanation (II)
Hdu1724[Simpson formula for integral]ellipse
C language: Exercise 2
[shell] generate strings between specified dates
To solve the difficulties of small and medium-sized enterprises, Baidu AI Cloud makes an example
Digital signal processing -- Design of linear phase type (Ⅰ, Ⅲ) FIR filter (1)
Design of four kinds of linear phase FIR filters -- complete set of Matlab source code
Mysql database explanation (6)
ES6:Map