From 8c13670c13a7a965884d92193b039e26c96b95c6 Mon Sep 17 00:00:00 2001 From: Wu-cheng Li Date: Fri, 12 Aug 2011 20:25:00 +0800 Subject: Improve camera face detection javadoc. bug:4460717 Change-Id: I6e040911ce802e597e77dfdde1c92b75d51975c8 --- core/java/android/hardware/Camera.java | 43 ++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 7 deletions(-) diff --git a/core/java/android/hardware/Camera.java b/core/java/android/hardware/Camera.java index 3becec0189f9..c2a757f06808 100644 --- a/core/java/android/hardware/Camera.java +++ b/core/java/android/hardware/Camera.java @@ -1111,9 +1111,21 @@ public class Camera { * Parameters#getMaxNumDetectedFaces()} returns a number larger than 0. * If the face detection has started, apps should not call this again. * - * When the face detection is running, {@link Parameters#setWhiteBalance(String)}, + *

When the face detection is running, {@link Parameters#setWhiteBalance(String)}, * {@link Parameters#setFocusAreas(List)}, and {@link Parameters#setMeteringAreas(List)} - * have no effect. + * have no effect. The camera uses the detected faces to do auto-white balance, + * auto exposure, and autofocus. + * + *

If the apps call {@link #autoFocus(AutoFocusCallback)}, the camera + * will stop sending face callbacks. The last face callback indicates the + * areas used to do autofocus. After focus completes, face detection will + * resume sending face callbacks. If the apps call {@link + * #cancelAutoFocus()}, the face callbacks will also resume.

+ * + *

After calling {@link #takePicture(Camera.ShutterCallback, Camera.PictureCallback, + * Camera.PictureCallback)} or {@link #stopPreview()}, and then resuming + * preview with {@link #startPreview()}, the apps should call this method + * again to resume face detection.

* * @throws IllegalArgumentException if the face detection is unsupported. * @throws RuntimeException if the method fails or the face detection is @@ -1163,14 +1175,31 @@ public class Camera { * camera field of view, and (1000, 1000) represents the bottom-right of * the field of view. For example, suppose the size of the viewfinder UI * is 800x480. The rect passed from the driver is (-1000, -1000, 0, 0). - * The corresponding viewfinder rect should be (0, 0, 400, 240). The - * width and height of the rect will not be 0 or negative. The - * coordinates can be smaller than -1000 or bigger than 1000. But at - * least one vertex will be within (-1000, -1000) and (1000, 1000). + * The corresponding viewfinder rect should be (0, 0, 400, 240). It is + * guaranteed left < right and top < bottom. The coordinates can be + * smaller than -1000 or bigger than 1000. But at least one vertex will + * be within (-1000, -1000) and (1000, 1000). * *

The direction is relative to the sensor orientation, that is, what * the sensor sees. The direction is not affected by the rotation or - * mirroring of {@link #setDisplayOrientation(int)}.

+ * mirroring of {@link #setDisplayOrientation(int)}. The face bounding + * rectangle does not provide any information about face orientation.

+ * + *

Here is the matrix to convert driver coordinates to View coordinates + * in pixels.

+ *
+         * Matrix matrix = new Matrix();
+         * CameraInfo info = CameraHolder.instance().getCameraInfo()[cameraId];
+         * // Need mirror for front camera.
+         * boolean mirror = (info.facing == CameraInfo.CAMERA_FACING_FRONT);
+         * matrix.setScale(mirror ? -1 : 1, 1);
+         * // This is the value for android.hardware.Camera.setDisplayOrientation.
+         * matrix.postRotate(displayOrientation);
+         * // Camera driver coordinates range from (-1000, -1000) to (1000, 1000).
+         * // UI coordinates range from (0, 0) to (width, height).
+         * matrix.postScale(view.getWidth() / 2000f, view.getHeight() / 2000f);
+         * matrix.postTranslate(view.getWidth() / 2f, view.getHeight() / 2f);
+         * 
* * @see #startFaceDetection() */ -- cgit v1.2.3-59-g8ed1b