/// <summary> /// 刷脸认证 /// </summary> /// <param name="reqData"></param> /// <returns></returns> public XAIResAuth Auth(XAIReqAuth reqData) { var image_list = new List <BIDUImageInfo>(); var QualityControl = "QualityControl".ConfigValue(); var LivenessControl = "LivenessControl".ConfigValue(); reqData.Images.ForEach(f => { var image = new BIDUImageInfo() { image = f.Image.Split(new string[] { ";base64," }, StringSplitOptions.RemoveEmptyEntries)[1], image_type = "BASE64", face_type = f.Kind == "1" ? "LIVE" : f.Kind == "2" ? "IDCARD" : f.Kind, quality_control = QualityControl.IsNullOrEmptyOfVar() ? "NORMAL" : QualityControl, liveness_control = (f.Kind == "LIVE" && !LivenessControl.IsNullOrEmptyOfVar()) ? LivenessControl : "NONE" }; image_list.Add(image); }); LogModule.Info("XAI->BIDU:Auth--->入参:" + reqData.ToJson()); string resJson; try { resJson = client.Match(JArray.Parse(image_list.ToJson())).ToJson(); } catch (Exception ex) { throw new XAIException(7100, "请求人脸识别服务异常,请重试!" + ex.Message); } LogModule.Info("XAI->BIDU:Auth--->出参:" + resJson); var res = resJson.ToEntity <BIDUResponse>(); if (res.error_code != 0) { throw new XAIException(7100, typeof(BIDUErrorCodeEnum).GetEnumName(res.error_code.ToInt())); } if (res.result.score < 80) { throw new XAIException(7101, "图片对比阈值过低,对比失败!"); } return(new XAIResAuth() { AuthId = res.log_id, FaceTokenList = res.result.face_list.Select(s => s.face_token).ToList(), PaperWorkNo = reqData.UserInfo.PaperWorkNo, PhoneNo = reqData.UserInfo.PhoneNo, UserId = reqData.UserId }); }
private void button_diff_Click(object sender, RoutedEventArgs e) { try { var faces = new JArray { new JObject { { "image", ReadImg(m_imgPath1) }, { "image_type", "BASE64" }, { "face_type", "LIVE" }, { "quality_control", "LOW" }, { "liveness_control", "NONE" }, }, new JObject { { "image", ReadImg(m_imgPath2) }, { "image_type", "BASE64" }, { "face_type", "LIVE" }, { "quality_control", "LOW" }, { "liveness_control", "NONE" }, } }; var result = mClient.Match(faces); var score = (float)result["result"]["score"]; var list_faceinfo = new List <string>(); if (score > 50) { list_faceinfo.Add("像"); } else { list_faceinfo.Add("不像"); } list_faceinfo.Add(String.Format("得分:{0}", score)); textBox_diff.Text = string.Join("\n", list_faceinfo); } catch (Exception exception) { MessageBox.Show(exception.Message, "错误"); } }
/// <summary> /// 匹配 /// </summary> /// <param name="sourceImage"></param> /// <param name="matchImage"></param> /// <returns></returns> public JObject NetTwoFaceMatch(Image sourceImage, Image matchImage) { try { var client = new Baidu.Aip.Face.Face(API_KEY, SECRET_KEY) { Timeout = 60000 // 修改超时时间 }; string sourceData = ImageToBase64(sourceImage); string matchData = ImageToBase64(matchImage); JArray faces = new JArray { new JObject { { "image", sourceData }, { "image_type", "BASE64" }, { "face_type", "LIVE" }, { "quality_control", "LOW" }, { "liveness_control", "NONE" }, }, new JObject { { "image", matchData }, { "image_type", "BASE64" }, { "face_type", "LIVE" }, { "quality_control", "LOW" }, { "liveness_control", "NONE" }, } }; JObject result = client.Match(faces); return(result); } catch (Exception e) { return(new JObject { { "error_code", 1 }, { "error_msg", e.ToString() } }); } }