百度人臉識(shí)別之人臉識(shí)別FaceIdentify(簽到考勤)
更新時(shí)間:2019年08月28日 16:34:29 作者:楊小哥
這篇文章主要為大家詳細(xì)介紹了百度人臉識(shí)別之人臉識(shí)別FaceIdentify,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
本文實(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)重新填寫注冊信息"; break; case 216611: DebugText.text = "user not exist 用戶id不存在,請(qǐng)確認(rèn)該用戶是否注冊或注冊已經(jīng)生效(需要已經(jīng)注冊超過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)注冊超過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í)別!"; } } } } }
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
相關(guān)文章
Unity接入百度AI實(shí)現(xiàn)果蔬識(shí)別
本文將介紹如何利用Unity接入百度AI從而實(shí)現(xiàn)果蔬識(shí)別,可以做到識(shí)別近千種水果和蔬菜的名稱,可自定義返回識(shí)別結(jié)果數(shù)。感興趣的小伙伴可以了解一下2022-02-02c#使用Unity粒子實(shí)現(xiàn)炮塔發(fā)射系統(tǒng)
Unity自帶粒子發(fā)射器、動(dòng)畫器、渲染器各兩種,利用Unity的粒子系統(tǒng)制作一個(gè)炮塔發(fā)射系統(tǒng),了解粒子系統(tǒng),必須先了解每一個(gè)屬性都代表了什么,之后才能根據(jù)這些原理來調(diào)整出自己滿意的效果2022-04-04