android项目实战-人脸识别接口应用
1.face++接口:
https://www.faceplusplus.com.cn/
2.源码:
https://gitee.com/zouchengxin/analyze_face
3.效果:
http://39.106.207.193:8080/analyze_face.mp4
4.App下载:
https://gitee.com/zouchengxin/analyze_face/blob/master/app/release/app-release.apk
5.代码解读:
FaceUtils.java
主要用来调用face++ Detect和Beautify接口并与DetectActivity和BeautyActivity通讯
public class FaceUtils {
private String TAG="FaceUtils";
private String api_key="_XkXB2jly_0ZteVlGNxI8cT6S8XE4Gnj";
private String api_secret="guR94t2Pwg_0DKNTyt3QPe7iAQBuCtpa";
private FacePPApi faceApi;
public FaceUtils(){
faceApi=new FacePPApi(api_key,api_secret);
}
//传入图片进行人脸检测和人脸分析
public void detect_face(final AppCompatActivity activity, byte[] img){
Map<String,String> map=new HashMap<>();
map.put("return_landmark","1");
map.put("return_attributes","gender,age,smiling,headpose,facequality,blur,eyestatus,emotion,ethnicity,beauty,mouthstatus,eyegaze,skinstatus");
faceApi.detect(map,img,new IFacePPCallBack<DetectResponse>() {
@Override
public void onSuccess(DetectResponse detectResponse) {
String error = detectResponse.getError_message();
if(error!=null){
Toast.makeText(activity,error,Toast.LENGTH_LONG).show();
Log.e(TAG,error);
return;
}
System.out.println("detect:"+detectResponse.toString());
Intent intent=new Intent();
intent.setClass(activity,DetectActivity.class);
ImageResource.getInstance().setDetectResponse(detectResponse);
//intent.putExtra("data", JSONObject.toJSONString(detectResponse));
activity.startActivityForResult(intent,2);