我是靠谱客的博主 可耐饼干,这篇文章主要介绍百度人脸识别之人脸识别FaceIdentify(签到考勤),现在分享给大家,希望可以做个参考。

本文实例为大家分享了百度人脸识别之人脸识别FaceIdentify,供大家参考,具体内容如下


复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using System.Collections.Generic; using UnityEngine; using Baidu.Aip.Face; using Newtonsoft.Json.Linq; using UnityEngine.UI; using System.IO; //识别,(用于签到考勤) public class FaceIdentify : MonoBehaviour { private Face client;//百度API接口 private JObject result;//识别数据的返回结果 private byte[] image;//图片字节数 private Dictionary<string, object> options = new Dictionary<string, object>();//多参数 private double scores;//返回的分数,用来判定识别是否达标 private string group_id;//用户所在的用户组,或者说部门 private int error_code;//返回得错误代码 private string error_msg;//返回得错误提示信息 public Text DebugText; public Text DebugText1; public Text DebugText2; private string result_group_id;//result返回的用户组数据 private string result_uid;//result返回的用户id数据 private string result_user_info;//result 返回的用户信息数据 public bool isSuccess = false; private void Awake() { client = new Face(AccessToken.client_id, AccessToken.client_secret); AccessToken.ClientCallback();//获取证书 } private void Start() { DebugText.text = ""; DebugText1.text = ""; DebugText2.text = ""; } public void faceIdentify() { Invoke("Identify", 5.0f); } void Identify() { group_id = "U3D1"; string path = Application.dataPath + "/ScreenShot/" + WebCamera.ScreenShotTexture2D + ".jpg"; image = File.ReadAllBytes(path); options = new Dictionary<string, object>() { {"ext_fileds","faceliveness" }, {"user_top_num",1 }//最大返回5个识别数 }; try//避免出现网络异常导致错误 { result = client.Identify(group_id, image, options); Debug.Log(result); error_code = int.Parse(result["error_code"].ToString());//先把json数据转成字符串,再转成int类型 error_msg = result["error_msg"].ToString();//把返回的json错误信息转成字符串 switch (error_code) { case 216100: DebugText.text = "invalid param 参数异常,请重新填写注册信息"; break; case 216611: DebugText.text = "user not exist 用户id不存在,请确认该用户是否注册或注册已经生效(需要已经注册超过5s)"; break; case 216401: DebugText.text = "internal error 内部错误"; break; case 216402: DebugText.text = "face not found 未找到人脸,请检查图片是否含有人脸"; break; case 216500: DebugText.text = "unknown error 未知错误"; break; case 216615: DebugText.text = "fail to process images 服务处理该图片失败,发生后重试即可"; break; case 216618: DebugText.text = "no user in group 组内用户为空,确认该group是否存在或已经生效(需要已经注册超过5s)"; break; default: DebugText.text = error_msg; break; } if (error_code != 216100 || error_code != 216101|| error_code != 216401 || error_code != 216402 || error_code != 216500 || error_code != 216615 || error_code != 216618) { DebugText1.text = result.ToString();//显示返回的数据信息 } } catch { if (error_code != 216100 || error_code != 216101 || error_code != 216401 || error_code != 216402 || error_code != 216500 || error_code != 216615 || error_code != 216618) { JToken res = result["result"]; scores = double.Parse(res[0]["scores"][0].ToString()); if (scores > 80.0f) { result_uid = res[0]["uid"].ToString(); result_group_id = res[0]["group_id"].ToString(); result_user_info = res[0]["user_info"].ToString(); DebugText1.text = "识别成功,今日已签到!"; DebugText2.text = result_uid+"n"+ result_group_id+"n" + result_user_info; Debug.Log(result_uid.ToString() + result_group_id.ToString() + result_user_info.ToString()); } else { DebugText1.text = "失败,请重新识别!"; } } } } }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持靠谱客。

最后

以上就是可耐饼干最近收集整理的关于百度人脸识别之人脸识别FaceIdentify(签到考勤)的全部内容,更多相关百度人脸识别之人脸识别FaceIdentify(签到考勤)内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(152)

评论列表共有 0 条评论

立即
投稿
返回
顶部