1 |
|
2 |
|
3 | import { NativeModules } from 'react-native';
|
4 |
|
5 | const faceDetectionDisabledMessage = 'Face detection has not been included in this build.';
|
6 |
|
7 | const FaceDetectorModule: Object = NativeModules.ExpoFaceDetector || {
|
8 | stubbed: true,
|
9 | Mode: {},
|
10 | Landmarks: {},
|
11 | Classifications: {},
|
12 | detectFaces: () => new Promise((_, reject) => reject(faceDetectionDisabledMessage)),
|
13 | };
|
14 |
|
15 | type Point = { x: number, y: number };
|
16 |
|
17 | export type FaceFeature = {
|
18 | bounds: {
|
19 | size: {
|
20 | width: number,
|
21 | height: number,
|
22 | },
|
23 | origin: Point,
|
24 | },
|
25 | smilingProbability?: number,
|
26 | leftEarPosition?: Point,
|
27 | rightEarPosition?: Point,
|
28 | leftEyePosition?: Point,
|
29 | leftEyeOpenProbability?: number,
|
30 | rightEyePosition?: Point,
|
31 | rightEyeOpenProbability?: number,
|
32 | leftCheekPosition?: Point,
|
33 | rightCheekPosition?: Point,
|
34 | leftMouthPosition?: Point,
|
35 | mouthPosition?: Point,
|
36 | rightMouthPosition?: Point,
|
37 | bottomMouthPosition?: Point,
|
38 | noseBasePosition?: Point,
|
39 | yawAngle?: number,
|
40 | rollAngle?: number,
|
41 | };
|
42 |
|
43 | type DetectionOptions = {
|
44 | mode?: $Keys<typeof FaceDetectorModule.Mode>,
|
45 | detectLandmarks?: $Keys<typeof FaceDetectorModule.Landmarks>,
|
46 | runClassifications?: $Keys<typeof FaceDetectorModule.Classifications>,
|
47 | };
|
48 |
|
49 | export default class FaceDetector {
|
50 | static Constants = {
|
51 | Mode: FaceDetectorModule.Mode,
|
52 | Landmarks: FaceDetectorModule.Landmarks,
|
53 | Classifications: FaceDetectorModule.Classifications,
|
54 | };
|
55 |
|
56 | static detectFacesAsync(uri: string, options: ?DetectionOptions): Promise<Array<FaceFeature>> {
|
57 | return FaceDetectorModule.detectFaces({ ...options, uri });
|
58 | }
|
59 | }
|
60 |
|
61 | export const Constants = FaceDetector.Constants;
|