react-native-vision-camera-spoof-detector 1.1.17 → 1.1.19
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.
|
@@ -45,6 +45,8 @@ class FaceAntiSpoofingAdvanced(private val assetManager: AssetManager) {
|
|
|
45
45
|
private val outputs = mutableMapOf<Int, Any>()
|
|
46
46
|
private var outputIndex0: Int = 0
|
|
47
47
|
private var outputIndex1: Int = 1
|
|
48
|
+
private val modelInputBuffer = Array(INPUT_IMAGE_SIZE) { Array(INPUT_IMAGE_SIZE) { FloatArray(3) } }
|
|
49
|
+
private val grayBuffer = Array(INPUT_IMAGE_SIZE) { IntArray(INPUT_IMAGE_SIZE) }
|
|
48
50
|
|
|
49
51
|
init {
|
|
50
52
|
initializeInterpreter()
|
|
@@ -371,8 +373,6 @@ class FaceAntiSpoofingAdvanced(private val assetManager: AssetManager) {
|
|
|
371
373
|
): SampledFrame {
|
|
372
374
|
val targetWidth = INPUT_IMAGE_SIZE
|
|
373
375
|
val targetHeight = INPUT_IMAGE_SIZE
|
|
374
|
-
val rgbBuffer = Array(targetHeight) { Array(targetWidth) { FloatArray(3) } }
|
|
375
|
-
val grayBuffer = Array(targetHeight) { IntArray(targetWidth) }
|
|
376
376
|
val scaleX = srcWidth.toFloat() / targetWidth
|
|
377
377
|
val scaleY = srcHeight.toFloat() / targetHeight
|
|
378
378
|
|
|
@@ -385,12 +385,19 @@ class FaceAntiSpoofingAdvanced(private val assetManager: AssetManager) {
|
|
|
385
385
|
val r = (rgba[srcIndex].toInt() and 0xFF) / 255f
|
|
386
386
|
val g = (rgba[srcIndex + 1].toInt() and 0xFF) / 255f
|
|
387
387
|
val b = (rgba[srcIndex + 2].toInt() and 0xFF) / 255f
|
|
388
|
-
|
|
389
|
-
|
|
388
|
+
|
|
389
|
+
modelInputBuffer[targetY][targetX][0] = r
|
|
390
|
+
modelInputBuffer[targetY][targetX][1] = g
|
|
391
|
+
modelInputBuffer[targetY][targetX][2] = b
|
|
392
|
+
grayBuffer[targetY][targetX] = (
|
|
393
|
+
0.299f * rgba[srcIndex].toInt() +
|
|
394
|
+
0.587f * rgba[srcIndex + 1].toInt() +
|
|
395
|
+
0.114f * rgba[srcIndex + 2].toInt()
|
|
396
|
+
).toInt()
|
|
390
397
|
}
|
|
391
398
|
}
|
|
392
399
|
|
|
393
|
-
return SampledFrame(
|
|
400
|
+
return SampledFrame(modelInputBuffer, grayBuffer)
|
|
394
401
|
}
|
|
395
402
|
|
|
396
403
|
// FROM WORKING VERSION: laplacian with Bitmap
|
package/android/src/main/java/com/margelo/nitro/camera/spoofdetector/HybridSpoofDetectorOutput.kt
CHANGED
|
@@ -100,42 +100,33 @@ class HybridSpoofDetectorOutput(
|
|
|
100
100
|
val width = image.width
|
|
101
101
|
val height = image.height
|
|
102
102
|
val bytesPerPixel = 4
|
|
103
|
-
val
|
|
104
|
-
val
|
|
103
|
+
val outputSize = width * height * bytesPerPixel
|
|
104
|
+
val packed = ByteArray(outputSize)
|
|
105
105
|
val buffer = plane.buffer.duplicate()
|
|
106
106
|
buffer.order(java.nio.ByteOrder.nativeOrder())
|
|
107
107
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
val copyLength = rowBytes.coerceAtMost(rowStride)
|
|
112
|
-
buffer.position(srcOffset)
|
|
113
|
-
val slice = ByteArray(copyLength)
|
|
114
|
-
buffer.get(slice)
|
|
115
|
-
System.arraycopy(slice, 0, rgba, dstOffset, copyLength)
|
|
108
|
+
if (pixelStride == bytesPerPixel && rowStride == width * bytesPerPixel) {
|
|
109
|
+
buffer.get(packed)
|
|
110
|
+
return packed
|
|
116
111
|
}
|
|
117
112
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
for (
|
|
122
|
-
val
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
packed[outputIndex++] = b.toByte()
|
|
132
|
-
packed[outputIndex++] = a.toByte()
|
|
133
|
-
}
|
|
113
|
+
var outputIndex = 0
|
|
114
|
+
for (y in 0 until height) {
|
|
115
|
+
val rowOffset = y * rowStride
|
|
116
|
+
for (x in 0 until width) {
|
|
117
|
+
val pixelOffset = rowOffset + x * pixelStride
|
|
118
|
+
val r = buffer.get(pixelOffset).toInt() and 0xFF
|
|
119
|
+
val g = buffer.get(pixelOffset + 1).toInt() and 0xFF
|
|
120
|
+
val b = buffer.get(pixelOffset + 2).toInt() and 0xFF
|
|
121
|
+
val a = buffer.get(pixelOffset + 3).toInt() and 0xFF
|
|
122
|
+
packed[outputIndex++] = r.toByte()
|
|
123
|
+
packed[outputIndex++] = g.toByte()
|
|
124
|
+
packed[outputIndex++] = b.toByte()
|
|
125
|
+
packed[outputIndex++] = a.toByte()
|
|
134
126
|
}
|
|
135
|
-
return packed
|
|
136
127
|
}
|
|
137
128
|
|
|
138
|
-
return
|
|
129
|
+
return packed
|
|
139
130
|
}
|
|
140
131
|
|
|
141
132
|
override fun dispose() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-vision-camera-spoof-detector",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.19",
|
|
4
4
|
"description": "High-performance face anti-spoofing and liveness detection module for React Native Vision Camera. Uses TensorFlow Lite with GPU acceleration and optimized YUV processing.",
|
|
5
5
|
"homepage": "https://github.com/dpraful/react-native-vision-camera-spoof-detector",
|
|
6
6
|
"repository": {
|