This is an app that uses MediaPipe's Hands model to detect the hand parts in the frames seen by your device's camera. These instructions walk you through building and running the demo on an Android device. Camera captures are discarded immediately after use, nothing is stored or saved.
-
If you don't have it already, install Android Studio 4.1 or later, following the instructions on the website.
-
Android device and Android development environment with minimum API 21.
-
Open Android Studio, and from the
Welcome
screen, selectOpen an existing Android Studio project
. -
From the
Open File or Project
window that appears, navigate to and select themediapipe-demo-hand-detection
directory from wherever you cloned the Supreme Tech sample GitHub repo. ClickOK
. -
If it asks you to do a
Gradle Sync
, clickOK
. -
You may also need to install various platforms and tools, if you get errors like
Failed to find target with hash string 'android-21'
and similar. Click theRun
button (the green arrow) or selectRun
>Run 'android'
from the top menu. You may need to rebuild the project usingBuild
>Rebuild Project
. -
If it asks you to use
Instant Run
, clickProceed Without Instant Run
. -
Also, you need to have an Android device plugged in with developer options enabled at this point. See here for more details on setting up developer devices.
Hand detection logic is implemented in classes inside the package vn.supremetech.examples.handdetection
. Follow these steps to integrate the model into your own app.
-
Copy the TFLite models (
palm_detection.tflite
andhand_landmark.tflite
) to your app'sassests
folder. -
Add these dependencies to your app's
build.gradle
file:implementation 'org.tensorflow:tensorflow-lite-support:0.2.0'
implementation 'org.tensorflow:tensorflow-lite-gpu:2.5.0'
-
Copy all files under the
vn.supremetech.examples.handdetection.handlandmark
package to your app. -
Initialize a hand detector instance:
val detector = HandDetector.create(this)
- Detect hand landmarks:
val landmarks = detector.process(bitmap)
// Do something with the landmarks
- Close the hand detector once completed:
detector.close()
Downloading, extraction and placement in assets folder has been managed
automatically by download.gradle
.
If you explicitly want to download the model, you can download it from here:
Please do not delete the assets folder content. If you explicitly deleted the
files, then please choose Build
> Rebuild
from menu to re-download the
deleted model files into assets folder.