바 이 두 얼굴 인식 얼굴 인식 Face Identify(출석 체크)
5004 단어 바 이 두 얼굴 인식얼굴 인식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+"
"+ result_group_id+"
" + result_user_info;
Debug.Log(result_uid.ToString() + result_group_id.ToString() + result_user_info.ToString());
}
else
{
DebugText1.text = " , !";
}
}
}
}
}이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.