/// <summary> /// Bubbles up the face API event via the behaviour. /// </summary> /// <param name="sender"></param> /// <param name="result"></param> private void _faceAPI_OnDetect(object sender, FaceAPIEventArgs args) { if (Verbose) { Debug.LogFormat("Result: {0} faces detected. {1}", args.FacesDetected.Count, Time.timeSinceLevelLoad); } if (OnDetect != null) { OnDetect(sender, args); } }
public IEnumerator Detect(Texture2D texture) { // Get the PNG var data = texture.EncodeToPNG(); // No query customisations yet, but in the future the query string can be // formatted here var queryString = String.Format(FaceStrings.QUERY_STRING_FORMAT_DETECT, true, true, FaceStrings.PARAMETER_STRING_FACE_ATTRIBUTES); var requestUrl = FaceStrings.URL_DETECT + queryString; if (Verbose) { Debug.LogFormat("Detect 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); // Dump the response for now if (Verbose) { Debug.LogFormat("Detect Response {0}.", client.text); } var facesDetected = JsonConvert.DeserializeObject <List <DetectResponse.RootObject> >(client.text); var args = new FaceAPIEventArgs { FacesDetected = facesDetected, OriginalImage = texture }; if (OnDetect != null) { OnDetect(this, args); } }