@rick427/react-native-liveness 0.1.2 → 0.1.4
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.
package/android/build.gradle
CHANGED
|
@@ -52,12 +52,12 @@ android {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
compileOptions {
|
|
55
|
-
sourceCompatibility JavaVersion.
|
|
56
|
-
targetCompatibility JavaVersion.
|
|
55
|
+
sourceCompatibility JavaVersion.VERSION_17
|
|
56
|
+
targetCompatibility JavaVersion.VERSION_17
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
kotlinOptions {
|
|
60
|
-
jvmTarget = "
|
|
60
|
+
jvmTarget = "17"
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
@@ -12,8 +12,9 @@ class LivenessCameraPackage : ReactPackage {
|
|
|
12
12
|
init {
|
|
13
13
|
// Register the frame processor plugin under the name "detectLiveness".
|
|
14
14
|
// JS side calls VisionCameraProxy.initFrameProcessorPlugin('detectLiveness').
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
// Lambda ignores proxy/options — FrameProcessorPlugin is no-arg in VC v4.5+.
|
|
16
|
+
FrameProcessorPluginRegistry.addFrameProcessorPlugin("detectLiveness") { _, _ ->
|
|
17
|
+
LivenessCameraPlugin()
|
|
17
18
|
}
|
|
18
19
|
}
|
|
19
20
|
}
|
|
@@ -7,12 +7,10 @@ import com.google.mlkit.vision.face.FaceDetection
|
|
|
7
7
|
import com.google.mlkit.vision.face.FaceDetectorOptions
|
|
8
8
|
import com.mrousavy.camera.frameprocessors.Frame
|
|
9
9
|
import com.mrousavy.camera.frameprocessors.FrameProcessorPlugin
|
|
10
|
-
import com.mrousavy.camera.frameprocessors.VisionCameraProxyHolder
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
) : FrameProcessorPlugin(proxy, options) {
|
|
11
|
+
// Vision Camera v4.5+ removed VisionCameraProxyHolder and made FrameProcessorPlugin
|
|
12
|
+
// a no-arg constructor. The proxy/options are no longer passed at construction time.
|
|
13
|
+
class LivenessCameraPlugin : FrameProcessorPlugin() {
|
|
16
14
|
|
|
17
15
|
private val faceDetector = FaceDetection.getClient(
|
|
18
16
|
FaceDetectorOptions.Builder()
|
|
@@ -23,15 +21,28 @@ class LivenessCameraPlugin(
|
|
|
23
21
|
.build()
|
|
24
22
|
)
|
|
25
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Convert Vision Camera's Orientation to ML Kit rotation degrees.
|
|
26
|
+
* Uses toString() comparison to stay resilient across VC patch versions
|
|
27
|
+
* where the Orientation API (toDegrees / toSurfaceRotation) may vary.
|
|
28
|
+
*/
|
|
29
|
+
private fun orientationDegrees(frame: Frame): Int {
|
|
30
|
+
val name = frame.orientation.toString().uppercase()
|
|
31
|
+
return when {
|
|
32
|
+
name.contains("LANDSCAPE_LEFT") -> 90
|
|
33
|
+
name.contains("PORTRAIT_UPSIDE_DOWN") -> 180
|
|
34
|
+
name.contains("LANDSCAPE_RIGHT") -> 270
|
|
35
|
+
else -> 0 // PORTRAIT
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
26
39
|
override fun callback(frame: Frame, arguments: Map<String, Any>?): Any {
|
|
27
40
|
val mediaImage: Image = frame.image
|
|
28
|
-
val
|
|
29
|
-
|
|
30
|
-
val inputImage = InputImage.fromMediaImage(mediaImage, rotationDegrees)
|
|
41
|
+
val inputImage = InputImage.fromMediaImage(mediaImage, orientationDegrees(frame))
|
|
31
42
|
|
|
32
43
|
return try {
|
|
33
44
|
// Tasks.await blocks the frame-processor thread synchronously.
|
|
34
|
-
// ML Kit face detection is fast (~5
|
|
45
|
+
// ML Kit face detection is fast (~5–10 ms) so this is acceptable.
|
|
35
46
|
val faces = Tasks.await(faceDetector.process(inputImage))
|
|
36
47
|
|
|
37
48
|
if (faces.isEmpty()) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rick427/react-native-liveness",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"description": "Liveness detection library for React Native using Vision Camera v4 and ML Kit",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|