public static void prepareMatrix( android.graphics.Matrix matrix, boolean mirror, int viewWidth, int viewHeight) { // This is the value for android.hardware.Camera.setDisplayOrientation. // Camera driver coordinates range from (-1000, -1000) to (1000, 1000). // UI coordinates range from (0, 0) to (width, height). matrix.postScale(viewWidth / 2000f, viewHeight / 2000f); matrix.postTranslate(viewWidth / 2f, viewHeight / 2f); }
@Override public void onFaceDetection(Camera.Face[] faces, Camera camera) { RectF rectf = new RectF(); for (Camera.Face face : faces) { int centerX = face.rect.centerX(); int centerY = face.rect.centerY(); android.graphics.Matrix matrix = new android.graphics.Matrix(); // Width needs to be divided by 2 because the overlay is for both eyes: prepareMatrix(matrix, false, mOverlayView.getWidth() / 2, mOverlayView.getHeight()); rectf.set(face.rect); matrix.mapRect(rectf); mOverlayView.show3DRect((int) rectf.centerX(), (int) rectf.centerY()); mOverlayView.show3DToast("Found face! x = " + rectf.centerX() + ", y = " + rectf.centerY()); } }