Example usage for android.media FaceDetector findFaces

List of usage examples for android.media FaceDetector findFaces

Introduction

In this page you can find the example usage for android.media FaceDetector findFaces.

Prototype

public int findFaces(Bitmap bitmap, Face[] faces) 

Source Link

Document

Finds all the faces found in a given android.graphics.Bitmap .

Usage

From source file:Main.java

private static PointF findFaceMid(Bitmap in) {
    PointF mid = new PointF();
    Bitmap bitmap565 = in.copy(Bitmap.Config.RGB_565, true);

    FaceDetector fd = new FaceDetector(in.getWidth(), in.getHeight(), 1);
    FaceDetector.Face[] faces = new FaceDetector.Face[1];
    fd.findFaces(bitmap565, faces);

    FaceDetector.Face face = faces[0];/*  www .  j a  v a 2  s.  com*/
    if (face != null) {
        try {
            face.getMidPoint(mid);
            return mid;
        } catch (NullPointerException n) {
        }
    }
    return null;

}

From source file:Main.java

private static PointF findFaceMid(Bitmap in) {
    PointF mid = new PointF();
    Bitmap bitmap565 = in.copy(Bitmap.Config.RGB_565, true);

    FaceDetector fd = new FaceDetector(in.getWidth(), in.getHeight(), 1);
    FaceDetector.Face[] faces = new FaceDetector.Face[1];
    fd.findFaces(bitmap565, faces);

    FaceDetector.Face face = faces[0];/*from   w w  w  .  ja v a 2  s  . c om*/
    if (face != null) {
        try {
            face.getMidPoint(mid);
            return mid;
        } catch (NullPointerException n) {
            // FIXME please fix this horrible NPE catch block
            Log.e("Error", n.getLocalizedMessage());
        }
    }
    return null;

}

From source file:com.jwork.spycamera.CameraTaskService.java

public String getPrivacy(Bitmap sourceImage) {
    int MAX_FACES = 10;
    FaceDetector fd;
    FaceDetector.Face[] faces = new FaceDetector.Face[MAX_FACES];

    int count = 0;
    try {/*from  w  ww.  j a v a2s  .  c o m*/
        fd = new FaceDetector(sourceImage.getWidth(), sourceImage.getHeight(), MAX_FACES);
        count = fd.findFaces(sourceImage, faces);
    } catch (Exception e) {
        return null;
    }

    if (count == 0 || count > 1)
        return "Public";
    else
        return "Private";
}

From source file:uk.co.senab.photup.model.PhotoUpload.java

public void detectPhotoTags(final Bitmap originalBitmap) {
    // If we've already done Face detection, don't do it again...
    if (mCompletedDetection) {
        return;//from  w w  w.  j a  v a  2s  . c  o  m
    }

    final OnFaceDetectionListener listener = mFaceDetectListener.get();
    if (null != listener) {
        listener.onFaceDetectionStarted(this);
    }

    final int bitmapWidth = originalBitmap.getWidth();
    final int bitmapHeight = originalBitmap.getHeight();

    Bitmap bitmap = originalBitmap;

    // The Face detector only accepts 565 bitmaps, so create one if needed
    if (Bitmap.Config.RGB_565 != bitmap.getConfig()) {
        bitmap = originalBitmap.copy(Bitmap.Config.RGB_565, false);
    }

    final FaceDetector detector = new FaceDetector(bitmapWidth, bitmapHeight,
            Constants.FACE_DETECTOR_MAX_FACES);
    final FaceDetector.Face[] faces = new FaceDetector.Face[Constants.FACE_DETECTOR_MAX_FACES];
    final int detectedFaces = detector.findFaces(bitmap, faces);

    // We must have created a converted 565 bitmap
    if (bitmap != originalBitmap) {
        bitmap.recycle();
        bitmap = null;
    }

    if (Flags.DEBUG) {
        Log.d(LOG_TAG, "Detected Faces: " + detectedFaces);
    }

    FaceDetector.Face face;
    final PointF point = new PointF();
    for (int i = 0, z = faces.length; i < z; i++) {
        face = faces[i];
        if (null != face) {
            if (Flags.DEBUG) {
                Log.d(LOG_TAG, "Detected Face with confidence: " + face.confidence());
            }
            face.getMidPoint(point);
            addPhotoTag(new PhotoTag(point.x, point.y, bitmapWidth, bitmapWidth));
        }
    }

    if (null != listener) {
        listener.onFaceDetectionFinished(this);
    }
    mFaceDetectListener = null;

    mCompletedDetection = true;
}