本发明涉及人脸识别技术领域,特别涉及一种基于ai实现快速采集药店会员数据方法。
背景技术:
人脸识别,特指利用分析比较人脸视觉特征信息进行身份鉴别的计算机技术。人脸识别是用摄像机或摄像头采集含有人脸的图像或视频流,并自动在图像中检测和跟踪人脸,进而对检测到的人脸进行脸部的一系列相关技术,通常也叫做人像识别、面部识别。
“人脸识别系统”集成了人工智能、机器识别、机器学习、模型理论、专家系统、视频图像处理等多种专业技术,其核心技术的实现,展现了弱人工智能向强人工智能的转化。
当前面临的问题:传统会员资料采集无法采集到会员头像,并且效率低下。无法在消费者卖药的同时快速采集。
技术实现要素:
本发明解决的技术问题在于提供基于人脸识别技术的会员资料采集方法,解决了传统会员资料采集效率低、实时性低、成本高等问题。
本发明解决上述技术问题的技术方案是:
所述的方法包含以下几个步骤:
步骤一、创建表单,定义会员名称、手机号输入框;
步骤二、设置按钮,点击时调用摄像头进行拍摄并存为图片格式;
步骤三、将图片数据异步提交到服务器;
步骤四、服务器调用百度人脸识别api,发送图片数据;
步骤五、解析返回的数据,验证拍摄的人脸是否符合标准;
步骤六、提交表单,保存采集的数据,完成会员资料采集。
本发明的有益效果:本发明基于人脸识别技术实现了快速采集、成本低、实时且高效的方法。
附图说明
下面结合附图对本发明进一步说明:
图1为本发明的方法流程图。
具体实施方式
如图1所示,本发明采用如下步骤可以实现会员资料的快速采集:
步骤一、创建表单,定义会员名称、手机号输入框;
<formaction=""method="post"id="editform">
<inputtype="text"class="col-xs-12form-controlpinput"placeholder="会员名称"name="membername"value="">
<inputtype="text"class="col-xs-12form-controlpinput"maxlength="11"placeholder="手机号"name="mobile"value="">
</form>
步骤二、设置按钮,点击时调用摄像头进行拍摄并存为图片格式;
$("#btnpaface").on("click",function(){
resmsg.removeclass("redsuccesscolor").addclass("skyblue").children(".resshowmsg").text("正在上传图片,请稍后...");
context.drawimage(video,0,0,430,290);
vardataurl=canvas1.todataurl("image/png",1.0);
uploadimg(dataurl);
});
步骤三、将图片数据异步提交到服务器;
functionuploadimg(dataurl){
varpostdata={};
postdata['filestr']=dataurl;
$.ajax({
type:"post",
url:setcustom.posturl,
data:postdata,
datatype:"json",
success:function(result){
if(result.statuscode==200){
resmsg.removeclass("redskyblue").addclass("successcolor").children(".resshowmsg").text("拍照成功,支持多张。");
imggroup.append("<divclass='img-item'><imgsrc='"+dataurl+"'/><iclass='glyphiconglyphicon-removeclosei'></i></div>");
imgurlarr.push(dataurl);
}else{
resmsg.removeclass("successcolorskyblue").addclass("red").children(".resshowmsg").text("拍照失败,请重新点击拍照按钮拍照。");
}
},
error:function(){
alert("图片未知错误!");
}
});
}
步骤四、服务器调用百度人脸识别api,发送图片数据;
hashmap<string,string>options=newhashmap<string,string>();
options.put("max_face_num","1");
options.put("face_fields","qualities,faceliveness");
jsonobjectjsonobject=client.detect(arrayutils.toprimitive(imagedatas),options);
步骤五、解析返回的数据,验证拍摄的人脸是否符合标准;
jsonobjectjsonobject=newjsonobject(res);
jsonobjectvalidateresult=newjsonobject();
if(!jsonobject.isnull("result")&&jsonobject.getjsonarray("result").length()>0){
jsonobjectresultobject=jsonobject.getjsonarray("result").getjsonobject(0);
if(resultobject.length()>0){
doubleblurvalue=double.valueof(resultobject.getjsonobject("qualities").get("blur").tostring());
if(blurvalue>=0.7){
validateresult.put("blur",blurvalue);
validateresult.put("standard",0.7);
validateresult.put("type","lt");
validateresult.put("errortext","模糊度过高,请重新拍摄");
returnvalidateresult.tostring();
}
integercompleteness=resultobject.getjsonobject("qualities").getint("completeness");
if(completeness!=1){
validateresult.put("completeness",0);
validateresult.put("standard",1);
validateresult.put("type","eq");
validateresult.put("errortext","当前获取的人脸不完整,请对准摄像头");
returnvalidateresult.tostring();
}
integerwidth=resultobject.getjsonobject("location").getint("width");
integerheight=resultobject.getjsonobject("location").getint("height");
if(width<100||height<100){
validateresult.put("size",width+"*"+height);
validateresult.put("standard","100*100");
validateresult.put("type","ge");
validateresult.put("errortext","范围过小,请靠近摄像头");
returnvalidateresult.tostring();
}
if(faceliveness){
doublefacelivenessvalue=double.valueof(resultobject.get("faceliveness").tostring());
if(facelivenessvalue<faceliveness_value_limit){
validateresult.put("faceliveness",facelivenessvalue);
validateresult.put("standard",faceliveness_value_limit);
validateresult.put("type","ge");
validateresult.put("errortext","请在现场抓拍!");
returnvalidateresult.tostring();
}
}
return"success";
}
}
validateresult.append("imagetype","nonsupport");
validateresult.put("errortext","请将您的脸部对准摄像头!");
步骤六、提交表单,保存采集的数据,完成会员资料采集;
$("#addmenber").click(function(){
varform=$("#editform");
form.removedata("validator").removedata("unobtrusivevalidation");
$.validator.unobtrusive.parse(form);
if(!form.validform()){
returnfalse;
}
if(form.valid()){
varpara=form.serializearray();
varfacepass=true;
$.each($('#content-item').find(".item-list"),function(index,childobj){
varvalidate=$(childobj).find(".validate").text();
if(validate=="fail"){
$("#uploadimageinfotext").css("color","#ff0000").text("存在不符合要求的照片!");
facepass=false;
returnfalse;
}
varimgpara=newobject();
varimgparavalue=$(childobj).find("img").attr("src");
imgpara.name="filestr";
imgpara.value=imgparavalue;
para.push(imgpara);
})
if(!facepass)
returnfalse;
$.ajax({
url:"${ctx}/base/member/shortcut_insert.action",
data:para,
type:"post",
success:function(json){
json=json||{};
if(json.statuscode==200){
msgalert("提示","提交成功!","success");
$("#facemodal").izimodal('close');
}else{
msgalert("错误",json.msg,"error");
}
}
});
}
})。