Last active
August 29, 2015 14:06
-
-
Save niusounds/36120186d721de2a19f4 to your computer and use it in GitHub Desktop.
Camera.FaceDetectionListener
This file contains hidden or 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
| public class MyFaceDetectionListener implements Camera.FaceDetectionListener { | |
| private Matrix m = new Matrix(); | |
| private RectF rect = new RectF(); | |
| // Call this before startFaceDetection(). | |
| // targetWidth and targetHeight are usually size of view which shows camera preview. | |
| public void setup(boolean useFrontCamera, int displayOrientation, float targetWidth, float targetHeight) { | |
| m.setScale(useFrontCamera ? -1 : 1, 1); | |
| m.postRotate(displayOrientation); | |
| m.postTranslate(1000, 1000); | |
| m.postScale(targetWidth / 2000f, targetHeight / 2000f); | |
| } | |
| @Override | |
| public void onFaceDetection(Camera.Face[] faces, Camera camera) { | |
| for (Camera.Face face : faces) { | |
| rect.set(face.rect); | |
| m.mapRect(rect); | |
| processFace(rect); | |
| } | |
| } | |
| public void processFace(RectF rect) { | |
| // Do something with rect. | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment