百度人臉識別之人臉識別FaceIdentify(簽到考勤)
本文實例為大家分享了百度人臉識別之人臉識別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
您可能感興趣的文章
- 01-10c#實現(xiàn)識別圖片上的驗證碼數(shù)字
- 01-10C#使用ImitateLogin模擬登錄百度
- 01-10C#開發(fā)Android百度地圖手機(jī)應(yīng)用程序(多地圖展示)
- 01-10基于C#技術(shù)實現(xiàn)身份證識別功能
- 01-10C#實現(xiàn)百度ping推送功能的方法
- 01-10.NET C#利用ZXing生成、識別二維碼/條形碼
- 01-10C#如何自動識別文件的編碼
- 01-10.NET/C#實現(xiàn)識別用戶訪問設(shè)備的方法
- 01-10WinForm調(diào)用百度地圖接口用法示例
- 01-10C#實現(xiàn)微信結(jié)合百度api獲取當(dāng)前用戶地理位置的方法


閱讀排行
本欄相關(guān)
- 01-10C#通過反射獲取當(dāng)前工程中所有窗體并
- 01-10關(guān)于ASP網(wǎng)頁無法打開的解決方案
- 01-10WinForm限制窗體不能移到屏幕外的方法
- 01-10WinForm繪制圓角的方法
- 01-10C#實現(xiàn)txt定位指定行完整實例
- 01-10WinForm實現(xiàn)仿視頻播放器左下角滾動新
- 01-10C#停止線程的方法
- 01-10C#實現(xiàn)清空回收站的方法
- 01-10C#通過重寫Panel改變邊框顏色與寬度的
- 01-10C#實現(xiàn)讀取注冊表監(jiān)控當(dāng)前操作系統(tǒng)已
隨機(jī)閱讀
- 01-10SublimeText編譯C開發(fā)環(huán)境設(shè)置
- 08-05織夢dedecms什么時候用欄目交叉功能?
- 01-11ajax實現(xiàn)頁面的局部加載
- 08-05DEDE織夢data目錄下的sessions文件夾有什
- 01-10使用C語言求解撲克牌的順子及n個骰子
- 01-10C#中split用法實例總結(jié)
- 01-10delphi制作wav文件的方法
- 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
- 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
- 04-02jquery與jsp,用jquery