android.media.FaceDetector.Face Java Examples
The following examples show how to use
android.media.FaceDetector.Face.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CameraSurfaceView.java From Android-Screen-to-Face-Distance-Measurement with MIT License | 5 votes |
private void updateMeasurement(final FaceDetector.Face currentFace) { if (currentFace == null) { // _facesFoundInMeasurement--; return; } _foundFace = _currentFaceDetectionThread.getCurrentFace(); _points.add(new Point(_foundFace.eyesDistance(), CALIBRATION_DISTANCE_A4_MM * (_distanceAtCalibrationPoint / _foundFace .eyesDistance()))); while (_points.size() > _threashold) { _points.remove(0); } float sum = 0; for (Point p : _points) { sum += p.getEyeDistance(); } _currentAvgEyeDistance = sum / _points.size(); _currentDistanceToFace = CALIBRATION_DISTANCE_A4_MM * (_distanceAtCalibrationPoint / _currentAvgEyeDistance); _currentDistanceToFace = Util.MM_TO_CM(_currentDistanceToFace); MeasurementStepMessage message = new MeasurementStepMessage(); message.setConfidence(currentFace.confidence()); message.setCurrentAvgEyeDistance(_currentAvgEyeDistance); message.setDistToFace(_currentDistanceToFace); message.setEyesDistance(currentFace.eyesDistance()); message.setMeasurementsLeft(_calibrationsLeft); message.setProcessTimeForLastFrame(_processTimeForLastFrame); MessageHUB.get().sendMessage(MessageHUB.MEASUREMENT_STEP, message); }
Example #2
Source File: FaceDetectionThread.java From Android-Screen-to-Face-Distance-Measurement with MIT License | 4 votes |
public Face getCurrentFace() { return _currentFace; }
Example #3
Source File: FaceDetectionThread.java From Android-Screen-to-Face-Distance-Measurement with MIT License | 4 votes |
/** * bla bla bla */ @Override public void run() { long t = System.currentTimeMillis(); YuvImage yuvimage = new YuvImage(_data, ImageFormat.NV21, _previewSize.width, _previewSize.height, null); ByteArrayOutputStream baos = new ByteArrayOutputStream(); if (!yuvimage.compressToJpeg(new Rect(0, 0, _previewSize.width, _previewSize.height), 100, baos)) { Log.e("Camera", "compressToJpeg failed"); } Log.i("Timing", "Compression finished: " + (System.currentTimeMillis() - t)); t = System.currentTimeMillis(); BitmapFactory.Options bfo = new BitmapFactory.Options(); bfo.inPreferredConfig = Bitmap.Config.RGB_565; _currentFrame = BitmapFactory.decodeStream(new ByteArrayInputStream( baos.toByteArray()), null, bfo); Log.i("Timing", "Decode Finished: " + (System.currentTimeMillis() - t)); t = System.currentTimeMillis(); // Rotate the so it siuts our portrait mode Matrix matrix = new Matrix(); matrix.postRotate(90); matrix.preScale(-1, 1); // We rotate the same Bitmap _currentFrame = Bitmap.createBitmap(_currentFrame, 0, 0, _previewSize.width, _previewSize.height, matrix, false); Log.i("Timing", "Rotate, Create finished: " + (System.currentTimeMillis() - t)); t = System.currentTimeMillis(); if (_currentFrame == null) { Log.e(FACEDETECTIONTHREAD_TAG, "Could not decode Image"); return; } FaceDetector d = new FaceDetector(_currentFrame.getWidth(), _currentFrame.getHeight(), 1); Face[] faces = new Face[1]; d.findFaces(_currentFrame, faces); Log.i("Timing", "FaceDetection finished: " + (System.currentTimeMillis() - t)); t = System.currentTimeMillis(); _currentFace = faces[0]; Log.d(FACEDETECTIONTHREAD_TAG, "Found: " + faces[0] + " Faces"); }
Example #4
Source File: MasaccioImageView.java From Masaccio with Apache License 2.0 | 3 votes |
public void setFaces(final Face[] faces) { if ((faces != null) && (faces.length > 0)) { mDetectedFaces = faces; } else { mDetectedFaces = null; } applyCrop(); }
Example #5
Source File: MasaccioImageView.java From Masaccio with Apache License 2.0 | 2 votes |
private void getFaceOffsets(final Face[] faces, final float[] offsets, final float scaleFactor, final float width, final float height, final float maxOffsetX, final float maxOffsetY) { try { Face bestFace = null; float maxConfidence = 0; for (final Face face : faces) { final float faceConfidence = face.confidence(); if (faceConfidence > maxConfidence) { maxConfidence = faceConfidence; bestFace = face; } } if (bestFace == null) { getDefaultOffsets(offsets, maxOffsetX, maxOffsetY); return; } final PointF midPoint = new PointF(); bestFace.getMidPoint(midPoint); final float scaledOffsetX = (midPoint.x * scaleFactor) - ((width - maxOffsetX) * FACE_POSITION_RATIO_X); final float scaledOffsetY = (midPoint.y * scaleFactor) - ((height - maxOffsetY) * FACE_POSITION_RATIO_Y); if (Math.round(maxOffsetX) >= 0) { offsets[0] = Math.min(Math.max(0, scaledOffsetX), maxOffsetX); } else { offsets[0] = scaledOffsetX; } if (Math.round(maxOffsetY) >= 0) { offsets[1] = Math.min(Math.max(0, scaledOffsetY), maxOffsetY); } else { offsets[1] = scaledOffsetY; } } catch (final Exception e) { getDefaultOffsets(offsets, maxOffsetX, maxOffsetY); } }
Example #6
Source File: MasaccioImageView.java From Masaccio with Apache License 2.0 | 2 votes |
@Override public Face[] process(final Bitmap bitmap) { final Map<Bitmap, Face[]> facesMap = mFacesMap; final Face[] preProcessed = facesMap.get(bitmap); if (preProcessed != null) { if (preProcessed == NO_FACES) { return null; } return preProcessed; } final Face[] faces = new Face[MAX_FACES]; final Bitmap bitmap565 = convertTo565(bitmap); if (bitmap565 != null) { final FaceDetector faceDetector = new FaceDetector(bitmap565.getWidth(), bitmap565.getHeight(), MAX_FACES); final int faceCount = faceDetector.findFaces(bitmap565, faces); if (faceCount > 0) { final Face[] detected = new Face[faceCount]; System.arraycopy(faces, 0, detected, 0, faceCount); facesMap.put(bitmap, detected); return detected; } } facesMap.put(bitmap, NO_FACES); return null; }
Example #7
Source File: MasaccioImageView.java From Masaccio with Apache License 2.0 | 2 votes |
private Face[] getFaces(final Bitmap bitmap) { return mFacesMap.get(bitmap); }
Example #8
Source File: MasaccioImageView.java From Masaccio with Apache License 2.0 | votes |
public Face[] process(Bitmap bitmap);