Skip to content

Instantly share code, notes, and snippets.

@niusounds
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save niusounds/36120186d721de2a19f4 to your computer and use it in GitHub Desktop.

Select an option

Save niusounds/36120186d721de2a19f4 to your computer and use it in GitHub Desktop.
Camera.FaceDetectionListener
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