I need a simple way of detecting faces in my Camera app. All I care about is a callback saying that a face was detected in certain place or with coordinates where it was detected on the preview. I've noticed that there seem to be several face detection APIs - in Google Play services and in both legacy and camera2 APIs. Which one should I use for the simple requirement described above?
The legacy version is older, and has much lower accuracy than the new Google Play services API.
The camera2 API depends upon face detection capabilities built into the camera hardware, so it isn't necessarily available on all devices. I have not done an exhaustive comparison, but I think that the accuracy is also lower than that of the new Google Play services API.
See this tutorial for using the Google Play services API for tracking faces in the camera preview:
https://developers.google.com/vision/face-tracker-tutorial
The callback that you'd define would be a subclass of Tracker, similar to the GraphicFaceTracker in the tutorial.
If you don't need to track faces or you have other code that manages the camera, you can call the face detector directly like this:
Frame frame = Frame.Builder().setBitmap(myBitmap).build();
SparseArray<Face> faces = faceDetector.detect(frame);
See for information here:
https://developers.google.com/android/reference/com/google/android/gms/vision/package-summary
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With