代码拉取完成,页面将自动刷新
Android Face SDK 接口说明文档
public class FaceAPI {
/**
* 初始化人脸引擎
* 返回true 正确,返回其它值错误
* */
public boolean initial();
/**
* 人脸检测(包含检测、特征提取、人脸防伪【可选,返回face.spoofingScore】)
* 返回结果中包含人脸框的位置,人脸的特征feature,用来与其它人脸照片的feature进行比对,即可得出两张脸的相似度。
* 将多个人脸的feature及对应的faceid存储到sdcard中,就完成了人脸的注册功能,即1:N中的N。
*
* 如果购买的是带有人脸防伪的SDK,在运行完face_detect后,人脸真伪的值存储于 Face.spoofingScore中。
* if face.spoofingScore > 0.95
* System.out.println("假脸");
* else
* System.out.println("真脸");
* */
public Face face_detect(byte[] NV21_data , int width, int height);
/**
* 比对人脸特征
* 对face_detect返回结果中的feature进行比对,得到两个feature(即两张人脸)的相似度。
*
* 对已经注册的人脸特征进行循环比对,选择最高分数的人脸,if score > Threshold((0,1)根据场景选择该值,推荐0.9) 即可认为是识别到了目标脸
* */
public float compare2feature(byte[] fea1, byte[] fea2);
/**
* 计算两个照片的相似度
* 返回两个照片的相似度(0,1)
* */
public float compare2Image(String file1, String file2);
/**
* 人脸License检测接口
* @return true or false
*/
public static native boolean check();
/**
* 获取Android硬件指纹码接口
* @return 32位的string 码
*/
public static native String getCode();
}
调用Demo
//初始化人脸引擎
com.face.faceantispoofing.FaceAPI faceapi = new com.face.faceantispoofing.FaceAPI();
boolean ret = faceapi.initial();
if (!ret){
Log.e("error"," initial failed.");
}
//人脸检测 + 特征提取
Bitmap bmp = BitmapFactory.decodeFile("/sdcard/1.png");
//ImageFormat.NV21
byte[] mImageNV21 =getNV21(bmp.getWidth() , bmp.getHeight(),bmp);
int width = bmp.getWidth();
int height = bmp.getHeight();
com.face.faceantispoofing.Face face = faceapi.face_detect(data,width,height);
if (face == null) {
Log.i("okface", "noface");
return
}
//选购了带防伪的SDK具备一下人脸真伪的检测功能
float hackerScore = face.spoofingScore;
Log.i("okface", "" + hackerScore);
if (hackerScore > 0.95F) {
Log.e("okface", "假脸");
}
byte[] feature = face.feature;
//将提取的人脸特征 feature 保存下来(存储到sdcard上),关联业务系统的人脸ID,
//再利用 api.compare2feature(byte[] fea1, byte[] fea2) 对两个人脸的特征进行比对,即可获取两个照片的相似度
// for( i =0; i < features.length(); i++){
// score = api.compare2feature(features[i],feature) //保留最高的相似度,如果相似度大于0.9(这个值可以根据场景选择合适的阈值)就可以推测两个脸非常的像。
// }
//比对两张照片的相似度
String file1 = "/sdcard/okface/1.jpg";
String file2 = "/sdcard/okface/2.jpg";
float score = faceapi.compare2Image(file1,file2);
Log.i("score", "socre is "+ score);
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。