react-native-vision-camera-spoof-detector 1.1.10 → 1.1.15
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/README.md +103 -186
- package/VisionCameraSpoofDetector.podspec +41 -0
- package/ios/FaceAntiSpoofManager.swift +106 -4
- package/ios/FaceAntiSpoofModule.m +38 -51
- package/ios/HybridSpoofDetectorFactory.swift +10 -0
- package/ios/HybridSpoofDetectorOutput.swift +164 -0
- package/nitro.json +4 -0
- package/nitrogen/generated/ios/VisionCameraSpoofDetector+autolinking.rb +62 -0
- package/nitrogen/generated/ios/VisionCameraSpoofDetector-Swift-Cxx-Bridge.cpp +60 -0
- package/nitrogen/generated/ios/VisionCameraSpoofDetector-Swift-Cxx-Bridge.hpp +151 -0
- package/nitrogen/generated/ios/VisionCameraSpoofDetector-Swift-Cxx-Umbrella.hpp +60 -0
- package/nitrogen/generated/ios/VisionCameraSpoofDetectorAutolinking.mm +33 -0
- package/nitrogen/generated/ios/VisionCameraSpoofDetectorAutolinking.swift +26 -0
- package/nitrogen/generated/ios/c++/HybridSpoofDetectorFactorySpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridSpoofDetectorFactorySpecSwift.hpp +97 -0
- package/nitrogen/generated/ios/swift/AntiSpoofingResult.swift +54 -0
- package/nitrogen/generated/ios/swift/Func_void_AntiSpoofingResult.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridSpoofDetectorFactorySpec.swift +56 -0
- package/nitrogen/generated/ios/swift/HybridSpoofDetectorFactorySpec_cxx.swift +142 -0
- package/nitrogen/generated/ios/swift/Size.swift +34 -0
- package/nitrogen/generated/ios/swift/SpoofDetectorOutputOptions.swift +74 -0
- package/package.json +8 -3
- package/src/specs/SpoofDetectorFactory.nitro.ts +1 -0
- package/ios/FaceAntiSpoofFrameProcessor.swift +0 -301
- package/ios/FaceAntiSpoofJSI.h +0 -12
- package/ios/FaceAntiSpoofJSI.mm +0 -92
- package/ios/FaceAntiSpoofPluginRegister.m +0 -84
- package/ios/models/FaceAntiSpoofing.tflite +0 -0
- package/react-native-vision-camera-spoof-detector.podspec +0 -22
- /package/{ios/models → lib/assets}/model_spec.json +0 -0
|
@@ -1,301 +0,0 @@
|
|
|
1
|
-
import Foundation
|
|
2
|
-
|
|
3
|
-
#if canImport(VisionCamera)
|
|
4
|
-
import VisionCamera
|
|
5
|
-
import AVFoundation
|
|
6
|
-
import CoreImage
|
|
7
|
-
import UIKit
|
|
8
|
-
import Accelerate
|
|
9
|
-
|
|
10
|
-
#if canImport(TensorFlowLite)
|
|
11
|
-
import TensorFlowLite
|
|
12
|
-
#endif
|
|
13
|
-
|
|
14
|
-
typealias FaceAntiSpoofFrameType = VisionCamera.Frame
|
|
15
|
-
typealias FaceAntiSpoofProxyType = VisionCamera.VisionCameraProxyHolder
|
|
16
|
-
typealias FaceAntiSpoofPluginBase = VisionCamera.FrameProcessorPlugin
|
|
17
|
-
|
|
18
|
-
@objc(FaceAntiSpoofFrameProcessor)
|
|
19
|
-
class FaceAntiSpoofFrameProcessor: FaceAntiSpoofPluginBase {
|
|
20
|
-
private weak var proxyHolder: FaceAntiSpoofProxyType?
|
|
21
|
-
|
|
22
|
-
// Processing state
|
|
23
|
-
private let processingQueue = DispatchQueue(label: "com.faceantispoof.processing", qos: .userInitiated)
|
|
24
|
-
private var isProcessing: Bool = false
|
|
25
|
-
private var latestResult: [String: Any] = ["error": "Not initialized", "isLive": false, "label": "Not Initialized"]
|
|
26
|
-
private static let INPUT_IMAGE_SIZE: Int = 256
|
|
27
|
-
private static let BASE_THRESHOLD: Float = 0.2
|
|
28
|
-
private static let LAPLACE_THRESHOLD: Int = 50
|
|
29
|
-
private static let LAPLACIAN_THRESHOLD: Int = 4000
|
|
30
|
-
|
|
31
|
-
#if canImport(TensorFlowLite)
|
|
32
|
-
// Interpreter is provided by FaceAntiSpoofManager.sharedInterpreter
|
|
33
|
-
#endif
|
|
34
|
-
|
|
35
|
-
override init(
|
|
36
|
-
proxy: FaceAntiSpoofProxyType,
|
|
37
|
-
options: [AnyHashable : Any]! = [:]
|
|
38
|
-
) {
|
|
39
|
-
#if canImport(VisionCamera)
|
|
40
|
-
super.init(proxy: proxy, options: options)
|
|
41
|
-
#else
|
|
42
|
-
super.init(proxy: proxy, options: options as NSDictionary?)
|
|
43
|
-
#endif
|
|
44
|
-
self.proxyHolder = proxy
|
|
45
|
-
|
|
46
|
-
#if canImport(TensorFlowLite)
|
|
47
|
-
let managerInited = FaceAntiSpoofManager.initializeModel()
|
|
48
|
-
if managerInited {
|
|
49
|
-
NSLog("[FaceAntiSpoof] Manager initialized model")
|
|
50
|
-
} else {
|
|
51
|
-
NSLog("[FaceAntiSpoof] Manager failed to initialize model; running stub")
|
|
52
|
-
}
|
|
53
|
-
#else
|
|
54
|
-
NSLog("[FaceAntiSpoof] TensorFlowLite not available; running stub")
|
|
55
|
-
#endif
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
deinit {
|
|
59
|
-
NSLog("[FaceAntiSpoof] deinit - releasing resources")
|
|
60
|
-
self.proxyHolder = nil
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
override func callback(
|
|
64
|
-
_ frame: FaceAntiSpoofFrameType,
|
|
65
|
-
withArguments arguments: [AnyHashable : Any]?
|
|
66
|
-
) -> Any {
|
|
67
|
-
#if canImport(TensorFlowLite)
|
|
68
|
-
guard FaceAntiSpoofManager.isModelLoaded() else {
|
|
69
|
-
return ["error": "Model not loaded", "isLive": false, "label": "stub"]
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
let sampleBuffer = frame.buffer
|
|
73
|
-
guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else {
|
|
74
|
-
return ["error": "No pixel buffer", "isLive": false, "label": "stub"]
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
let width = CVPixelBufferGetWidth(pixelBuffer)
|
|
78
|
-
let height = CVPixelBufferGetHeight(pixelBuffer)
|
|
79
|
-
|
|
80
|
-
// If processing already in flight, return latest cached result immediately
|
|
81
|
-
var shouldReturnLatest = false
|
|
82
|
-
objc_sync_enter(self)
|
|
83
|
-
if isProcessing {
|
|
84
|
-
shouldReturnLatest = true
|
|
85
|
-
} else {
|
|
86
|
-
isProcessing = true
|
|
87
|
-
}
|
|
88
|
-
objc_sync_exit(self)
|
|
89
|
-
|
|
90
|
-
if shouldReturnLatest {
|
|
91
|
-
return latestResult
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// Capture a small, resized RGB float snapshot synchronously while the pixel buffer is valid
|
|
95
|
-
let targetSize = CGSize(width: Self.INPUT_IMAGE_SIZE, height: Self.INPUT_IMAGE_SIZE)
|
|
96
|
-
guard let rgbInput = Self.rgbFloatData(from: pixelBuffer, orientation: frame.orientation, size: targetSize) else {
|
|
97
|
-
objc_sync_enter(self)
|
|
98
|
-
isProcessing = false
|
|
99
|
-
objc_sync_exit(self)
|
|
100
|
-
latestResult = ["error": "Failed to create RGB snapshot", "isLive": false, "label": "error"]
|
|
101
|
-
return latestResult
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// Offload heavy model work to a background queue
|
|
105
|
-
processingQueue.async { [weak self] in
|
|
106
|
-
guard let self = self else { return }
|
|
107
|
-
defer {
|
|
108
|
-
objc_sync_enter(self)
|
|
109
|
-
self.isProcessing = false
|
|
110
|
-
objc_sync_exit(self)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
guard let interpreter = FaceAntiSpoofManager.sharedInterpreter else {
|
|
114
|
-
self.latestResult = ["error": "Interpreter not available", "isLive": false, "label": "error"]
|
|
115
|
-
return
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
do {
|
|
119
|
-
// Prepare input Data (Float32 little-endian)
|
|
120
|
-
var inputFloats = rgbInput
|
|
121
|
-
let inputData = Data(bytes: &inputFloats, count: inputFloats.count * MemoryLayout<Float>.size)
|
|
122
|
-
|
|
123
|
-
try interpreter.copy(inputData, toInputAt: 0)
|
|
124
|
-
try interpreter.invoke()
|
|
125
|
-
|
|
126
|
-
// Read outputs (assume indices 0 and 1 correspond to clssPred and leafNodeMask)
|
|
127
|
-
let out0 = try interpreter.output(at: 0)
|
|
128
|
-
let out1 = try interpreter.output(at: 1)
|
|
129
|
-
|
|
130
|
-
let clssPred: [Float] = out0.data.withUnsafeBytes { ptr in
|
|
131
|
-
let floatPtr = ptr.bindMemory(to: Float.self)
|
|
132
|
-
return Array(floatPtr)
|
|
133
|
-
}
|
|
134
|
-
let leafMask: [Float] = out1.data.withUnsafeBytes { ptr in
|
|
135
|
-
let floatPtr = ptr.bindMemory(to: Float.self)
|
|
136
|
-
return Array(floatPtr)
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Compute neural network score similar to Android leafScore1
|
|
140
|
-
let count = min(clssPred.count, leafMask.count)
|
|
141
|
-
var nnScore: Float = 0.0
|
|
142
|
-
for i in 0..<count {
|
|
143
|
-
nnScore += abs(clssPred[i]) * leafMask[i]
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Laplacian score computed from the RGB snapshot (resized)
|
|
147
|
-
let lapScore = Self.calculateLaplacianScore(from: rgbInput, width: Self.INPUT_IMAGE_SIZE, height: Self.INPUT_IMAGE_SIZE)
|
|
148
|
-
|
|
149
|
-
let combined = Self.calculateCombinedScore(neuralScore: nnScore, laplacianScore: lapScore)
|
|
150
|
-
let confidence = Self.calculateConfidence(neuralScore: nnScore, laplacianScore: lapScore)
|
|
151
|
-
let isLive = nnScore < Self.BASE_THRESHOLD && lapScore > Self.LAPLACIAN_THRESHOLD
|
|
152
|
-
|
|
153
|
-
self.latestResult = [
|
|
154
|
-
"neuralNetworkScore": Double(nnScore),
|
|
155
|
-
"laplacianScore": lapScore,
|
|
156
|
-
"combinedScore": Double(combined),
|
|
157
|
-
"confidence": Double(confidence),
|
|
158
|
-
"isLive": isLive,
|
|
159
|
-
"label": isLive ? "live" : "spoof",
|
|
160
|
-
"width": width,
|
|
161
|
-
"height": height
|
|
162
|
-
]
|
|
163
|
-
} catch {
|
|
164
|
-
self.latestResult = ["error": "Processing error: \(error)", "isLive": false, "label": "error"]
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// Return latest result immediately (may be previous or initial)
|
|
169
|
-
return latestResult
|
|
170
|
-
#else
|
|
171
|
-
return ["error": "TensorFlowLite not available", "isLive": false, "label": "stub"]
|
|
172
|
-
#endif
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// MARK: - Helpers
|
|
176
|
-
#if canImport(TensorFlowLite)
|
|
177
|
-
private static func floatArray(from data: Data) -> [Float] {
|
|
178
|
-
let count = data.count / MemoryLayout<Float>.size
|
|
179
|
-
return data.withUnsafeBytes { buffer -> [Float] in
|
|
180
|
-
let ptr = buffer.bindMemory(to: Float.self)
|
|
181
|
-
return Array(UnsafeBufferPointer(start: ptr.baseAddress, count: count))
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
private static let sharedCIContext: CIContext = CIContext(options: nil)
|
|
186
|
-
|
|
187
|
-
private static func rgbFloatData(from pixelBuffer: CVPixelBuffer, orientation: UIImage.Orientation, size: CGSize) -> [Float]? {
|
|
188
|
-
CVPixelBufferLockBaseAddress(pixelBuffer, CVPixelBufferLockFlags.readOnly)
|
|
189
|
-
defer { CVPixelBufferUnlockBaseAddress(pixelBuffer, CVPixelBufferLockFlags.readOnly) }
|
|
190
|
-
|
|
191
|
-
let image = CIImage(cvPixelBuffer: pixelBuffer)
|
|
192
|
-
let exifOrientation: CGImagePropertyOrientation
|
|
193
|
-
switch orientation {
|
|
194
|
-
case .up, .upMirrored:
|
|
195
|
-
exifOrientation = .up
|
|
196
|
-
case .right, .rightMirrored:
|
|
197
|
-
exifOrientation = .right
|
|
198
|
-
case .down, .downMirrored:
|
|
199
|
-
exifOrientation = .down
|
|
200
|
-
case .left, .leftMirrored:
|
|
201
|
-
exifOrientation = .left
|
|
202
|
-
@unknown default:
|
|
203
|
-
exifOrientation = .up
|
|
204
|
-
}
|
|
205
|
-
let ciImage = image.oriented(forExifOrientation: Int32(exifOrientation.rawValue))
|
|
206
|
-
let context = Self.sharedCIContext
|
|
207
|
-
guard let cgImage = context.createCGImage(ciImage, from: ciImage.extent) else { return nil }
|
|
208
|
-
|
|
209
|
-
let width = Int(size.width)
|
|
210
|
-
let height = Int(size.height)
|
|
211
|
-
let colorSpace = CGColorSpaceCreateDeviceRGB()
|
|
212
|
-
var rawData = [UInt8](repeating: 0, count: width * height * 4)
|
|
213
|
-
rawData.withUnsafeMutableBytes { ptr in
|
|
214
|
-
if let base = ptr.baseAddress {
|
|
215
|
-
let bytesPerRow = width * 4
|
|
216
|
-
if let ctx = CGContext(data: base,
|
|
217
|
-
width: width,
|
|
218
|
-
height: height,
|
|
219
|
-
bitsPerComponent: 8,
|
|
220
|
-
bytesPerRow: bytesPerRow,
|
|
221
|
-
space: colorSpace,
|
|
222
|
-
bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue) {
|
|
223
|
-
ctx.interpolationQuality = .high
|
|
224
|
-
ctx.draw(cgImage, in: CGRect(x: 0, y: 0, width: width, height: height))
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
var floatData = [Float](repeating: 0, count: width * height * 3)
|
|
230
|
-
var idx = 0
|
|
231
|
-
for y in 0..<height {
|
|
232
|
-
for x in 0..<width {
|
|
233
|
-
let pixelIndex = (y * width + x) * 4
|
|
234
|
-
let r = Float(rawData[pixelIndex]) / 255.0
|
|
235
|
-
let g = Float(rawData[pixelIndex + 1]) / 255.0
|
|
236
|
-
let b = Float(rawData[pixelIndex + 2]) / 255.0
|
|
237
|
-
floatData[idx] = r
|
|
238
|
-
floatData[idx + 1] = g
|
|
239
|
-
floatData[idx + 2] = b
|
|
240
|
-
idx += 3
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
return floatData
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
private static func calculateLaplacianScore(from rgbData: [Float], width: Int, height: Int) -> Int {
|
|
247
|
-
var grey = [Int](repeating: 0, count: width * height)
|
|
248
|
-
var i = 0
|
|
249
|
-
for y in 0..<height {
|
|
250
|
-
for x in 0..<width {
|
|
251
|
-
let base = (y * width + x) * 3
|
|
252
|
-
let r = Int((rgbData[base] * 255).rounded())
|
|
253
|
-
let g = Int((rgbData[base + 1] * 255).rounded())
|
|
254
|
-
let b = Int((rgbData[base + 2] * 255).rounded())
|
|
255
|
-
let value = Int(0.299 * Float(r) + 0.587 * Float(g) + 0.114 * Float(b))
|
|
256
|
-
grey[i] = value
|
|
257
|
-
i += 1
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
let laplace = [[0,1,0],[1,-4,1],[0,1,0]]
|
|
262
|
-
let size = 3
|
|
263
|
-
var score = 0
|
|
264
|
-
let threshold = Self.LAPLACE_THRESHOLD
|
|
265
|
-
for y in 0..<(height - size + 1) {
|
|
266
|
-
for x in 0..<(width - size + 1) {
|
|
267
|
-
var result = 0
|
|
268
|
-
for ky in 0..<size {
|
|
269
|
-
for kx in 0..<size {
|
|
270
|
-
result += grey[(y + ky) * width + (x + kx)] * laplace[ky][kx]
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
if result > threshold {
|
|
274
|
-
score += 1
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
return score
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
private static func calculateCombinedScore(neuralScore: Float, laplacianScore: Int) -> Float {
|
|
282
|
-
let normalizedNeural = min(max(neuralScore, 0), 1)
|
|
283
|
-
let normalizedLaplacian = min(max(Float(laplacianScore) / Float(Self.LAPLACIAN_THRESHOLD), 0), 1)
|
|
284
|
-
let neuralWeight: Float = 0.6
|
|
285
|
-
let laplacianWeight: Float = 0.4
|
|
286
|
-
let invertedNeural = 1.0 - normalizedNeural
|
|
287
|
-
return (invertedNeural * neuralWeight) + (normalizedLaplacian * laplacianWeight)
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
private static func calculateConfidence(neuralScore: Float, laplacianScore: Int) -> Float {
|
|
291
|
-
let neuralConfidence = min(max(neuralScore, 0), 1)
|
|
292
|
-
let laplacianConfidence = min(max(Float(laplacianScore) / Float(Self.LAPLACIAN_THRESHOLD), 0), 1)
|
|
293
|
-
let invertedNeural = 1.0 - neuralConfidence
|
|
294
|
-
return (invertedNeural * 0.6 + laplacianConfidence * 0.4)
|
|
295
|
-
}
|
|
296
|
-
#endif
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
#endif
|
|
300
|
-
|
|
301
|
-
|
package/ios/FaceAntiSpoofJSI.h
DELETED
package/ios/FaceAntiSpoofJSI.mm
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
// Objective-C++ JSI registration for FaceAntiSpoof
|
|
2
|
-
#import "FaceAntiSpoofJSI.h"
|
|
3
|
-
#import <Foundation/Foundation.h>
|
|
4
|
-
#import <objc/runtime.h>
|
|
5
|
-
#import <objc/message.h>
|
|
6
|
-
|
|
7
|
-
#ifdef __cplusplus
|
|
8
|
-
#include <jsi/jsi.h>
|
|
9
|
-
using namespace facebook;
|
|
10
|
-
#endif
|
|
11
|
-
|
|
12
|
-
// Helper to call +[FaceAntiSpoofManager isModelLoaded]
|
|
13
|
-
static bool FaceAntiSpoofManager_isModelLoaded() {
|
|
14
|
-
Class managerClass = objc_getClass("FaceAntiSpoofManager");
|
|
15
|
-
if (!managerClass) return false;
|
|
16
|
-
SEL sel = sel_getUid("isModelLoaded");
|
|
17
|
-
if (!sel) return false;
|
|
18
|
-
BOOL (*msgSendBool)(id, SEL) = (BOOL (*)(id, SEL))objc_msgSend;
|
|
19
|
-
return msgSendBool((id)managerClass, sel);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Helper to call +[FaceAntiSpoofManager initializeModel]
|
|
23
|
-
static bool FaceAntiSpoofManager_initialize() {
|
|
24
|
-
Class managerClass = objc_getClass("FaceAntiSpoofManager");
|
|
25
|
-
if (!managerClass) return false;
|
|
26
|
-
SEL sel = sel_getUid("initializeModel");
|
|
27
|
-
if (!sel) return false;
|
|
28
|
-
BOOL (*msgSendBool)(id, SEL) = (BOOL (*)(id, SEL))objc_msgSend;
|
|
29
|
-
return msgSendBool((id)managerClass, sel);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
extern "C" void FaceAntiSpoofJSI_install(void *runtimePtr) {
|
|
33
|
-
#ifdef __cplusplus
|
|
34
|
-
if (!runtimePtr) {
|
|
35
|
-
NSLog(@"[FaceAntiSpoof] JSI install called with NULL runtime pointer");
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
jsi::Runtime *rt = reinterpret_cast<jsi::Runtime*>(runtimePtr);
|
|
40
|
-
if (!rt) {
|
|
41
|
-
NSLog(@"[FaceAntiSpoof] JSI install: invalid runtime pointer");
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
// Register faceAntiSpoof_isModelLoaded()
|
|
47
|
-
auto isLoadedFunc = jsi::Function::createFromHostFunction(*rt,
|
|
48
|
-
jsi::PropNameID::forAscii(*rt, "faceAntiSpoof_isModelLoaded"), 0,
|
|
49
|
-
[](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
|
|
50
|
-
bool loaded = FaceAntiSpoofManager_isModelLoaded();
|
|
51
|
-
return jsi::Value(loaded);
|
|
52
|
-
}
|
|
53
|
-
);
|
|
54
|
-
rt->global().setProperty(*rt, "faceAntiSpoof_isModelLoaded", isLoadedFunc);
|
|
55
|
-
|
|
56
|
-
// Register faceAntiSpoof_initialize()
|
|
57
|
-
auto initFunc = jsi::Function::createFromHostFunction(*rt,
|
|
58
|
-
jsi::PropNameID::forAscii(*rt, "faceAntiSpoof_initialize"), 0,
|
|
59
|
-
[](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
|
|
60
|
-
bool ok = FaceAntiSpoofManager_initialize();
|
|
61
|
-
return jsi::Value(ok);
|
|
62
|
-
}
|
|
63
|
-
);
|
|
64
|
-
rt->global().setProperty(*rt, "faceAntiSpoof_initialize", initFunc);
|
|
65
|
-
|
|
66
|
-
// Register faceAntiSpoof_getModuleInfo()
|
|
67
|
-
auto infoFunc = jsi::Function::createFromHostFunction(*rt,
|
|
68
|
-
jsi::PropNameID::forAscii(*rt, "faceAntiSpoof_getModuleInfo"), 0,
|
|
69
|
-
[](jsi::Runtime &rt, const jsi::Value &thisVal, const jsi::Value *args, size_t count) -> jsi::Value {
|
|
70
|
-
jsi::Object obj(rt);
|
|
71
|
-
obj.setProperty(rt, "name", jsi::String::createFromUtf8(rt, "FaceAntiSpoof"));
|
|
72
|
-
jsi::Array methods(rt, 4);
|
|
73
|
-
methods.setValueAtIndex(rt, 0, jsi::String::createFromUtf8(rt, "initialize"));
|
|
74
|
-
methods.setValueAtIndex(rt, 1, jsi::String::createFromUtf8(rt, "checkModelStatus"));
|
|
75
|
-
methods.setValueAtIndex(rt, 2, jsi::String::createFromUtf8(rt, "isAvailable"));
|
|
76
|
-
methods.setValueAtIndex(rt, 3, jsi::String::createFromUtf8(rt, "cleanup"));
|
|
77
|
-
obj.setProperty(rt, "methods", methods);
|
|
78
|
-
return obj;
|
|
79
|
-
}
|
|
80
|
-
);
|
|
81
|
-
rt->global().setProperty(*rt, "faceAntiSpoof_getModuleInfo", infoFunc);
|
|
82
|
-
|
|
83
|
-
NSLog(@"[FaceAntiSpoof] JSI functions registered");
|
|
84
|
-
} catch (const std::exception &ex) {
|
|
85
|
-
NSLog(@"[FaceAntiSpoof] JSI registration exception: %s", ex.what());
|
|
86
|
-
} catch (...) {
|
|
87
|
-
NSLog(@"[FaceAntiSpoof] JSI registration unknown exception");
|
|
88
|
-
}
|
|
89
|
-
#else
|
|
90
|
-
NSLog(@"[FaceAntiSpoof] JSI install compiled without C++ support");
|
|
91
|
-
#endif
|
|
92
|
-
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
#import <Foundation/Foundation.h>
|
|
2
|
-
#if __has_include(<VisionCamera/FrameProcessorPluginRegistry.h>)
|
|
3
|
-
#import <VisionCamera/FrameProcessorPluginRegistry.h>
|
|
4
|
-
#import <VisionCamera/FrameProcessorPlugin.h>
|
|
5
|
-
#import <VisionCamera/VisionCameraProxyHolder.h>
|
|
6
|
-
#define FACE_ANTISPOOF_HAS_VISION_CAMERA_HEADERS 1
|
|
7
|
-
#elif __has_include("FrameProcessorPluginRegistry.h")
|
|
8
|
-
#import "FrameProcessorPluginRegistry.h"
|
|
9
|
-
#import "FrameProcessorPlugin.h"
|
|
10
|
-
#import "VisionCameraProxyHolder.h"
|
|
11
|
-
#define FACE_ANTISPOOF_HAS_VISION_CAMERA_HEADERS 1
|
|
12
|
-
#endif
|
|
13
|
-
#import <objc/runtime.h>
|
|
14
|
-
#import <objc/message.h>
|
|
15
|
-
|
|
16
|
-
// Register after VisionCamera has loaded so its registry is available.
|
|
17
|
-
void FaceAntiSpoofRegisterPlugin(void) {
|
|
18
|
-
@autoreleasepool {
|
|
19
|
-
static BOOL registered = NO;
|
|
20
|
-
if (registered) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
#if FACE_ANTISPOOF_HAS_VISION_CAMERA_HEADERS
|
|
25
|
-
// Use a direct reference so the registry is linked in device builds.
|
|
26
|
-
[FrameProcessorPluginRegistry addFrameProcessorPlugin:@"faceAntiSpoof"
|
|
27
|
-
withInitializer:^FrameProcessorPlugin*(VisionCameraProxyHolder *proxy, NSDictionary *options) {
|
|
28
|
-
Class dynClass = NSClassFromString(@"FaceAntiSpoofFrameProcessor");
|
|
29
|
-
if (dynClass == Nil) {
|
|
30
|
-
return nil;
|
|
31
|
-
}
|
|
32
|
-
id alloced = ((id (*)(id, SEL))objc_msgSend)((id)dynClass, sel_registerName("alloc"));
|
|
33
|
-
SEL initSel = sel_registerName("initWithProxy:withOptions:");
|
|
34
|
-
if (![alloced respondsToSelector:initSel]) {
|
|
35
|
-
return nil;
|
|
36
|
-
}
|
|
37
|
-
return ((id (*)(id, SEL, id, id))objc_msgSend)(alloced, initSel, proxy, options);
|
|
38
|
-
}];
|
|
39
|
-
registered = YES;
|
|
40
|
-
#else
|
|
41
|
-
Class registry = NSClassFromString(@"FrameProcessorPluginRegistry");
|
|
42
|
-
|
|
43
|
-
if (registry == Nil) {
|
|
44
|
-
NSLog(@"[FaceAntiSpoof] VisionCamera registry is not loaded");
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
SEL selector = NSSelectorFromString(@"addFrameProcessorPlugin:withInitializer:");
|
|
49
|
-
if (![registry respondsToSelector:selector]) {
|
|
50
|
-
NSLog(@"[FaceAntiSpoof] VisionCamera registry API is unavailable");
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Create initializer block using objc_msgSend to avoid compile-time selector checks
|
|
55
|
-
id initializer = ^id(id proxy, id options) {
|
|
56
|
-
Class dynClass = NSClassFromString(@"FaceAntiSpoofFrameProcessor");
|
|
57
|
-
if (dynClass == Nil) {
|
|
58
|
-
return nil;
|
|
59
|
-
}
|
|
60
|
-
SEL allocSel = sel_registerName("alloc");
|
|
61
|
-
id alloced = ((id (*)(id, SEL))objc_msgSend)((id)dynClass, allocSel);
|
|
62
|
-
|
|
63
|
-
// VisionCamera's Objective-C initializer is `initWithProxy:withOptions:`.
|
|
64
|
-
SEL initSel = sel_registerName("initWithProxy:withOptions:");
|
|
65
|
-
if (![alloced respondsToSelector:initSel]) {
|
|
66
|
-
return nil;
|
|
67
|
-
}
|
|
68
|
-
id instance = ((id (*)(id, SEL, id, id))objc_msgSend)(alloced, initSel, proxy, options);
|
|
69
|
-
return instance;
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
// Call +addFrameProcessorPlugin:name with the block
|
|
73
|
-
// We use objc_msgSend to avoid compile-time dependency on the header signature
|
|
74
|
-
void (*msgSend)(id, SEL, id, id) = (void (*)(id, SEL, id, id))objc_msgSend;
|
|
75
|
-
msgSend((id)registry, selector, @"faceAntiSpoof", initializer);
|
|
76
|
-
registered = YES;
|
|
77
|
-
#endif
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Keep the old startup hook for apps where VisionCamera is already loaded.
|
|
82
|
-
__attribute__((constructor)) static void register_face_anti_spoof_plugin_at_load(void) {
|
|
83
|
-
FaceAntiSpoofRegisterPlugin();
|
|
84
|
-
}
|
|
Binary file
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
Pod::Spec.new do |s|
|
|
2
|
-
s.name = 'react-native-vision-camera-spoof-detector'
|
|
3
|
-
s.version = '1.1.0'
|
|
4
|
-
s.summary = 'Face anti-spoof detector for VisionCamera (iOS)'
|
|
5
|
-
s.homepage = 'https://github.com/dpraful/react-native-vision-camera-spoof-detector'
|
|
6
|
-
s.license = { :type => 'MIT', :file => 'LICENSE' }
|
|
7
|
-
s.authors = { 'JESCON TECHNOLOGIES PVT LTD' => 'jescontechnologies@gmail.com' }
|
|
8
|
-
s.platform = :ios, '11.0'
|
|
9
|
-
s.source = { :path => '.' }
|
|
10
|
-
|
|
11
|
-
s.swift_version = '5.0'
|
|
12
|
-
|
|
13
|
-
s.source_files = 'ios/**/*.{h,m,mm,swift,mm,cpp,c,cc}'
|
|
14
|
-
s.resources = ['ios/models/*']
|
|
15
|
-
|
|
16
|
-
# Dependencies
|
|
17
|
-
s.dependency 'TensorFlowLiteSwift'
|
|
18
|
-
s.dependency 'VisionCamera'
|
|
19
|
-
|
|
20
|
-
# Keep default deployment target and static linkage consistent with RN
|
|
21
|
-
s.pod_target_xcconfig = { 'EXCLUDED_ARCHS[sdk=iphonesimulator*]' => 'arm64' }
|
|
22
|
-
end
|
|
File without changes
|