From 1922205a82d277defc7d79db510c5b7862800a8e Mon Sep 17 00:00:00 2001 From: Sanjan Hegde <41730488+SanjanHegde@users.noreply.github.com> Date: Mon, 25 Mar 2024 22:09:51 +0530 Subject: [PATCH] Fixing Android application throwing an error of no value if no face is detected in any frame. (#287) * Fixing Android application throwing an error of no value if no face is detected in a video frame. * Added tag string. * Added the check to see if faceBlendshapes is Present for the frame and removed the generic try and catch block. * Log info correction --- .../fragment/FaceBlendshapesResultAdapter.kt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/face_landmarker/android/app/src/main/java/com/google/mediapipe/examples/facelandmarker/fragment/FaceBlendshapesResultAdapter.kt b/examples/face_landmarker/android/app/src/main/java/com/google/mediapipe/examples/facelandmarker/fragment/FaceBlendshapesResultAdapter.kt index afacfc74..ea7635aa 100644 --- a/examples/face_landmarker/android/app/src/main/java/com/google/mediapipe/examples/facelandmarker/fragment/FaceBlendshapesResultAdapter.kt +++ b/examples/face_landmarker/android/app/src/main/java/com/google/mediapipe/examples/facelandmarker/fragment/FaceBlendshapesResultAdapter.kt @@ -33,12 +33,18 @@ class FaceBlendshapesResultAdapter : fun updateResults(faceLandmarkerResult: FaceLandmarkerResult? = null) { categories = MutableList(52) { null } - if (faceLandmarkerResult != null) { - val sortedCategories = faceLandmarkerResult.faceBlendshapes().get()[0].sortedBy { -it.score() } + if (faceLandmarkerResult != null && faceLandmarkerResult.faceBlendshapes().isPresent) { + val faceBlendshapes = faceLandmarkerResult.faceBlendshapes().get() + val sortedCategories = faceBlendshapes[0].sortedByDescending { it.score() } val min = kotlin.math.min(sortedCategories.size, categories.size) for (i in 0 until min) { categories[i] = sortedCategories[i] } + } else { + Log.v( + "FaceBlendshapesResultAdapter", + "FaceLandmarkerResult is null or faceBlendshapes has no value is present for this frame" + ) } }