/// <summary> /// Bubbles up the face API event via the behaviour. /// </summary> /// <param name="sender"></param> /// <param name="result"></param> private void _emotionAPI_OnRecognize(object sender, EmotionAPIEventArgs args) { if (Verbose) { Debug.LogFormat("Result: {0} faces detected. {1}", args.EmotionsDetected.Count, Time.timeSinceLevelLoad); } if (OnRecognize != null) { OnRecognize(sender, args); } }
public IEnumerator Recognize(Texture2D texture) { // Get the PNG var data = texture.EncodeToPNG(); // No query in the URL var requestUrl = EmotionStrings.URL_RECOGNIZE; if (Verbose) { Debug.LogFormat("Recognize URL {0}.", requestUrl); } // Add the headers Dictionary <string, string> headers = new Dictionary <string, string>(); headers.Add(CognitiveStrings.HEADER_OCP_APIM_SUBSCRIPTION_KEY, APIKey); headers.Add(CognitiveStrings.HEADER_CONTENT_TYPE, CognitiveStrings.CONTENT_TYPE_OCTET_STREAM); // The fantastic Unity WWW request var client = new WWW(requestUrl, data, headers); yield return(client); if (Verbose) { Debug.LogFormat("Detect Response {0}.", client.text); } var response = JsonConvert.DeserializeObject <RecognizeResponse>(client.text); var args = new EmotionAPIEventArgs() { EmotionsDetected = response.Emotions, OriginalImage = texture }; if (OnRecognize != null) { OnRecognize(this, args); } }