react-native-facesdk
v1.0.3
Published
test
Downloads
225
Readme
react-native-facesdk
百度和云从人脸识别的封装
安装
npm install react-native-facesdk
使用
- 添加 Android 权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
- 使用模块和组件
import * as React from 'react';
import { useEffect, useState } from 'react';
import { StyleSheet, View, NativeSyntheticEvent } from 'react-native';
import {
FaceDetectResult,
FaceSDK,
FaceView,
SDKType,
} from 'react-native-facesdk';
function App() {
const [initSuccess, setInitSuccess] = useState(false);
useEffect(() => {
const init = async () => {
// await FaceSDK.sharedInstance.init({
// type: SDKType.CLOUDWALK,
// });
await FaceSDK.sharedInstance.init({
type: SDKType.BAIDU,
license: 'N6GG-8QFB-AGAY-XDKU',
});
const localUsers = await FaceSDK.sharedInstance.getAllUsers();
console.log('localUsers', localUsers);
await FaceSDK.sharedInstance.clearDatabase();
const users = [
{
groupId: '0',
userId: '0',
userName: '0',
faceImageUrl:
'https://nb-remote-totalinfo.oss-cn-beijing.aliyuncs.com/d78f8c71456f49a0b2524aca82571470.png',
},
];
const { successList, failureList } =
await FaceSDK.sharedInstance.batchImportUser(users);
console.log('批量导入完成');
console.log(successList);
console.log(failureList);
const localUsers2 = await FaceSDK.sharedInstance.getAllUsers();
console.log('localUsers2', localUsers2);
setInitSuccess(true);
};
init();
return () => {
FaceSDK.sharedInstance.destroy();
};
}, []);
const onFaceDetectResult = (e: NativeSyntheticEvent<FaceDetectResult>) => {
console.log(e.nativeEvent);
};
return (
<View style={styles.container}>
{initSuccess && (
<FaceView
style={styles.container}
type={SDKType.CLOUDWALK}
onFaceDetectResult={onFaceDetectResult}
/>
)}
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#000',
},
});