|
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using LitJson;
using UnityEngine.UI;
public class FaceTest1 : MonoBehaviour
{
public string ImageURL = "";
//按鈕上的文本
public Text Btn_ShibieText;
//顯示結果
public GameObject ShowResult;
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void TestHttpSend()
{
//識別文字
WWWForm form = new WWWForm();
form.AddField("api_key", "q8QTfr-xS5hm-i25JuWRLmWQQSHRRtzy");
form.AddField("api_secret", "3JAabNdllrl-Dm_-iYSG43B0ewypFlWt");
form.AddField("image_url", ImageURL);
StartCoroutine(SendPost("https://api-cn./imagepp/v1/recognizetext", form));
}
//提交數(shù)據(jù)進行識別
IEnumerator SendPost(string _url, WWWForm _wForm)
{
WWW postData = new WWW(_url, _wForm);
yield return postData;
if (postData.error != "")
{
Debug.Log(postData.error);
ShowResult.SetActive(true);
Btn_ShibieText.text = "識別";
ShowResult.transform.Find("Text").GetComponent<Text>().text = "識別失敗!";
GameObject.Find("DebugText").GetComponent<Text>().text = postData.error;
//myTimer = 2.0f;
}
else
{
Btn_ShibieText.text = "識別";
Debug.Log(postData.text);
GameObject.Find("DebugText").GetComponent<Text>().text = postData.text;
JsonJieXi(postData.text);
}
}
void JsonJieXi(string str)
{
JsonData jd = JsonMapper.ToObject(str);
Debug.Log(jd["result"].Count);
for (int i = 0; i < jd["result"].Count; i++)
{
for (int j = 0; j < jd["result"]["child-objects"].Count; j++)
{
Debug.Log(jd["result"]["child-objects"][j]["type"].ToString());
Debug.Log(jd["result"]["child-objects"][j]["value"].ToString());
}
}
}
}
|