服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - C# - 百度人脸识别之人脸识别FaceIdentify(签到考勤)

百度人脸识别之人脸识别FaceIdentify(签到考勤)

2022-08-04 09:44杨小哥 C#

这篇文章主要为大家详细介绍了百度人脸识别之人脸识别FaceIdentify,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

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

百度人脸识别之人脸识别FaceIdentify(签到考勤)

百度人脸识别之人脸识别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 = "失败,请重新识别!";
        }
      }
    }
  }
}

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

原文链接:https://blog.csdn.net/qq_38962400/article/details/79642562

延伸 · 阅读

精彩推荐
  • C#C#后台接受前台JSON字符串装换成字典集合处理

    C#后台接受前台JSON字符串装换成字典集合处理

    本文介绍C#利用Newtonsoft接收前端的JSON字符串,并解析反序列化成字典集合,对其进行处理。...

    Darren Ji3642021-11-18
  • C#.Net(c#)汉字和Unicode编码互相转换实例

    .Net(c#)汉字和Unicode编码互相转换实例

    下面小编就为大家带来一篇.Net(c#)汉字和Unicode编码互相转换实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧...

    C#教程网4512021-12-23
  • C#WinForm实现自定义右下角提示效果的方法

    WinForm实现自定义右下角提示效果的方法

    这篇文章主要介绍了WinForm实现自定义右下角提示效果的方法,涉及WinForm自定义提示效果的实现方法,具有一定参考借鉴价值,需要的朋友可以参考下...

    我心依旧11332021-10-21
  • C#Datagridview使用技巧(9)Datagridview的右键菜单

    Datagridview使用技巧(9)Datagridview的右键菜单

    这篇文章主要为大家详细介绍了Datagridview使用技巧,Datagridview的右键菜单,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...

    .NET开发菜鸟3842022-01-04
  • C#C#中如何正确的使用字符串String

    C#中如何正确的使用字符串String

    这篇文章主要给大家介绍了关于在C#中如何正确的使用字符串String的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考...

    Fode6852022-03-06
  • C#C#实现单词本功能

    C#实现单词本功能

    这篇文章主要为大家详细介绍了C#实现单词本功能,复习巩固所学单词,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...

    、你我山前没相见9992022-07-31
  • C#C#图片查看器实现方法

    C#图片查看器实现方法

    本篇文章给大家分享了用C#制作图片查看器的方法以及先实现代码,有需要的读者们参考下。...

    彬菌5722022-02-22
  • C#C#创建安全的字典(Dictionary)存储结构

    C#创建安全的字典(Dictionary)存储结构

    本文主要对存储结构字典(Dictionary)的一些常用方法进行简单的说明,并阐述了如何创建安全的字典(Dictionary)存储结构。希望对大家有所帮助...

    彭泽090210692021-12-13