Code
How to Run
1. Set Up React-Native Development Environment
2. How to run Android App
yarn
cd example
yarn android
3. How to run the iOS App
yarn
cd example
yarn
cd ios
pod install
And then, open the FaceRecognitionReactNative.xcworkspace
in Xcode
and run.
4. Install license
const initSDKAsync = async () => {
try {
if (Platform.OS == 'ios') {
var ret = await FaceSDKModule.setActivation(
'ZxU5Xu7XDitkVZ2y6ooEnkM2aianIE0MC8DncGam0djE+QHVQuNClk+9yJkEElg3zj6KSmloIUbcIYzayCmjdqT/qLCpNg4IHx4CuMOSHuafQLDFFSh/C3pU8sfAHn5f57dXKRPS73tSN52hTlQOZtl99J+47U8oShMmcruG6IdWKj//8ZQm3KkiOAxMZ7IOeoj3lRBnWPr4aZeLDTll9jtNqhIW5S1ElUI8R7ViJiJiHgw0FHwqkQAXXcoUly84HuDr4/W7OGNi7yBfOug21TNgCkHc5yaaerRzqEsAFq61YHlAFNmGhNFhscGEqPfROwcU1BLb1HwbrJQCsZJDjQ=='
);
console.log('set activation:', ret);
} else {
var ret = await FaceSDKModule.setActivation(
'EGH+RzwjnvhbtLxq49y1nDDSxguXUZPkgifx/9EGeg3qGrrnsZbP4/nQH1hE/BQyt86UqMByIaUuoqUvJORHPnJBOFSkEIEL4GX1FQjMzDZabA/V2HmkEaY9hAXlIkd4aDAdy7YI37hqfGgvsg8OgSi12aM7ScyHwzC/mbFkTSMHMM/+nB9aWBaO79nCSRWQfpOoQjh823fCwVIJc7YPLxJJjlPZaTASx1DPnoZ8qaCl7tVJpmGIwgTlJq/0ywLrok+q6usCkERqVGloab3O4YcfpZ1Pw7kvUjBvGsR5eWaMzS+xx1tlLvcv0F0pRhJeBRln+2Th57AeNMxXFLxfyQ=='
);
console.log('set activation:', ret);
}
API Usage
1. FaceSDKModule
Activate the FaceSDKModule
Call the setActivation
method:
var ret = await FaceSDKModule.setActivation("...");
console.log("set activation:", ret);
Initialize the FaceSDKModule
Call the initSDK
method:
var ret = await FaceSDKModule.initSDK();
Set Parameters
Use the setParam
method to configure settings:
var ret = await FaceSDKModule.setParam(checkLivenessLevel);
Use the extractFaces
method to detect and extract faces from an image:
var faceBoxes = await FaceSDKModule.extractFaces(uri);
Calculate Face Similarity
Compare two face templates using the similarityCalculation
method:
const similarity = await FaceSDKModule.similarityCalculation(
face.templates,
person.templates
);
2. Working with camera stream
Build the Camera Screen & Process Face Detection
To implement the native camera and process face detection, refer to the example/src/FaceRecognitionPage.tsx
file in the repository.
<FaceRecognitionSdkView style={styles.box} livenessLevel={1} cameraLens={1} />
Get Face Detection Results
Use the following code to listen for face detection events:
const eventEmitter = new NativeEventEmitter(FaceSDKModule);
let eventListener = eventEmitter.addListener('onFaceDetected', (event) => {
setFaces(event);
if (recognized == false) {
identifyPerson(event);
}
});
Start & Stop the Camera
Start Camera
const startCamera = async () => {
await FaceSDKModule.startCamera();
}
Stop Camera
const stopCamera = async () => {
await FaceSDKModule.stopCamera();
}