FileDocCategorySizeDatePackage
FaceDetector.javaAPI DocAndroid 1.5 API6872Wed May 06 22:42:00 BST 2009android.media

FaceDetector

public class FaceDetector extends Object
Identifies the faces of people in a {@link android.graphics.Bitmap} graphic object.

Fields Summary
private static boolean
sInitialized
private int
mFD
private int
mSDK
private int
mDCR
private int
mWidth
private int
mHeight
private int
mMaxFaces
private byte[]
mBWBuffer
Constructors Summary
public FaceDetector(int width, int height, int maxFaces)
Creates a FaceDetector, configured with the size of the images to be analysed and the maximum number of faces that can be detected. These parameters cannot be changed once the object is constructed.

param
width the width of the image
param
height the height of the image
param
maxFaces the maximum number of faces to identify

        if (!sInitialized) {
            return;
        }
        fft_initialize(width, height, maxFaces);
        mWidth = width;
        mHeight = height;
        mMaxFaces = maxFaces;
        mBWBuffer = new byte[width * height];
    
Methods Summary
private native voidfft_destroy()

private native intfft_detect(android.graphics.Bitmap bitmap)

private native voidfft_get_face(android.media.FaceDetector$Face face, int i)

private native intfft_initialize(int width, int height, int maxFaces)

protected voidfinalize()

        fft_destroy();
    
public intfindFaces(android.graphics.Bitmap bitmap, android.media.FaceDetector$Face[] faces)
Finds all the faces found in a given {@link android.graphics.Bitmap}. The supplied array is populated with {@link FaceDetector.Face}s for each face found. The bitmap must be in 565 format (for now).

param
bitmap the {@link android.graphics.Bitmap} graphic to be analyzed
param
faces an array in which to place all found {@link FaceDetector.Face}s. The array must be sized equal to the maxFaces value set at initialization
return
the number of faces found
throws
IllegalArgumentException if the Bitmap dimensions don't match the dimensions defined at initialization or the given array is not sized equal to the maxFaces value defined at initialization

        if (!sInitialized) {
            return 0;
        }
        if (bitmap.getWidth() != mWidth || bitmap.getHeight() != mHeight) {
            throw new IllegalArgumentException(
                    "bitmap size doesn't match initialization");
        }
        if (faces.length < mMaxFaces) {
            throw new IllegalArgumentException(
                    "faces[] smaller than maxFaces");
        }
        
        int numFaces = fft_detect(bitmap);
        if (numFaces >= mMaxFaces)
            numFaces = mMaxFaces;
        for (int i=0 ; i<numFaces ; i++) {
            if (faces[i] == null)
                faces[i] = new Face();
            fft_get_face(faces[i], i);
        }
        return numFaces;
    
private static native voidnativeClassInit()