Skip to content

Instantly share code, notes, and snippets.

@mcpotter
Last active October 16, 2017 03:46
Show Gist options
  • Save mcpotter/bad3f1e91ff3b35c459f37dbf4c3eec7 to your computer and use it in GitHub Desktop.
Save mcpotter/bad3f1e91ff3b35c459f37dbf4c3eec7 to your computer and use it in GitHub Desktop.
public void init() {
//...
for (int i = 0; i < numberOfCameras; i++) {
Camera.getCameraInfo(i, ci);
if (ci.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
isFrontFacing = true;
break;
}
}
//...
FaceDetector detector =
new FaceDetector
.Builder(context)
.setLandmarkType(FaceDetector.ALL_LANDMARKS)
.setClassificationType(FaceDetector.ALL_CLASSIFICATIONS)
.setTrackingEnabled(true)
.setMode(FaceDetector.FAST_MODE)
.setProminentFaceOnly(isFrontFacing)
.setMinFaceSize(isFrontFacing ? 0.35f : 0.15f)
.build();
Detector.Processor<Face> processor;
if (isFrontFacing) {
Tracker<Face> tracker = new FaceTracker(overlay);
processor =
new LargestFaceFocusingProcessor.Builder(detector, tracker).build();
} else {
MultiProcessor.Factory<Face> factory = face -> new FaceTracker(overlay);
processor = new MultiProcessor.Builder<>(factory).build();
}
detector.setProcessor(processor);
cameraSource =
new CameraSource
.Builder(context, detector)
.setFacing(facing)
.setRequestedPreviewSize(defaultWidth, defaultHeight)
.setRequestedFps(60.0f)
.setAutoFocusEnabled(true)
.build();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment