Skip to content

Commit

Permalink
Fix face detector settings not being applied on first run
Browse files Browse the repository at this point in the history
  • Loading branch information
sjchmiela committed Oct 10, 2018
1 parent 3e33c55 commit c0a24ea
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class ExpoCameraView extends CameraView implements LifecycleEventListener
// Scanning-related properties
private BarCodeScanner mBarCodeScanner;
private FaceDetector mFaceDetector;
private Map<String, Object> mPendingFaceDetectorSettings;
private boolean mShouldDetectFaces = false;
private boolean mShouldScanBarCodes = false;

Expand Down Expand Up @@ -270,6 +271,10 @@ public void onHostResume() {
FaceDetectorProvider faceDetectorProvider = mModuleRegistry.getModule(FaceDetectorProvider.class);
if (faceDetectorProvider != null) {
mFaceDetector = faceDetectorProvider.createFaceDetectorWithContext(getContext());
if (mPendingFaceDetectorSettings != null) {
mFaceDetector.setSettings(mPendingFaceDetectorSettings);
mPendingFaceDetectorSettings = null;
}
}
}
}
Expand Down Expand Up @@ -308,7 +313,9 @@ public void setShouldDetectFaces(boolean shouldDetectFaces) {
}

public void setFaceDetectorSettings(Map<String, Object> settings) {
if (mFaceDetector != null) {
if (mFaceDetector == null) {
mPendingFaceDetectorSettings = settings;
} else {
mFaceDetector.setSettings(settings);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
import java.util.Map;

public class ExpoFaceDetector implements expo.interfaces.facedetector.FaceDetector {
private static final String RUN_CLASSIFICATIONS_KEY = "runClassifications";
private static final String DETECT_LANDMARKS_KEY = "detectLandmarks";
private static final String TRACKING_KEY = "tracking";
private static final String MODE_KEY = "mode";

public static int ALL_CLASSIFICATIONS = FaceDetector.ALL_CLASSIFICATIONS;
public static int NO_CLASSIFICATIONS = FaceDetector.NO_CLASSIFICATIONS;
public static int ALL_LANDMARKS = FaceDetector.ALL_LANDMARKS;
Expand Down Expand Up @@ -85,10 +90,21 @@ public List<Bundle> detectFaces(byte[] imageData, int width, int height, int rot
}

public void setSettings(Map<String, Object> settings) {
setMode(((Number) settings.get("mode")).intValue());
setLandmarkType(((Number) settings.get("detectLandmarks")).intValue());
setTrackingEnabled((Boolean) settings.get("tracking"));
setClassificationType(((Number) settings.get("runClassifications")).intValue());
if (settings.get(MODE_KEY) instanceof Number) {
setMode(((Number) settings.get(MODE_KEY)).intValue());
}

if (settings.get(DETECT_LANDMARKS_KEY) instanceof Number) {
setLandmarkType(((Number) settings.get(DETECT_LANDMARKS_KEY)).intValue());
}

if (settings.get(TRACKING_KEY) instanceof Boolean) {
setTrackingEnabled((Boolean) settings.get(TRACKING_KEY));
}

if (settings.get(RUN_CLASSIFICATIONS_KEY) instanceof Number) {
setClassificationType(((Number) settings.get(RUN_CLASSIFICATIONS_KEY)).intValue());
}
}

public void setClassificationType(int classificationType) {
Expand Down

0 comments on commit c0a24ea

Please sign in to comment.