欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

歡迎來到入門教程網(wǎng)!

C#教程

當(dāng)前位置:主頁 > 軟件編程 > C#教程 >

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

來源:本站原創(chuàng)|時間:2020-01-10|欄目:C#教程|點擊: 次

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


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;//識別數(shù)據(jù)的返回結(jié)果
  private byte[] image;//圖片字節(jié)數(shù)
  private Dictionary<string, object> options = new Dictionary<string, object>();//多參數(shù)
  private double scores;//返回的分?jǐn)?shù),用來判定識別是否達(dá)標(biāo)
  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返回的用戶組數(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個識別數(shù)
    };
    try//避免出現(xiàn)網(wǎng)絡(luò)異常導(dǎo)致錯誤
    {
      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錯誤信息轉(zhuǎn)成字符串
      switch (error_code)
      {
        case 216100:
          DebugText.text = "invalid param 參數(shù)異常,請重新填寫注冊信息";
          break;
        case 216611:
          DebugText.text = "user not exist 用戶id不存在,請確認(rèn)該用戶是否注冊或注冊已經(jīng)生效(需要已經(jīng)注冊超過5s)";
          break;
        case 216401:
          DebugText.text = "internal error 內(nèi)部錯誤";
          break;
        case 216402:
          DebugText.text = "face not found 未找到人臉,請檢查圖片是否含有人臉";
          break;
        case 216500:
          DebugText.text = "unknown error 未知錯誤";
          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)注冊超過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 = "識別成功,今日已簽到!";
          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 = "失敗,請重新識別!";
        }
      }
    }
  }
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持我們。

上一篇:C# 導(dǎo)出Excel的6種簡單方法實現(xiàn)

欄    目:C#教程

下一篇:C#中RSA加密與解密的實例詳解

本文標(biāo)題:百度人臉識別之人臉識別FaceIdentify(簽到考勤)

本文地址:http://mengdiqiu.com.cn/a1/C_jiaocheng/4668.html

網(wǎng)頁制作CMS教程網(wǎng)絡(luò)編程軟件編程腳本語言數(shù)據(jù)庫服務(wù)器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進(jìn)行處理、任何非本站因素導(dǎo)致的法律后果,本站均不負(fù)任何責(zé)任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有