List of usage examples for android.media FaceDetector FaceDetector
public FaceDetector(int width, int height, int maxFaces)
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);/* w ww .j a va2 s. co m*/ FaceDetector.Face face = faces[0]; 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);/*from ww w . j a v a 2 s .c o m*/ FaceDetector.Face face = faces[0]; 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;/*from w w w. j a va 2s. c om*/ FaceDetector.Face[] faces = new FaceDetector.Face[MAX_FACES]; int count = 0; try { 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 av a 2 s. com } 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; }