Last updated:
0 purchases
flutter bdface plugin
flutter_bdface_plugin #
A new Flutter plugin.
百度人脸识别离线采集SDK封装。实现了Android和 Ios 两端使用。
本插件基于百度离线采集SDK(SDK下载日期:2020-12-15)。
实现过程参考了插件baidu_face_plugin。
Getting Started #
This project is a starting point for a Flutter
plug-in package,
a specialized package that includes platform-specific implementation code for
Android and/or iOS.
For help getting started with Flutter, view our
online documentation, which offers tutorials,
samples, guidance on mobile development, and a full API reference.
一.安卓初始化和配置 #
1 . 在实际项目中增加入口 application class
FaceSDKManager.getInstance().initialize 传入自己申请到的授权文件(修改字符串miaomumu-face-android)
demo代码
public class MainApplication extends FlutterApplication {
@Override
public void onCreate() {
super.onCreate();
initFacePlugin();
}
private void initFacePlugin() {
// 初始化SDK
FaceSDKManager.getInstance().initialize(this, "miaomumu-face-android",
"idl-license.face-android", new IInitCallback() {
@Override
public void initSuccess() {
Log.e("baidu", "初始化成功");
}
@Override
public void initFailure(final int errCode, final String errMsg) {
Log.e("baidu", "初始化失败 = " + errCode + " " + errMsg);
}
});
// 随机动作
Config.isLivenessRandom = true;
// 根据需求添加活体动作
Config.livenessList.clear();
Config.livenessList.add(LivenessTypeEnum.Eye);
// TODO test// Config.livenessList.add(LivenessTypeEnum.Mouth);// Config.livenessList.add(LivenessTypeEnum.HeadUp);// Config.livenessList.add(LivenessTypeEnum.HeadDown);// Config.livenessList.add(LivenessTypeEnum.HeadLeft);// Config.livenessList.add(LivenessTypeEnum.HeadRight);// Config.livenessList.add(LivenessTypeEnum.HeadLeftOrRight);
// 设置 FaceConfig
FaceConfig config = FaceSDKManager.getInstance().getFaceConfig();
// 设置可检测的最小人脸阈值
config.setMinFaceSize(FaceEnvironment.VALUE_MIN_FACE_SIZE);
// 设置可检测到人脸的阈值
config.setNotFaceValue(FaceEnvironment.VALUE_NOT_FACE_THRESHOLD);
// 设置模糊度阈值
config.setBlurnessValue(FaceEnvironment.VALUE_BLURNESS);
// 设置光照阈值(范围0-255)
config.setBrightnessValue(FaceEnvironment.VALUE_BRIGHTNESS);
// 设置遮挡阈值
config.setOcclusionValue(FaceEnvironment.VALUE_OCCLUSION);
// 设置人脸姿态角阈值
config.setHeadPitchValue(FaceEnvironment.VALUE_HEAD_PITCH);
config.setHeadYawValue(FaceEnvironment.VALUE_HEAD_YAW);
// 设置闭眼阈值
config.setEyeClosedValue(FaceEnvironment.VALUE_CLOSE_EYES);
// 设置图片缓存数量
config.setCacheImageNum(FaceEnvironment.VALUE_CACHE_IMAGE_NUM);
// 设置活体动作,通过设置list,LivenessTypeEunm.Eye, LivenessTypeEunm.Mouth,
// LivenessTypeEunm.HeadUp, LivenessTypeEunm.HeadDown, LivenessTypeEunm.HeadLeft,
// LivenessTypeEunm.HeadRight, LivenessTypeEunm.HeadLeftOrRight
config.setLivenessTypeList(Config.livenessList);
// 设置动作活体是否随机
config.setLivenessRandom(Config.isLivenessRandom);
// 设置开启提示音
config.setSound(true);
// 原图缩放系数
config.setScale(FaceEnvironment.VALUE_SCALE);
// 抠图高的设定,为了保证好的抠图效果,我们要求高宽比是4:3,所以会在内部进行计算,只需要传入高即可
config.setCropHeight(FaceEnvironment.VALUE_CROP_HEIGHT);
// 加密类型,0:Base64加密,上传时image_sec传false;1:百度加密文件加密,上传时image_sec传true
config.setSecType(FaceEnvironment.VALUE_SEC_TYPE);
FaceSDKManager.getInstance().setFaceConfig(config);
// 初始化资源文件
FaceSDKResSettings.initializeResId();
}}
copied to clipboard
2 .修改实际项目 AndroidManifest.xml 的入口application 节点添加android:name=".MainApplication"
二.IOS初始化和配置 #
导入项目资源文件。(下载demo中的 bundle, 图片文件,授权文件)
if(Platform.isIOS){
new FlutterBdfacePlugin().initIosSdk("xxx-face-ios");
}
copied to clipboard
调用方式同安卓,无需再进行其它配置
copied to clipboard
三.可能遇到的问题 #
与百度地图库冲突,如 com.baidu.a.a.a.a.a 错误。 删除flutter_bmfutils 依赖, 执行 flutter clean,重新 build.
安卓闪退问题,检查授权文件是否正确导入,SDK 是否初始化成功。目前 Android 只在 Application 中初始化。
Android release 代码混淆问题 -keep class com.example.flutter_bdface_plugin.** {*;}
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.