react-native-vision-camera-spoof-detector 1.1.21 → 1.1.22
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.
|
@@ -292,29 +292,6 @@ class FaceAntiSpoofingAdvanced(private val assetManager: AssetManager) {
|
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
294
|
|
|
295
|
-
private fun neuralNetworkAntiSpoofingRGBA(rgba: ByteArray, width: Int, height: Int): Result<Float> {
|
|
296
|
-
return try {
|
|
297
|
-
val img = normalizeRgbaImage(rgba, width, height, INPUT_IMAGE_SIZE, INPUT_IMAGE_SIZE)
|
|
298
|
-
val input = arrayOf(img)
|
|
299
|
-
|
|
300
|
-
clssPred[0].fill(0f)
|
|
301
|
-
leafNodeMask[0].fill(0f)
|
|
302
|
-
|
|
303
|
-
outputs[outputIndex0] = clssPred
|
|
304
|
-
outputs[outputIndex1] = leafNodeMask
|
|
305
|
-
|
|
306
|
-
interpreter!!.runForMultipleInputsOutputs(arrayOf(input), outputs)
|
|
307
|
-
|
|
308
|
-
Log.i(TAG, "clss_pred: [${clssPred[0].joinToString()}]")
|
|
309
|
-
Log.i(TAG, "leaf_node_mask: [${leafNodeMask[0].joinToString()}]")
|
|
310
|
-
|
|
311
|
-
Result.success(leafScore1(clssPred, leafNodeMask))
|
|
312
|
-
} catch (e: Exception) {
|
|
313
|
-
Log.e(TAG, "Error in neuralNetworkAntiSpoofingRGBA", e)
|
|
314
|
-
Result.failure(e)
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
|
|
318
295
|
private fun neuralNetworkAntiSpoofingSampled(rgbBuffer: Array<Array<FloatArray>>): Result<Float> {
|
|
319
296
|
return try {
|
|
320
297
|
val input = arrayOf(rgbBuffer)
|
|
@@ -363,38 +340,13 @@ class FaceAntiSpoofingAdvanced(private val assetManager: AssetManager) {
|
|
|
363
340
|
return floatValues
|
|
364
341
|
}
|
|
365
342
|
|
|
366
|
-
private fun normalizeRgbaImage(
|
|
367
|
-
rgba: ByteArray,
|
|
368
|
-
srcWidth: Int,
|
|
369
|
-
srcHeight: Int,
|
|
370
|
-
targetWidth: Int,
|
|
371
|
-
targetHeight: Int
|
|
372
|
-
): Array<Array<FloatArray>> {
|
|
373
|
-
val floatValues = Array(targetHeight) { Array(targetWidth) { FloatArray(3) } }
|
|
374
|
-
val scaleX = srcWidth.toFloat() / targetWidth
|
|
375
|
-
val scaleY = srcHeight.toFloat() / targetHeight
|
|
376
|
-
|
|
377
|
-
for (targetY in 0 until targetHeight) {
|
|
378
|
-
val srcY = (targetY * scaleY).toInt().coerceIn(0, srcHeight - 1)
|
|
379
|
-
for (targetX in 0 until targetWidth) {
|
|
380
|
-
val srcX = (targetX * scaleX).toInt().coerceIn(0, srcWidth - 1)
|
|
381
|
-
val srcIndex = (srcY * srcWidth + srcX) * 4
|
|
382
|
-
|
|
383
|
-
val r = (rgba[srcIndex].toInt() and 0xFF) / 255f
|
|
384
|
-
val g = (rgba[srcIndex + 1].toInt() and 0xFF) / 255f
|
|
385
|
-
val b = (rgba[srcIndex + 2].toInt() and 0xFF) / 255f
|
|
386
|
-
floatValues[targetY][targetX] = floatArrayOf(r, g, b)
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
return floatValues
|
|
391
|
-
}
|
|
392
|
-
|
|
393
343
|
private data class SampledFrame(
|
|
394
344
|
val rgbBuffer: Array<Array<FloatArray>>,
|
|
395
345
|
val grayBuffer: Array<IntArray>
|
|
396
346
|
)
|
|
397
347
|
|
|
348
|
+
// Single-pass resize: one source pixel sample writes both the model RGB tensor
|
|
349
|
+
// and the grayscale buffer used for Laplacian scoring.
|
|
398
350
|
private fun sampleRgbaToModelAndGray(
|
|
399
351
|
rgba: ByteArray,
|
|
400
352
|
srcWidth: Int,
|
|
@@ -446,17 +398,6 @@ class FaceAntiSpoofingAdvanced(private val assetManager: AssetManager) {
|
|
|
446
398
|
}
|
|
447
399
|
}
|
|
448
400
|
|
|
449
|
-
private fun laplacianFromRgba(rgba: ByteArray, width: Int, height: Int): Result<Int> {
|
|
450
|
-
return try {
|
|
451
|
-
val gray = rgbaToGrayscale(rgba, width, height, INPUT_IMAGE_SIZE, INPUT_IMAGE_SIZE)
|
|
452
|
-
val score = calculateLaplacianFromGray(gray)
|
|
453
|
-
Result.success(score)
|
|
454
|
-
} catch (e: Exception) {
|
|
455
|
-
Log.e(TAG, "Error in laplacianFromRgba", e)
|
|
456
|
-
Result.failure(e)
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
|
|
460
401
|
// FROM WORKING VERSION: calculateLaplacianScore
|
|
461
402
|
private fun calculateLaplacianScore(bitmap: Bitmap): Int {
|
|
462
403
|
val laplace = arrayOf(
|
|
@@ -508,32 +449,6 @@ class FaceAntiSpoofingAdvanced(private val assetManager: AssetManager) {
|
|
|
508
449
|
return greyImg
|
|
509
450
|
}
|
|
510
451
|
|
|
511
|
-
private fun rgbaToGrayscale(
|
|
512
|
-
rgba: ByteArray,
|
|
513
|
-
srcWidth: Int,
|
|
514
|
-
srcHeight: Int,
|
|
515
|
-
targetWidth: Int,
|
|
516
|
-
targetHeight: Int
|
|
517
|
-
): Array<IntArray> {
|
|
518
|
-
val gray = Array(targetHeight) { IntArray(targetWidth) }
|
|
519
|
-
val scaleX = srcWidth.toFloat() / targetWidth
|
|
520
|
-
val scaleY = srcHeight.toFloat() / targetHeight
|
|
521
|
-
|
|
522
|
-
for (targetY in 0 until targetHeight) {
|
|
523
|
-
val srcY = (targetY * scaleY).toInt().coerceIn(0, srcHeight - 1)
|
|
524
|
-
for (targetX in 0 until targetWidth) {
|
|
525
|
-
val srcX = (targetX * scaleX).toInt().coerceIn(0, srcWidth - 1)
|
|
526
|
-
val srcIndex = (srcY * srcWidth + srcX) * 4
|
|
527
|
-
val r = rgba[srcIndex].toInt() and 0xFF
|
|
528
|
-
val g = rgba[srcIndex + 1].toInt() and 0xFF
|
|
529
|
-
val b = rgba[srcIndex + 2].toInt() and 0xFF
|
|
530
|
-
gray[targetY][targetX] = (0.299 * r + 0.587 * g + 0.114 * b).toInt()
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
|
-
|
|
534
|
-
return gray
|
|
535
|
-
}
|
|
536
|
-
|
|
537
452
|
private fun calculateLaplacianFromGray(img: Array<IntArray>): Int {
|
|
538
453
|
val laplace = arrayOf(
|
|
539
454
|
intArrayOf(0, 1, 0),
|
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.22",
|
|
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": {
|