分享

【新提醒】【unity进行文字图像识别

 鸿蛟家平 2017-09-27
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));
    }
    //提交数据进行识别
    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());
            }
        }
    }
     
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多