Created
January 3, 2022 16:09
-
-
Save IvanShafran/d1e2b41db8b604aa4540d136329c3b57 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Inside FaceDetectorProcessor.java | |
public class FaceDetectorProcessor extends VisionProcessorBase<List<Face>> { | |
public static class Emotion { | |
public final float smileProbability; | |
public final float leftEyeOpenProbability; | |
public final float rightEyeOpenProbability; | |
public Emotion(float smileProbability, float leftEyeOpenProbability, float rightEyeOpenProbability) { | |
this.smileProbability = smileProbability; | |
this.leftEyeOpenProbability = leftEyeOpenProbability; | |
this.rightEyeOpenProbability = rightEyeOpenProbability; | |
} | |
} | |
public interface EmotionListener { | |
void onEmotion(Emotion emotion); | |
} | |
private EmotionListener listener; | |
public void setListener(EmotionListener listener) { | |
this.listener = listener; | |
} | |
@Override | |
protected void onSuccess(@NonNull List<Face> faces, @NonNull GraphicOverlay graphicOverlay) { | |
if (!faces.isEmpty() && listener != null) { | |
Face face = faces.get(0); | |
if (face.getSmilingProbability() != null && | |
face.getLeftEyeOpenProbability() != null && face.getRightEyeOpenProbability() != null) { | |
listener.onEmotion(new Emotion( | |
face.getSmilingProbability(), | |
face.getLeftEyeOpenProbability(), | |
face.getRightEyeOpenProbability() | |
)); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment