vision-camera-face-detection 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +33 -0
  3. package/VisionCameraFaceDetection.podspec +45 -0
  4. package/android/build.gradle +106 -0
  5. package/android/gradle.properties +6 -0
  6. package/android/src/main/AndroidManifest.xml +3 -0
  7. package/android/src/main/AndroidManifestNew.xml +2 -0
  8. package/android/src/main/java/com/visioncamerafacedetection/FaceHelper.kt +112 -0
  9. package/android/src/main/java/com/visioncamerafacedetection/VisionCameraFaceDetectionModule.kt +118 -0
  10. package/android/src/main/java/com/visioncamerafacedetection/VisionCameraFaceDetectionPackage.kt +25 -0
  11. package/android/src/main/java/com/visioncamerafacedetection/VisionCameraFaceDetectionPlugin.kt +359 -0
  12. package/ios/FaceHelper.swift +238 -0
  13. package/ios/VisionCameraFaceDetection-Bridging-Header.h +6 -0
  14. package/ios/VisionCameraFaceDetectionModule.mm +19 -0
  15. package/ios/VisionCameraFaceDetectionModule.swift +105 -0
  16. package/ios/VisionCameraFaceDetectionPlugin.mm +22 -0
  17. package/ios/VisionCameraFaceDetectionPlugin.swift +341 -0
  18. package/lib/commonjs/Camera.cjs +161 -0
  19. package/lib/commonjs/Camera.cjs.map +1 -0
  20. package/lib/commonjs/FaceDetector.cjs +42 -0
  21. package/lib/commonjs/FaceDetector.cjs.map +1 -0
  22. package/lib/commonjs/Tensor.cjs +24 -0
  23. package/lib/commonjs/Tensor.cjs.map +1 -0
  24. package/lib/commonjs/index.cjs +39 -0
  25. package/lib/commonjs/index.cjs.map +1 -0
  26. package/lib/module/Camera.mjs +158 -0
  27. package/lib/module/Camera.mjs.map +1 -0
  28. package/lib/module/FaceDetector.mjs +36 -0
  29. package/lib/module/FaceDetector.mjs.map +1 -0
  30. package/lib/module/Tensor.mjs +17 -0
  31. package/lib/module/Tensor.mjs.map +1 -0
  32. package/lib/module/index.mjs +4 -0
  33. package/lib/module/index.mjs.map +1 -0
  34. package/lib/typescript/src/Camera.d.ts +17 -0
  35. package/lib/typescript/src/Camera.d.ts.map +1 -0
  36. package/lib/typescript/src/FaceDetector.d.ts +118 -0
  37. package/lib/typescript/src/FaceDetector.d.ts.map +1 -0
  38. package/lib/typescript/src/Tensor.d.ts +3 -0
  39. package/lib/typescript/src/Tensor.d.ts.map +1 -0
  40. package/lib/typescript/src/index.d.ts +4 -0
  41. package/lib/typescript/src/index.d.ts.map +1 -0
  42. package/package.json +186 -0
  43. package/src/Camera.tsx +192 -0
  44. package/src/FaceDetector.ts +161 -0
  45. package/src/Tensor.ts +27 -0
  46. package/src/index.tsx +3 -0
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.detectFromBase64 = detectFromBase64;
7
+ exports.initTensor = initTensor;
8
+ var _reactNative = require("react-native");
9
+ const LINKING_ERROR = `The package 'vision-camera-face-detection' doesn't seem to be linked. Make sure: \n\n` + _reactNative.Platform.select({
10
+ ios: "- You have run 'pod install'\n",
11
+ default: ''
12
+ }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
13
+ const VisionCameraFaceDetectionModule = _reactNative.NativeModules.VisionCameraFaceDetectionModule ? _reactNative.NativeModules.VisionCameraFaceDetectionModule : new Proxy({}, {
14
+ get() {
15
+ throw new Error(LINKING_ERROR);
16
+ }
17
+ });
18
+ function initTensor(modelPath, count) {
19
+ return VisionCameraFaceDetectionModule.initTensor(modelPath, count);
20
+ }
21
+ function detectFromBase64(imageString) {
22
+ return VisionCameraFaceDetectionModule.detectFromBase64(imageString);
23
+ }
24
+ //# sourceMappingURL=Tensor.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","LINKING_ERROR","Platform","select","ios","default","VisionCameraFaceDetectionModule","NativeModules","Proxy","get","Error","initTensor","modelPath","count","detectFromBase64","imageString"],"sourceRoot":"../../src","sources":["Tensor.ts"],"mappings":";;;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA,MAAMC,aAAa,GACjB,uFAAuF,GACvFC,qBAAQ,CAACC,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,+BAA+B,GACnCC,0BAAa,CAACD,+BAA+B,GACzCC,0BAAa,CAACD,+BAA+B,GAC7C,IAAIE,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACT,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAEA,SAASU,UAAUA,CAACC,SAAiB,EAAEC,KAAc,EAAmB;EAC7E,OAAOP,+BAA+B,CAACK,UAAU,CAACC,SAAS,EAAEC,KAAK,CAAC;AACrE;AAEO,SAASC,gBAAgBA,CAACC,WAAmB,EAAgB;EAClE,OAAOT,+BAA+B,CAACQ,gBAAgB,CAACC,WAAW,CAAC;AACtE","ignoreList":[]}
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _Camera = require("./Camera.cjs");
7
+ Object.keys(_Camera).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _Camera[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _Camera[key];
14
+ }
15
+ });
16
+ });
17
+ var _FaceDetector = require("./FaceDetector.cjs");
18
+ Object.keys(_FaceDetector).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _FaceDetector[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _FaceDetector[key];
25
+ }
26
+ });
27
+ });
28
+ var _Tensor = require("./Tensor.cjs");
29
+ Object.keys(_Tensor).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _Tensor[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _Tensor[key];
36
+ }
37
+ });
38
+ });
39
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_Camera","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_FaceDetector","_Tensor"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,OAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,OAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,OAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,aAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,aAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,aAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,aAAA,CAAAL,GAAA;IAAA;EAAA;AAAA;AACA,IAAAM,OAAA,GAAAV,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAQ,OAAA,EAAAP,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAM,OAAA,CAAAN,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAE,OAAA,CAAAN,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
@@ -0,0 +1,158 @@
1
+ import React from 'react';
2
+ import { Camera as VisionCamera,
3
+ // runAsync,
4
+ useFrameProcessor } from 'react-native-vision-camera';
5
+ import { Worklets,
6
+ // useRunOnJS,
7
+ useSharedValue } from 'react-native-worklets-core';
8
+ import { useFaceDetector } from "./FaceDetector.mjs";
9
+
10
+ // types
11
+ import { jsx as _jsx } from "react/jsx-runtime";
12
+ /**
13
+ * Create a Worklet function that persists between re-renders.
14
+ * The returned function can be called from both a Worklet context and the JS context, but will execute on a Worklet context.
15
+ *
16
+ * @param {function} func The Worklet. Must be marked with the `'worklet'` directive.
17
+ * @param {DependencyList} dependencyList The React dependencies of this Worklet.
18
+ * @returns {UseWorkletType} A memoized Worklet
19
+ */
20
+ function useWorklet(func, dependencyList) {
21
+ const worklet = React.useMemo(() => {
22
+ const context = Worklets.defaultContext;
23
+ return context.createRunAsync(func);
24
+ // eslint-disable-next-line react-hooks/exhaustive-deps
25
+ }, dependencyList);
26
+ return worklet;
27
+ }
28
+
29
+ /**
30
+ * Create a Worklet function that runs the giver function on JS context.
31
+ * The returned function can be called from a Worklet to hop back to the JS thread.
32
+ *
33
+ * @param {function} func The Worklet. Must be marked with the `'worklet'` directive.
34
+ * @param {DependencyList} dependencyList The React dependencies of this Worklet.
35
+ * @returns {UseRunInJSType} a memoized Worklet
36
+ */
37
+ function useRunInJS(func, dependencyList) {
38
+ // eslint-disable-next-line react-hooks/exhaustive-deps
39
+ return React.useMemo(() => Worklets.createRunOnJS(func), dependencyList);
40
+ }
41
+
42
+ /**
43
+ * Vision camera wrapper
44
+ *
45
+ * @param {ComponentType} props Camera + face detection props
46
+ * @returns
47
+ */
48
+ export const Camera = /*#__PURE__*/React.forwardRef(({
49
+ faceDetectionOptions,
50
+ faceDetectionCallback,
51
+ ...props
52
+ }, ref) => {
53
+ const {
54
+ detectFaces
55
+ } = useFaceDetector(faceDetectionOptions);
56
+ /**
57
+ * Is there an async task already running?
58
+ */
59
+ const isAsyncContextBusy = useSharedValue(false);
60
+
61
+ /**
62
+ * Throws logs/errors back on js thread
63
+ */
64
+ const logOnJs = Worklets.createRunOnJS((log, error) => {
65
+ if (error) {
66
+ console.error(log, error.message ?? JSON.stringify(error));
67
+ } else {
68
+ console.log(log);
69
+ }
70
+ });
71
+
72
+ /**
73
+ * Runs on detection callback on js thread
74
+ */
75
+ const runOnJs = useRunInJS(faceDetectionCallback, [faceDetectionCallback]);
76
+
77
+ /**
78
+ * Async context that will handle face detection
79
+ */
80
+ const runOnAsyncContext = useWorklet(frame => {
81
+ 'worklet';
82
+
83
+ try {
84
+ const faces = detectFaces(frame);
85
+ // increment frame count so we can use frame on
86
+ // js side without frame processor getting stuck
87
+ frame.incrementRefCount();
88
+ runOnJs(faces, frame).finally(() => {
89
+ 'worklet';
90
+
91
+ // finally decrement frame count so it can be dropped
92
+ frame.decrementRefCount();
93
+ });
94
+ } catch (error) {
95
+ logOnJs('Execution error:', error);
96
+ } finally {
97
+ frame.decrementRefCount();
98
+ isAsyncContextBusy.value = false;
99
+ }
100
+ }, [detectFaces, runOnJs]);
101
+
102
+ /**
103
+ * Detect faces on frame on an async context without blocking camera preview
104
+ *
105
+ * @param {Frame} frame Current frame
106
+ */
107
+ function runAsync(frame) {
108
+ 'worklet';
109
+
110
+ if (isAsyncContextBusy.value) return;
111
+ // set async context as busy
112
+ isAsyncContextBusy.value = true;
113
+ // cast to internal frame and increment ref count
114
+ const internal = frame;
115
+ internal.incrementRefCount();
116
+ // detect faces in async context
117
+ runOnAsyncContext(internal);
118
+ }
119
+
120
+ /**
121
+ * Camera frame processor
122
+ */
123
+ const cameraFrameProcessor = useFrameProcessor(frame => {
124
+ 'worklet';
125
+
126
+ runAsync(frame);
127
+ }, [runOnAsyncContext]);
128
+
129
+ //
130
+ // use bellow when vision-camera's
131
+ // context creation issue is solved
132
+ //
133
+ // /**
134
+ // * Runs on detection callback on js thread
135
+ // */
136
+ // const runOnJs = useRunOnJS( faceDetectionCallback, [
137
+ // faceDetectionCallback
138
+ // ] )
139
+
140
+ // const cameraFrameProcessor = useFrameProcessor( ( frame ) => {
141
+ // 'worklet'
142
+ // runAsync( frame, () => {
143
+ // 'worklet'
144
+ // runOnJs(
145
+ // detectFaces( frame ),
146
+ // frame
147
+ // )
148
+ // } )
149
+ // }, [ runOnJs ] )
150
+
151
+ return /*#__PURE__*/_jsx(VisionCamera, {
152
+ ...props,
153
+ ref: ref,
154
+ frameProcessor: cameraFrameProcessor,
155
+ pixelFormat: "yuv"
156
+ });
157
+ });
158
+ //# sourceMappingURL=Camera.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","Camera","VisionCamera","useFrameProcessor","Worklets","useSharedValue","useFaceDetector","jsx","_jsx","useWorklet","func","dependencyList","worklet","useMemo","context","defaultContext","createRunAsync","useRunInJS","createRunOnJS","forwardRef","faceDetectionOptions","faceDetectionCallback","props","ref","detectFaces","isAsyncContextBusy","logOnJs","log","error","console","message","JSON","stringify","runOnJs","runOnAsyncContext","frame","faces","incrementRefCount","finally","decrementRefCount","value","runAsync","internal","cameraFrameProcessor","frameProcessor","pixelFormat"],"sourceRoot":"../../src","sources":["Camera.tsx"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SACEC,MAAM,IAAIC,YAAY;AACtB;AACAC,iBAAiB,QACZ,4BAA4B;AACnC,SACEC,QAAQ;AACR;AACAC,cAAc,QACT,4BAA4B;AACnC,SAASC,eAAe,QAAQ,oBAAgB;;AAEhD;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAuBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,UAAUA,CACjBC,IAAoC,EACpCC,cAA8B,EACd;EAChB,MAAM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,36 @@
1
+ import { useMemo } from 'react';
2
+ import { VisionCameraProxy } from 'react-native-vision-camera';
3
+ /**
4
+ * Create a new instance of face detector plugin
5
+ *
6
+ * @param {FaceDetectionOptions | undefined} options Detection options
7
+ * @returns {FaceDetectorPlugin} Plugin instance
8
+ */
9
+ function createFaceDetectorPlugin(options) {
10
+ const plugin = VisionCameraProxy.initFrameProcessorPlugin('detectFaces', {
11
+ ...options
12
+ });
13
+ if (!plugin) {
14
+ throw new Error('Failed to load Frame Processor Plugin "detectFaces"!');
15
+ }
16
+ return {
17
+ detectFaces: frame => {
18
+ 'worklet';
19
+
20
+ // @ts-ignore
21
+ return plugin.call(frame);
22
+ }
23
+ };
24
+ }
25
+
26
+ /**
27
+ * Use an instance of face detector plugin.
28
+ *
29
+ * @param {FaceDetectionOptions | undefined} options Detection options
30
+ * @returns {FaceDetectorPlugin} Memoized plugin instance that will be
31
+ * destroyed once the component using `useFaceDetector()` unmounts.
32
+ */
33
+ export function useFaceDetector(options) {
34
+ return useMemo(() => createFaceDetectorPlugin(options), [options]);
35
+ }
36
+ //# sourceMappingURL=FaceDetector.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useMemo","VisionCameraProxy","createFaceDetectorPlugin","options","plugin","initFrameProcessorPlugin","Error","detectFaces","frame","call","useFaceDetector"],"sourceRoot":"../../src","sources":["FaceDetector.ts"],"mappings":"AAAA,SAASA,OAAO,QAAQ,OAAO;AAC/B,SAASC,iBAAiB,QAAoB,4BAA4B;AA0H1E;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,wBAAwBA,CAC/BC,OAA8B,EACV;EACpB,MAAMC,MAAM,GAAGH,iBAAiB,CAACI,wBAAwB,CAAC,aAAa,EAAE;IACvE,GAAGF;EACL,CAAC,CAAC;EAEF,IAAI,CAACC,MAAM,EAAE;IACX,MAAM,IAAIE,KAAK,CAAC,sDAAsD,CAAC;EACzE;EAEA,OAAO;IACLC,WAAW,EAAGC,KAAY,IAAa;MACrC,SAAS;;MACT;MACA,OAAOJ,MAAM,CAACK,IAAI,CAACD,KAAK,CAAC;IAC3B;EACF,CAAC;AACH;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,eAAeA,CAC7BP,OAA8B,EACV;EACpB,OAAOH,OAAO,CAAC,MAAME,wBAAwB,CAACC,OAAO,CAAC,EAAE,CAACA,OAAO,CAAC,CAAC;AACpE","ignoreList":[]}
@@ -0,0 +1,17 @@
1
+ import { NativeModules, Platform } from 'react-native';
2
+ const LINKING_ERROR = `The package 'vision-camera-face-detection' doesn't seem to be linked. Make sure: \n\n` + Platform.select({
3
+ ios: "- You have run 'pod install'\n",
4
+ default: ''
5
+ }) + '- You rebuilt the app after installing the package\n' + '- You are not using Expo Go\n';
6
+ const VisionCameraFaceDetectionModule = NativeModules.VisionCameraFaceDetectionModule ? NativeModules.VisionCameraFaceDetectionModule : new Proxy({}, {
7
+ get() {
8
+ throw new Error(LINKING_ERROR);
9
+ }
10
+ });
11
+ export function initTensor(modelPath, count) {
12
+ return VisionCameraFaceDetectionModule.initTensor(modelPath, count);
13
+ }
14
+ export function detectFromBase64(imageString) {
15
+ return VisionCameraFaceDetectionModule.detectFromBase64(imageString);
16
+ }
17
+ //# sourceMappingURL=Tensor.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NativeModules","Platform","LINKING_ERROR","select","ios","default","VisionCameraFaceDetectionModule","Proxy","get","Error","initTensor","modelPath","count","detectFromBase64","imageString"],"sourceRoot":"../../src","sources":["Tensor.ts"],"mappings":"AAAA,SAASA,aAAa,EAAEC,QAAQ,QAAQ,cAAc;AAEtD,MAAMC,aAAa,GACjB,uFAAuF,GACvFD,QAAQ,CAACE,MAAM,CAAC;EAAEC,GAAG,EAAE,gCAAgC;EAAEC,OAAO,EAAE;AAAG,CAAC,CAAC,GACvE,sDAAsD,GACtD,+BAA+B;AAEjC,MAAMC,+BAA+B,GACnCN,aAAa,CAACM,+BAA+B,GACzCN,aAAa,CAACM,+BAA+B,GAC7C,IAAIC,KAAK,CACP,CAAC,CAAC,EACF;EACEC,GAAGA,CAAA,EAAG;IACJ,MAAM,IAAIC,KAAK,CAACP,aAAa,CAAC;EAChC;AACF,CACF,CAAC;AAEP,OAAO,SAASQ,UAAUA,CAACC,SAAiB,EAAEC,KAAc,EAAmB;EAC7E,OAAON,+BAA+B,CAACI,UAAU,CAACC,SAAS,EAAEC,KAAK,CAAC;AACrE;AAEA,OAAO,SAASC,gBAAgBA,CAACC,WAAmB,EAAgB;EAClE,OAAOR,+BAA+B,CAACO,gBAAgB,CAACC,WAAW,CAAC;AACtE","ignoreList":[]}
@@ -0,0 +1,4 @@
1
+ export * from "./Camera.mjs";
2
+ export * from "./FaceDetector.mjs";
3
+ export * from "./Tensor.mjs";
4
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":"AAAA,cAAc,cAAU;AACxB,cAAc,oBAAgB;AAC9B,cAAc,cAAU","ignoreList":[]}
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import { Camera as VisionCamera } from 'react-native-vision-camera';
3
+ import type { CameraProps, Frame } from 'react-native-vision-camera';
4
+ import type { Face, FaceDetectionOptions } from './FaceDetector';
5
+ type CallbackType = (faces: Face[], frame: Frame) => void | Promise<void>;
6
+ /**
7
+ * Vision camera wrapper
8
+ *
9
+ * @param {ComponentType} props Camera + face detection props
10
+ * @returns
11
+ */
12
+ export declare const Camera: React.ForwardRefExoticComponent<{
13
+ faceDetectionOptions?: FaceDetectionOptions;
14
+ faceDetectionCallback: CallbackType;
15
+ } & CameraProps & React.RefAttributes<VisionCamera>>;
16
+ export {};
17
+ //# sourceMappingURL=Camera.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Camera.d.ts","sourceRoot":"","sources":["../../../src/Camera.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EACL,MAAM,IAAI,YAAY,EAGvB,MAAM,4BAA4B,CAAC;AAUpC,OAAO,KAAK,EACV,WAAW,EACX,KAAK,EAEN,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EAAE,IAAI,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AASjE,KAAK,YAAY,GAAG,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,KAAK,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AA4C1E;;;;;GAKG;AACH,eAAO,MAAM,MAAM;2BA/CM,oBAAoB;2BACpB,YAAY;oDA8JpC,CAAC"}
@@ -0,0 +1,118 @@
1
+ import { type Frame } from 'react-native-vision-camera';
2
+ type FaceDetectorPlugin = {
3
+ /**
4
+ * Detect faces on frame
5
+ *
6
+ * @param {Frame} frame Frame to detect faces
7
+ */
8
+ detectFaces: (frame: Frame) => Face[];
9
+ };
10
+ type Point = {
11
+ x: number;
12
+ y: number;
13
+ };
14
+ export interface Face {
15
+ pitchAngle: number;
16
+ rollAngle: number;
17
+ yawAngle: number;
18
+ bounds: Bounds;
19
+ leftEyeOpenProbability: number;
20
+ rightEyeOpenProbability: number;
21
+ smilingProbability: number;
22
+ contours: Contours;
23
+ landmarks: Landmarks;
24
+ data: number[];
25
+ }
26
+ export interface Bounds {
27
+ width: number;
28
+ height: number;
29
+ x: number;
30
+ y: number;
31
+ }
32
+ export interface Contours {
33
+ FACE: Point[];
34
+ LEFT_EYEBROW_TOP: Point[];
35
+ LEFT_EYEBROW_BOTTOM: Point[];
36
+ RIGHT_EYEBROW_TOP: Point[];
37
+ RIGHT_EYEBROW_BOTTOM: Point[];
38
+ LEFT_EYE: Point[];
39
+ RIGHT_EYE: Point[];
40
+ UPPER_LIP_TOP: Point[];
41
+ UPPER_LIP_BOTTOM: Point[];
42
+ LOWER_LIP_TOP: Point[];
43
+ LOWER_LIP_BOTTOM: Point[];
44
+ NOSE_BRIDGE: Point[];
45
+ NOSE_BOTTOM: Point[];
46
+ LEFT_CHEEK: Point[];
47
+ RIGHT_CHEEK: Point[];
48
+ }
49
+ export interface Landmarks {
50
+ LEFT_CHEEK: Point;
51
+ LEFT_EAR: Point;
52
+ LEFT_EYE: Point;
53
+ MOUTH_BOTTOM: Point;
54
+ MOUTH_LEFT: Point;
55
+ MOUTH_RIGHT: Point;
56
+ NOSE_BASE: Point;
57
+ RIGHT_CHEEK: Point;
58
+ RIGHT_EAR: Point;
59
+ RIGHT_EYE: Point;
60
+ }
61
+ export interface FaceDetectionOptions {
62
+ /**
63
+ * Favor speed or accuracy when detecting faces.
64
+ *
65
+ * @default 'fast'
66
+ */
67
+ performanceMode?: 'fast' | 'accurate';
68
+ /**
69
+ * Whether to attempt to identify facial 'landmarks': eyes, ears, nose, cheeks, mouth, and so on.
70
+ *
71
+ * @default 'none'
72
+ */
73
+ landmarkMode?: 'none' | 'all';
74
+ /**
75
+ * Whether to detect the contours of facial features. Contours are detected for only the most prominent face in an image.
76
+ *
77
+ * @default 'none'
78
+ */
79
+ contourMode?: 'none' | 'all';
80
+ /**
81
+ * Whether or not to classify faces into categories such as 'smiling', and 'eyes open'.
82
+ *
83
+ * @default 'none'
84
+ */
85
+ classificationMode?: 'none' | 'all';
86
+ /**
87
+ * Sets the smallest desired face size, expressed as the ratio of the width of the head to width of the image.
88
+ *
89
+ * @default 0.15
90
+ */
91
+ minFaceSize?: number;
92
+ /**
93
+ * Whether or not to assign faces an ID, which can be used to track faces across images.
94
+ *
95
+ * Note that when contour detection is enabled, only one face is detected, so face tracking doesn't produce useful results. For this reason, and to improve detection speed, don't enable both contour detection and face tracking.
96
+ *
97
+ * @default false
98
+ */
99
+ trackingEnabled?: boolean;
100
+ /**
101
+ * Should auto scale face bounds, contour and landmarks on native side?
102
+ * This option should be disabled if you want to draw on frame using `Skia Frame Processor`.
103
+ * See [this](https://github.com/luicfrr/react-native-vision-camera-face-detector/issues/30#issuecomment-2058805546) and [this](https://github.com/luicfrr/react-native-vision-camera-face-detector/issues/35) for more details.
104
+ *
105
+ * @default false
106
+ */
107
+ autoScale?: boolean;
108
+ }
109
+ /**
110
+ * Use an instance of face detector plugin.
111
+ *
112
+ * @param {FaceDetectionOptions | undefined} options Detection options
113
+ * @returns {FaceDetectorPlugin} Memoized plugin instance that will be
114
+ * destroyed once the component using `useFaceDetector()` unmounts.
115
+ */
116
+ export declare function useFaceDetector(options?: FaceDetectionOptions): FaceDetectorPlugin;
117
+ export {};
118
+ //# sourceMappingURL=FaceDetector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FaceDetector.d.ts","sourceRoot":"","sources":["../../../src/FaceDetector.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAE3E,KAAK,kBAAkB,GAAG;IACxB;;;;OAIG;IACH,WAAW,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,EAAE,CAAC;CACvC,CAAC;AAEF,KAAK,KAAK,GAAG;IACX,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX,CAAC;AAEF,MAAM,WAAW,IAAI;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,sBAAsB,EAAE,MAAM,CAAC;IAC/B,uBAAuB,EAAE,MAAM,CAAC;IAChC,kBAAkB,EAAE,MAAM,CAAC;IAC3B,QAAQ,EAAE,QAAQ,CAAC;IACnB,SAAS,EAAE,SAAS,CAAC;IACrB,IAAI,EAAE,MAAM,EAAE,CAAC;CAChB;AAED,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;CACX;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,KAAK,E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eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AA4BD;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,OAAO,CAAC,EAAE,oBAAoB,GAC7B,kBAAkB,CAEpB"}
@@ -0,0 +1,3 @@
1
+ export declare function initTensor(modelPath: string, count?: number): Promise<string>;
2
+ export declare function detectFromBase64(imageString: string): Promise<any>;
3
+ //# sourceMappingURL=Tensor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Tensor.d.ts","sourceRoot":"","sources":["../../../src/Tensor.ts"],"names":[],"mappings":"AAoBA,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAE7E;AAED,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAElE"}
@@ -0,0 +1,4 @@
1
+ export * from './Camera';
2
+ export * from './FaceDetector';
3
+ export * from './Tensor';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC"}
package/package.json ADDED
@@ -0,0 +1,186 @@
1
+ {
2
+ "name": "vision-camera-face-detection",
3
+ "version": "1.2.0",
4
+ "description": "Plugin Face Detection for Vision Camera 4",
5
+ "source": "./src/index.tsx",
6
+ "main": "./lib/commonjs/index.cjs",
7
+ "module": "./lib/module/index.mjs",
8
+ "types": "./lib/typescript/src/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./lib/typescript/src/index.d.ts",
12
+ "import": "./lib/module/index.mjs",
13
+ "require": "./lib/commonjs/index.cjs"
14
+ }
15
+ },
16
+ "files": [
17
+ "src",
18
+ "lib",
19
+ "android",
20
+ "ios",
21
+ "cpp",
22
+ "*.podspec",
23
+ "!ios/build",
24
+ "!android/build",
25
+ "!android/gradle",
26
+ "!android/gradlew",
27
+ "!android/gradlew.bat",
28
+ "!android/local.properties",
29
+ "!**/__tests__",
30
+ "!**/__fixtures__",
31
+ "!**/__mocks__",
32
+ "!**/.*"
33
+ ],
34
+ "scripts": {
35
+ "example": "yarn workspace vision-camera-face-detection-example",
36
+ "test": "jest",
37
+ "typecheck": "tsc --noEmit",
38
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
39
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
40
+ "prepare": "bob build",
41
+ "release": "release-it"
42
+ },
43
+ "keywords": [
44
+ "react-native",
45
+ "ios",
46
+ "android"
47
+ ],
48
+ "repository": {
49
+ "type": "git",
50
+ "url": "git+https://github.com/edritech93/vision-camera-face-detection.git"
51
+ },
52
+ "author": "Yudi Edri Alviska <yudiedrialviska@gmail.com> (https://github.com/edritech93)",
53
+ "license": "MIT",
54
+ "bugs": {
55
+ "url": "https://github.com/edritech93/vision-camera-face-detection/issues"
56
+ },
57
+ "homepage": "https://github.com/edritech93/vision-camera-face-detection#readme",
58
+ "publishConfig": {
59
+ "registry": "https://registry.npmjs.org/"
60
+ },
61
+ "devDependencies": {
62
+ "@commitlint/config-conventional": "^17.0.2",
63
+ "@evilmartians/lefthook": "^1.5.0",
64
+ "@react-native/eslint-config": "^0.73.1",
65
+ "@release-it/conventional-changelog": "^5.0.0",
66
+ "@types/jest": "^29.5.5",
67
+ "@types/react": "^18.2.44",
68
+ "commitlint": "^17.0.2",
69
+ "del-cli": "^5.1.0",
70
+ "eslint": "^8.51.0",
71
+ "eslint-config-prettier": "^9.0.0",
72
+ "eslint-plugin-prettier": "^5.0.1",
73
+ "jest": "^29.7.0",
74
+ "prettier": "^3.0.3",
75
+ "react": "18.2.0",
76
+ "react-native": "0.74.3",
77
+ "react-native-builder-bob": "^0.25.0",
78
+ "react-native-vision-camera": "4.4.1",
79
+ "react-native-worklets-core": "1.3.3",
80
+ "release-it": "^15.0.0",
81
+ "turbo": "^1.10.7",
82
+ "typescript": "^5.2.2"
83
+ },
84
+ "resolutions": {
85
+ "@types/react": "^18.2.44"
86
+ },
87
+ "peerDependencies": {
88
+ "react": "*",
89
+ "react-native": "*",
90
+ "react-native-vision-camera": ">= 4.0",
91
+ "react-native-worklets-core": ">= 1.3"
92
+ },
93
+ "workspaces": [
94
+ "example"
95
+ ],
96
+ "packageManager": "yarn@3.6.1",
97
+ "jest": {
98
+ "preset": "react-native",
99
+ "modulePathIgnorePatterns": [
100
+ "<rootDir>/example/node_modules",
101
+ "<rootDir>/lib/"
102
+ ]
103
+ },
104
+ "commitlint": {
105
+ "extends": [
106
+ "@commitlint/config-conventional"
107
+ ]
108
+ },
109
+ "release-it": {
110
+ "git": {
111
+ "commitMessage": "chore: release ${version}",
112
+ "tagName": "v${version}"
113
+ },
114
+ "npm": {
115
+ "publish": true
116
+ },
117
+ "github": {
118
+ "release": true
119
+ },
120
+ "plugins": {
121
+ "@release-it/conventional-changelog": {
122
+ "preset": "angular"
123
+ }
124
+ }
125
+ },
126
+ "eslintConfig": {
127
+ "root": true,
128
+ "extends": [
129
+ "@react-native",
130
+ "prettier"
131
+ ],
132
+ "rules": {
133
+ "react/react-in-jsx-scope": "off",
134
+ "prettier/prettier": [
135
+ "error",
136
+ {
137
+ "quoteProps": "consistent",
138
+ "singleQuote": true,
139
+ "tabWidth": 2,
140
+ "trailingComma": "es5",
141
+ "useTabs": false
142
+ }
143
+ ]
144
+ }
145
+ },
146
+ "eslintIgnore": [
147
+ "node_modules/",
148
+ "lib/"
149
+ ],
150
+ "prettier": {
151
+ "quoteProps": "consistent",
152
+ "singleQuote": true,
153
+ "tabWidth": 2,
154
+ "trailingComma": "es5",
155
+ "useTabs": false
156
+ },
157
+ "react-native-builder-bob": {
158
+ "source": "src",
159
+ "output": "lib",
160
+ "targets": [
161
+ [
162
+ "commonjs",
163
+ {
164
+ "esm": true
165
+ }
166
+ ],
167
+ [
168
+ "module",
169
+ {
170
+ "esm": true
171
+ }
172
+ ],
173
+ [
174
+ "typescript",
175
+ {
176
+ "project": "tsconfig.build.json"
177
+ }
178
+ ]
179
+ ]
180
+ },
181
+ "create-react-native-library": {
182
+ "type": "module-legacy",
183
+ "languages": "kotlin-swift",
184
+ "version": "0.38.1"
185
+ }
186
+ }