/// <summary> /// Parse JSON data from the response /// Pass in the response from the API call /// </summary> /// <param name="respString"></param> public void ParseJSONData(string respString) { JSONObject dataArray = new JSONObject(respString); Debug.Log(respString); FoundImageObject _imageObject = ConvertObjectToFoundImageObject(dataArray); }
/// <summary> /// Get emotion data from the Cognitive Services Emotion API /// Stores the response into the responseData string /// </summary> /// <returns> IEnumerator - needs to be called in a Coroutine </returns> IEnumerator GetVisionData(byte[] bytes) { var headers = new Dictionary <string, string>() { { "Ocp-Apim-Subscription-Key", VISIONKEY }, { "Content-Type", "application/octet-stream" } }; WWW www = new WWW(visionURL, bytes, headers); yield return(www); try { var responseData = www.text; // Save the response as JSON string JSONObject dataArray = new JSONObject(responseData); JSONObject _categories = dataArray.list[0]; // Get the list of categories var x = new FoundImageObject(_categories); Text2.GetComponent <UnityEngine.UI.Text>().text = "Scene Information:\n"; foreach (var item in x.categories) { Text2.GetComponent <UnityEngine.UI.Text>().text += item.name + ": " + item.score + "\n"; } } catch (System.Exception X) { Text2.GetComponent <UnityEngine.UI.Text>().text += "Error: " + X.Message + "\n"; // throw; } }
/// <summary> /// Get emotion data from the Cognitive Services Emotion API /// Stores the response into the responseData string /// </summary> /// <returns> IEnumerator - needs to be called in a Coroutine </returns> IEnumerator GetVisionDataFromImages(byte[] bytes) { #if UNITY_WINRT byte[] bytes = UnityEngine.Windows.File.ReadAllBytes(fileName); #else //WWW reader = new WWW(fileName); //while (!reader.isDone) { } //byte[] bytes = reader.bytes; #endif var headers = new Dictionary <string, string>() { { "Ocp-Apim-Subscription-Key", VISIONKEY }, { "Content-Type", "application/octet-stream" } }; WWW www = new WWW(emotionURL, bytes, headers); yield return(www); responseData = www.text; // Save the response as JSON string FoundImageObject c = GetComponent <ParseComputerVisionResponse>().ParseJSONData(responseData); processImage(c); }
/// <summary> /// Parse JSON data from the response /// Pass in the response from the API call /// </summary> /// <param name="respString"></param> public FoundImageObject ParseJSONData(string respString) { JSONObject dataArray = new JSONObject(respString); FoundImageObject _imageObject = ConvertObjectToFoundImageObject(dataArray); return(_imageObject); }
public void processImage(FoundImageObject c) { // Acquiring animal phase database = GameObject.Find("Image").GetComponent <AnimalDatabase>(); ScreenManager sManager = GameObject.Find("SceneManager").GetComponent <ScreenManager>(); Animal animal; foreach (Category cat in c.categories) { // Fetch animal from database if animal fetched is not null then add to acquired animals animal = database.FetchAnimalByName(cat.name.Replace("\"", "")); if (animal != null) { int[] animals = PlayerPrefsX.GetIntArray("AnimalsAquired"); int[] dummy = new int[animals.Length + 1]; Debug.Log("-- " + animal.id + " " + database.FetchAnimalByID(animal.id)); for (int i = 0; i < animals.Length; i++) { dummy[i] = animals[i]; } if (!contains(animals, animal.id)) { dummy[dummy.Length - 1] = animal.id; PlayerPrefsX.SetIntArray("AnimalsAquired", dummy); DataManager.animalClicked = animal.id; // Set Found Animals PlayerPrefs.SetInt("foundAnimals", PlayerPrefs.GetInt("foundAnimals") + 1); PlayerPrefs.SetInt(animal.type, PlayerPrefs.GetInt(animal.type) + 1); // Set ScreenManager modified to false sManager.setModify(false); // Off camera cam.Exit(); showNoFoundPanel = false; // Redirect to FoundNewAnimal Screen SceneManager.LoadScene("FoundNewAnimal"); } else { showNoFoundPanel = false; StartCoroutine(activateDuplicatePanel()); } break; } } if (showNoFoundPanel) { StartCoroutine(activateNoFoundPanel()); } }