国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > C# > 正文

百度人臉識(shí)別之人臉識(shí)別FaceIdentify(簽到考勤)

2020-01-24 00:02:54
字體:
供稿:網(wǎng)友

本文實(shí)例為大家分享了百度人臉識(shí)別之人臉識(shí)別FaceIdentify,供大家參考,具體內(nèi)容如下


using System.Collections.Generic;using UnityEngine;using Baidu.Aip.Face;using Newtonsoft.Json.Linq;using UnityEngine.UI;using System.IO; //識(shí)別,(用于簽到考勤)public class FaceIdentify : MonoBehaviour {   private Face client;//百度API接口  private JObject result;//識(shí)別數(shù)據(jù)的返回結(jié)果  private byte[] image;//圖片字節(jié)數(shù)  private Dictionary<string, object> options = new Dictionary<string, object>();//多參數(shù)  private double scores;//返回的分?jǐn)?shù),用來判定識(shí)別是否達(dá)標(biāo)  private string group_id;//用戶所在的用戶組,或者說部門  private int error_code;//返回得錯(cuò)誤代碼  private string error_msg;//返回得錯(cuò)誤提示信息  public Text DebugText;  public Text DebugText1;  public Text DebugText2;  private string result_group_id;//result返回的用戶組數(shù)據(jù)  private string result_uid;//result返回的用戶id數(shù)據(jù)  private string result_user_info;//result 返回的用戶信息數(shù)據(jù)  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個(gè)識(shí)別數(shù)    };    try//避免出現(xiàn)網(wǎng)絡(luò)異常導(dǎo)致錯(cuò)誤    {      result = client.Identify(group_id, image, options);      Debug.Log(result);            error_code = int.Parse(result["error_code"].ToString());//先把json數(shù)據(jù)轉(zhuǎn)成字符串,再轉(zhuǎn)成int類型      error_msg = result["error_msg"].ToString();//把返回的json錯(cuò)誤信息轉(zhuǎn)成字符串      switch (error_code)      {        case 216100:          DebugText.text = "invalid param 參數(shù)異常,請(qǐng)重新填寫注冊(cè)信息";          break;        case 216611:          DebugText.text = "user not exist 用戶id不存在,請(qǐng)確認(rèn)該用戶是否注冊(cè)或注冊(cè)已經(jīng)生效(需要已經(jīng)注冊(cè)超過5s)";          break;        case 216401:          DebugText.text = "internal error 內(nèi)部錯(cuò)誤";          break;        case 216402:          DebugText.text = "face not found 未找到人臉,請(qǐng)檢查圖片是否含有人臉";          break;        case 216500:          DebugText.text = "unknown error 未知錯(cuò)誤";          break;        case 216615:          DebugText.text = "fail to process images 服務(wù)處理該圖片失敗,發(fā)生后重試即可";          break;        case 216618:          DebugText.text = "no user in group 組內(nèi)用戶為空,確認(rèn)該group是否存在或已經(jīng)生效(需要已經(jīng)注冊(cè)超過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();//顯示返回的數(shù)據(jù)信息              }    }    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 = "識(shí)別成功,今日已簽到!";          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 = "失敗,請(qǐng)重新識(shí)別!";        }      }    }  }}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 玛多县| 禄劝| 乌苏市| 元氏县| 行唐县| 叶城县| 梁河县| 苍溪县| 靖江市| 鲁甸县| 彰化市| 长寿区| 庆云县| 图木舒克市| 乳山市| 合阳县| 扶风县| 嵩明县| 佛冈县| 津市市| 巴林左旗| 酉阳| 呈贡县| 水富县| 陕西省| 台前县| 博野县| 泰顺县| 鹿邑县| 新闻| 衡南县| 纳雍县| 灵山县| 赤峰市| 治多县| 综艺| 岢岚县| 象山县| 宁国市| 山西省| 承德市|