AI Marker recognition with Tensorflow Lite and CameraX
-
Downolad Landmark tflite model file from https://www.kaggle.com/models/google/landmarks/frameworks/tfLite in my case i have landmarks_classifier_africa
-
In Android studio, create asserts directory and add the tflite file there
-
Add gradle dependencies for CameraX and TenserFlow:
// CameraX core library using the camera2 implementation val cameraxVersion = "1.4.0-alpha03" implementation("androidx.camera:camera-core:${cameraxVersion}") implementation("androidx.camera:camera-camera2:${cameraxVersion}") implementation("androidx.camera:camera-lifecycle:${cameraxVersion}") implementation("androidx.camera:camera-video:${cameraxVersion}") implementation("androidx.camera:camera-view:${cameraxVersion}") implementation("androidx.camera:camera-extensions:${cameraxVersion}")
// Tensorflow Lite dependencies implementation("org.tensorflow:tensorflow-lite-task-vision:0.4.2") // Import the GPU delegate plugin Library for GPU inference implementation("org.tensorflow:tensorflow-lite-gpu-delegate-plugin:0.4.0") implementation("org.tensorflow:tensorflow-lite-gpu:2.9.0")
=> you could also use the tenserFlow dependencie integrated recently in play-service
-
In AndroidManifest, add camera permission:
<uses-feature android:name="android.hardware.camera" android:required="false" /> <uses-permission android:name="android.permission.CAMERA"/>
-
For UI, since
PreviewView
from CameraX is not available as composable yet, i wrapped inAndroidView
to create theCameraPreview