基本信息
源码名称:JAVA调用百度接口实现人脸识别(完整代码+相关jar包)
源码大小:1.02M
文件格式:.zip
开发语言:Java
更新时间:2019-05-01
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
调用百度接口实现人脸信息的入库、查询、更新、删除、识别
调用百度接口实现人脸信息的入库、查询、更新、删除、识别
package com.creating.FaceRecognition;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import org.apache.commons.lang.exception.ExceptionUtils;
import net.sf.json.JSONObject;
/**
*
* @author chenxianj
* 20180107
*调用百度提供的人脸识别接口进行人脸信息的
*入库、检测、识别、库中人脸修改、库中人脸
*删除以及相关查询
*/
public class FacebaiduMain {
/**
* chenxianj 20170117
*人脸信息处理的主方法:向外部提供该方法,
*通过传过来的标志进行相关方法的调用
*imgStr:人脸信息,经base64转码后的
*faceflag:人脸信息处理标志,如下
*detect:人脸信息检测
*add:向人脸库中增加人脸信息
*recognition:人脸识别,判断指定人脸是否在人脸库中
*update:修改库中已存在的人脸信息
*delete:删除库中指定人脸信息
*select:查询库中指定人脸信息
* @throws Exception
* @throws UnsupportedEncodingException
*/
public void Faceinfomain(String faceflag,String imgStr,String uid,String userinfo) throws Exception{
try {
//人脸处理类
FacebaiduDeal facedeal = new FacebaiduDeal();
String imgParam = null;
if(faceflag.equals("detect")||faceflag.equals("add")||faceflag.equals("recognition")||faceflag.equals("update")){
if(imgStr==null){
throw new Exception("人脸信息不能为空!");
}
imgParam = URLEncoder.encode(imgStr, "UTF-8");
}
//人脸检测,imgParam
if(faceflag.equals("detect")){
facedeal.detect(imgParam);
}
//人脸信息入人脸库
if(faceflag.equals("add")){
//入库之前先检测下人脸信息是否合规
facedeal.detect(imgParam);
JSONObject jsonObject = facedeal.faceadd(imgParam, uid, userinfo);
if(jsonObject==null){
throw new Exception("脸部信息入库失败!");
}
String errorcode = jsonObject.optString("error_code");
if(!errorcode.equals("")){
String errormsg = jsonObject.optString("error_msg");
System.out.println("errormsg:" errormsg);
throw new Exception("脸部信息入库失败!报错信息为:" errormsg);
}
}
//人脸信息识别,判断指定人脸是否在人脸库中
if(faceflag.equals("recognition")){
JSONObject jsonjt = facedeal.facerecognition(imgParam);
if(jsonjt.optJSONArray("result")!=null){
JSONObject jsonObjectd = JSONObject.fromObject(jsonjt.optJSONArray("result").get(0));
String group_id = jsonObjectd.optString("group_id");
String uidkc = jsonObjectd.optString("uid");
String user_info = jsonObjectd.optString("user_info");
String[] jsscores = jsonObjectd.optString("scores").replace("[", "").replace("]","").split(",");
double scores = Double.valueOf(jsscores[0]);
if(scores<80){
throw new Exception("该人脸信息在人脸库中不存在!");
}
System.out.println("group_id:" group_id);
System.out.println("uidkc:" uidkc);
System.out.println("user_info:" user_info);
System.out.println("scores:" scores);
}else{
String errorcode = jsonjt.optString("error_msg");
System.out.println("errorcode:" errorcode);
}
}
//人脸信息更新
if(faceflag.equals("update")){
//入库之前先检测下人脸信息是否合规
facedeal.detect(imgParam);
JSONObject jsonObject = facedeal.faceupdate(imgParam, userinfo,uid);
String errorcode = jsonObject.optString("error_code");
if(errorcode!=null){
String errormsg = jsonObject.optString("error_msg");
System.out.println("errormsg:" errormsg);
}
jsonObject.optDouble("log_id");
}
//人脸信息删除
if(faceflag.equals("delete")){
JSONObject jsonObject = facedeal.facedelete(uid);
String errorcode = jsonObject.optString("error_code");
if(errorcode!=null){
String errormsg = jsonObject.optString("error_msg");
System.out.println("errormsg:" errormsg);
}
jsonObject.optDouble("log_id");
}
//人脸信息查询
if(faceflag.equals("select")){
JSONObject sjson = facedeal.faceselect(uid);
if(sjson.optJSONObject("result")!=null){
JSONObject jsonObjectd = JSONObject.fromObject(sjson.optJSONObject("result").get(0));
String group_id = jsonObjectd.optString("group_id");
String uidkc = jsonObjectd.optString("uid");
String user_info = jsonObjectd.optString("user_info");
System.out.println("group_id:" group_id);
System.out.println("uidkc:" uidkc);
System.out.println("user_info:" user_info);
}else{
String errorcode = sjson.optString("error_msg");
System.out.println("errorcode:" errorcode);
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
throw new Exception(ExceptionUtils.getStackTrace(e));
}
}
}