百度人脸识别之人脸识别FaceIdentify(签到考勤)
作者:杨小哥 时间:2022-08-24 18:25:03
本文实例为大家分享了百度人脸识别之人脸识别FaceIdentify,供大家参考,具体内容如下
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
标签:百度人脸识别,人脸识别,FaceIdentify
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
结合.net框架在C#派生类中触发基类事件及实现接口事件
2022-02-23 20:39:57
搭建MyBatis-Plus框架并进行数据库增删改查功能
2023-11-09 04:33:43
![](https://img.aspxhome.com/file/2023/7/59167_0s.png)
通过Java修改游戏存档的实现思路
2023-07-30 20:10:55
![](https://img.aspxhome.com/file/2023/7/75517_0s.jpg)
JAVA IDEA 打开assert 设置方式
2022-08-19 13:48:49
![](https://img.aspxhome.com/file/2023/7/77137_0s.png)
每天学Java!一分钟了解JRE与JDK
2021-06-13 11:52:41
![](https://img.aspxhome.com/file/2023/5/85895_0s.jpg)
Java代码精简之道(推荐)
2023-07-28 02:00:05
C# WinForm实现图片浏览器
2022-04-12 23:28:00
![](https://img.aspxhome.com/file/2023/6/92906_0s.jpg)
java设计模式--原型模式详解
2023-11-25 05:08:24
![](https://img.aspxhome.com/file/2023/0/60190_0s.png)
一篇文章带你搞定JAVA Maven
2023-12-09 17:42:10
![](https://img.aspxhome.com/file/2023/2/122262_0s.png)
C#生成Word文件(图片、文字)
2023-03-28 04:07:58
关于springboot 中使用httpclient或RestTemplate做MultipartFile文件跨服务传输的问题
2023-01-04 15:38:04
![](https://img.aspxhome.com/file/2023/0/110790_0s.jpg)
Spring Batch入门教程篇
2022-02-15 01:53:01
![](https://img.aspxhome.com/file/2023/4/83014_0s.png)
Android AlertDialog自定义样式实现代码
2023-07-08 13:10:06
Java的动态绑定与双分派_动力节点Java学院整理
2021-07-14 11:18:50
C#及WPF获取本机所有字体和颜色的方法
2022-12-23 01:23:13
SpringBoot的API文档生成工具SpringDoc使用详解
2021-11-09 07:15:45
![](https://img.aspxhome.com/file/2023/6/81236_0s.png)
Java中字符串String的+和+=及循环操作String原理详解
2023-05-13 15:10:35
Android mvvm之LiveData原理案例详解
2023-09-29 11:49:26
![](https://img.aspxhome.com/file/2023/5/92625_0s.png)
Java项目有中多个线程如何查找死锁
2023-01-06 06:17:35
![](https://img.aspxhome.com/file/2023/9/125489_0s.jpg)
RocketMQ生产者如何规避故障Broker方式详解
2022-06-23 04:36:10