移动客户端人工智能

MediaPipe在Android端的接入手跟踪hand tra

2021-01-27  本文已影响0人  hjm1fb

完整Demo下载地址

In order to use MediaPipe on earlier Android versions, MediaPipe needs to switch
to a lower Android API level. You can achieve this by specifying `api_level =
$YOUR_INTENDED_API_LEVEL` in android_ndk_repository() and/or
android_sdk_repository() in the
[`WORKSPACE`](https://github.com/google/mediapipe/blob/master/WORKSPACE) file.
Note: To reduce the binary size, consider appending `--linkopt="-s"` to the
    command below to strip symbols.

用的版本是V0.8.2, 之前的版本内存管理不完善,在低端机上使用一段时间容易Crash.

  1. 进入目录
    cd /Users/xxx/StudioProjects/others/mediapipe-0.8.2
  2. 编译
bazel build -c opt --fat_apk_cpu=arm64-v8a,armeabi-v7a mediapipe/examples/android/src/java/com/google/mediapipe/apps/aar_example:mp_multi_hand_tracking_082.aar --linkopt="-s"
  1. 拷贝aar
cp bazel-bin/mediapipe/examples/android/src/java/com/google/mediapipe/apps/aar_example/mp_multi_hand_tracking_082.aar.aar /Users/xxx/StudioProjects/others/mediapipe-0.8.2/mediapipe/examples/android/src/java/com/google/mediapipe/apps/aar_example/mp_multi_hand_tracking_082.aar.aar 
  1. 生成binarypb文件
    bazel build -c opt //mediapipe/graphs/hand_tracking:hand_tracking_mobile_gpu_binary_graph
  2. 拷贝binarypb文件
cp bazel-bin/mediapipe/graphs/hand_tracking/hand_tracking_mobile_gpu.binarypb /Users/xxx/Desktop/hand_tracking_mobile_gpu.binarypb
  1. 拷贝其他文件
    参考
    mediapipe-0.8.2/mediapipe/examples/android/src/java/com/google/mediapipe/apps/handtrackinggpu/BUILD
    里的assets清单,拷贝
"//mediapipe/graphs/hand_tracking:hand_tracking_mobile_gpu.binarypb",
"//mediapipe/modules/hand_landmark:handedness.txt",
"//mediapipe/modules/hand_landmark:hand_landmark.tflite",
"//mediapipe/modules/palm_detection:palm_detection.tflite",

到asset文件夹

  1. 配置Manifest
       <meta-data android:name="cameraFacingFront" android:value="true"/>
       <meta-data android:name="binaryGraphName" android:value="hand_tracking_mobile_gpu.binarypb"/>
       <meta-data android:name="inputVideoStreamName" android:value="input_video"/>
       <meta-data android:name="outputVideoStreamName" android:value="output_video"/>
       <meta-data android:name="flipFramesVertically" android:value="true"/>
  1. 完整Demo下载地址
    我在索尼手机上测试此Demo,发现启动会黑屏,但点击home键后返回就好了。

Tip:
在线看模型的网址:https://netron.app/

上一篇下一篇

猜你喜欢

热点阅读