UNPKG

1.76 kBPlain TextView Raw
1import { UnavailabilityError } from '@unimodules/core';
2
3import ExpoFaceDetector from './ExpoFaceDetector';
4
5type Point = { x: number; y: number };
6
7export type FaceFeature = {
8 bounds: {
9 size: {
10 width: number;
11 height: number;
12 };
13 origin: Point;
14 };
15 smilingProbability?: number;
16 leftEarPosition?: Point;
17 rightEarPosition?: Point;
18 leftEyePosition?: Point;
19 leftEyeOpenProbability?: number;
20 rightEyePosition?: Point;
21 rightEyeOpenProbability?: number;
22 leftCheekPosition?: Point;
23 rightCheekPosition?: Point;
24 leftMouthPosition?: Point;
25 mouthPosition?: Point;
26 rightMouthPosition?: Point;
27 bottomMouthPosition?: Point;
28 noseBasePosition?: Point;
29 yawAngle?: number;
30 rollAngle?: number;
31 faceID?: number;
32};
33
34type ValuesOf<T extends any[]> = T[number];
35
36export type FaceDetectorMode = string[];
37
38export type FaceDetectorLandmarks = ValuesOf<typeof ExpoFaceDetector.Landmarks>;
39
40export type FaceDetectorClassifications = ValuesOf<typeof ExpoFaceDetector.Classifications>;
41
42export interface Image {
43 uri: string;
44 width: number;
45 height: number;
46 orientation: number;
47}
48
49export type DetectionOptions = {
50 mode?: FaceDetectorMode;
51 detectLandmarks?: FaceDetectorLandmarks;
52 runClassifications?: FaceDetectorClassifications;
53};
54
55export async function detectFacesAsync(
56 uri: string,
57 options: DetectionOptions = {}
58): Promise<{ faces: FaceFeature[]; image: Image }> {
59 if (!ExpoFaceDetector.detectFaces) {
60 throw new UnavailabilityError('expo-face-detector', 'detectFaces');
61 }
62 return await ExpoFaceDetector.detectFaces({ ...options, uri });
63}
64
65export const Constants = {
66 Mode: ExpoFaceDetector.Mode,
67 Landmarks: ExpoFaceDetector.Landmarks,
68 Classifications: ExpoFaceDetector.Classifications,
69};