ArcSoft Face React Native is a powerful React Native library that integrates ArcSoft's face recognition SDK, providing comprehensive face detection, recognition, and analysis capabilities for mobile applications.
- 🔍 Face Detection: Detect faces in images with high accuracy
- 🆔 Face Recognition: Extract and compare facial features for identification
- 👤 Liveness Detection: Verify if the detected face is from a live person
- 📊 Age Detection: Estimate the age of detected faces
- 👥 Gender Detection: Determine the gender of detected faces
- 🚀 High Performance: Optimized for mobile devices
- 📱 Cross Platform: Supports both iOS and Android
npm install arcsoft-face-react-nativeor
yarn add arcsoft-face-react-native- React Native >= 0.60
- Android API Level >= 21
- ArcSoft Face SDK License (required for production use)
Add the following permissions to your android/app/src/main/AndroidManifest.xml:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />Add the following to your ios/YourApp/Info.plist:
<key>NSCameraUsageDescription</key>
<string>This app needs access to camera for face recognition</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>This app needs access to photo library for face recognition</string>-
Get ArcSoft SDK License
- Visit ArcSoft Official Website
- Register and obtain your
APP_IDandSDK_KEY
-
Native Module Configuration
- For React Native >= 0.60, auto-linking is supported
- For older versions, manual linking may be required
import ArcsoftFace from "arcsoft-face-react-native";
const initializeSDK = async () => {
try {
const success = await ArcsoftFace.init(
"YOUR_APP_ID", // Replace with your APP_ID
"YOUR_SDK_KEY", // Replace with your SDK_KEY
"YOUR_ACTIVE_KEY" // Optional: leave empty for online activation
);
if (success) {
console.log("ArcSoft SDK initialized successfully");
}
} catch (error) {
console.error("SDK initialization failed:", error);
}
};const detectFaces = async (imagePath) => {
try {
const faces = await ArcsoftFace.detectFaces(imagePath);
console.log("Detected faces:", faces);
// faces array contains face information:
// - rect: face bounding box coordinates
// - orient: face orientation
// - faceId: unique face identifier
} catch (error) {
console.error("Face detection failed:", error);
}
};const extractFaceFeature = async (imagePath) => {
try {
// extractType: 0 for registration, 1 for recognition
const feature = await ArcsoftFace.extractFeature(imagePath, 0);
if (feature) {
console.log("Face feature extracted");
// Store the feature for later comparison
return feature;
}
} catch (error) {
console.error("Feature extraction failed:", error);
}
};const compareFaces = async (feature1, feature2) => {
try {
const similarity = await ArcsoftFace.compareFaces(feature1, feature2);
console.log("Face similarity:", similarity);
// similarity ranges from 0 to 1
// typically, similarity > 0.8 indicates same person
if (similarity > 0.8) {
console.log("Faces match!");
} else {
console.log("Faces do not match");
}
} catch (error) {
console.error("Face comparison failed:", error);
}
};const checkLiveness = async (imagePath) => {
try {
const isLive = await ArcsoftFace.livenessDetection(imagePath);
if (isLive) {
console.log("Live person detected");
} else {
console.log("Not a live person");
}
} catch (error) {
console.error("Liveness detection failed:", error);
}
};const analyzeface = async (imagePath) => {
try {
const age = await ArcsoftFace.detectAge(imagePath);
const gender = await ArcsoftFace.detectGender(imagePath);
console.log(`Detected age: ${age}`);
console.log(`Detected gender: ${gender}`); // 'male' or 'female'
} catch (error) {
console.error("Face analysis failed:", error);
}
};const cleanup = async () => {
try {
await ArcsoftFace.uninit();
console.log("SDK cleanup completed");
} catch (error) {
console.error("Cleanup failed:", error);
}
};import React, { useEffect, useState } from "react";
import { View, Button, Text, Alert } from "react-native";
import ArcsoftFace from "arcsoft-face-react-native";
import { launchImageLibrary } from "react-native-image-picker";
const FaceRecognitionApp = () => {
const [isInitialized, setIsInitialized] = useState(false);
const [storedFeature, setStoredFeature] = useState(null);
useEffect(() => {
initializeSDK();
return () => {
ArcsoftFace.uninit();
};
}, []);
const initializeSDK = async () => {
try {
const success = await ArcsoftFace.init("YOUR_APP_ID", "YOUR_SDK_KEY", "");
setIsInitialized(success);
} catch (error) {
Alert.alert("Error", "Failed to initialize SDK");
}
};
const selectImageAndDetect = () => {
launchImageLibrary({ mediaType: "photo" }, async (response) => {
if (response.assets && response.assets[0]) {
const imagePath = response.assets[0].uri;
// Detect faces
const faces = await ArcsoftFace.detectFaces(imagePath);
if (faces.length > 0) {
// Extract feature
const feature = await ArcsoftFace.extractFeature(imagePath, 0);
setStoredFeature(feature);
// Analyze face
const age = await ArcsoftFace.detectAge(imagePath);
const gender = await ArcsoftFace.detectGender(imagePath);
Alert.alert(
"Face Analysis",
`Faces detected: ${faces.length}\nAge: ${age}\nGender: ${gender}`
);
} else {
Alert.alert("No Face", "No faces detected in the image");
}
}
});
};
const selectImageAndCompare = () => {
if (!storedFeature) {
Alert.alert("Error", "Please register a face first");
return;
}
launchImageLibrary({ mediaType: "photo" }, async (response) => {
if (response.assets && response.assets[0]) {
const imagePath = response.assets[0].uri;
const feature = await ArcsoftFace.extractFeature(imagePath, 1);
if (feature) {
const similarity = await ArcsoftFace.compareFaces(
storedFeature,
feature
);
const isMatch = similarity > 0.8;
Alert.alert(
"Face Comparison",
`Similarity: ${(similarity * 100).toFixed(2)}%\n${
isMatch ? "Match!" : "No match"
}`
);
}
}
});
};
return (
<View style={{ flex: 1, justifyContent: "center", padding: 20 }}>
<Text style={{ textAlign: "center", marginBottom: 20 }}>
SDK Status: {isInitialized ? "Initialized" : "Not Initialized"}
</Text>
<Button
title="Register Face"
onPress={selectImageAndDetect}
disabled={!isInitialized}
/>
<View style={{ marginVertical: 10 }} />
<Button
title="Verify Face"
onPress={selectImageAndCompare}
disabled={!isInitialized || !storedFeature}
/>
</View>
);
};
export default FaceRecognitionApp;| Method | Parameters | Return Type | Description |
|---|---|---|---|
init(appId, sdkKey, activeKey?) |
string, string, string? |
Promise<boolean> |
Initialize the SDK |
uninit() |
- | Promise<boolean> |
Uninitialize the SDK |
detectFaces(imagePath) |
string |
Promise<Array> |
Detect faces in image |
extractFeature(imagePath, extractType) |
string, number |
Promise<string> |
Extract face feature |
compareFaces(feature1, feature2) |
string, string |
Promise<number> |
Compare face features |
livenessDetection(imagePath) |
string |
Promise<boolean> |
Detect if face is live |
detectAge(imagePath) |
string |
Promise<number> |
Detect age |
detectGender(imagePath) |
string |
Promise<string> |
Detect gender |
Common error codes and solutions:
- 90114: Invalid APP_ID or SDK_KEY
- 90115: SDK not activated
- 90116: Insufficient memory
- 90117: Invalid image format
- 90118: No face detected
- Image Optimization: Use appropriate image sizes (recommended: 640x480 or smaller)
- Feature Caching: Store extracted features in local database for better performance
- Background Processing: Perform face operations on background threads
- Memory Management: Call
uninit()when the SDK is no longer needed
-
Build Issues
- Ensure proper native dependencies are linked
- Check Android/iOS minimum version requirements
-
Runtime Errors
- Verify SDK license validity
- Check image file permissions and format
-
Performance Issues
- Optimize image sizes
- Use appropriate detection parameters
This project is licensed under the ISC License.
For technical support and questions:
- Create an issue on GitHub
- Contact ArcSoft support for SDK-related questions
We welcome contributions! Please see our Contributing Guide for details.
See CHANGELOG.md for a list of changes.