///step 12 /// <summary> /// Identify the faces found in the image within the person group /// </summary> internal IEnumerator IdentifyFaces(List <string> listOfFacesIdToIdentify) { Debug.Log("LIST OF FACES : " + listOfFacesIdToIdentify.ToString()); // Create the object hosting the faces to identify FacesToIdentify_RootObject facesToIdentify = new FacesToIdentify_RootObject(); facesToIdentify.faceIds = new List <string>(); facesToIdentify.personGroupId = personGroupId; foreach (string facesId in listOfFacesIdToIdentify) { facesToIdentify.faceIds.Add(facesId); } facesToIdentify.maxNumOfCandidatesReturned = 1; facesToIdentify.confidenceThreshold = 0.5; // Serialise to Json format string facesToIdentifyJson = JsonConvert.SerializeObject(facesToIdentify); // Change the object into a bytes array byte[] facesData = Encoding.UTF8.GetBytes(facesToIdentifyJson); WWWForm webForm = new WWWForm(); string detectFacesEndpoint = $"{baseEndpoint}identify"; using (UnityWebRequest www = UnityWebRequest.Post(detectFacesEndpoint, webForm)) { www.SetRequestHeader("Ocp-Apim-Subscription-Key", key); www.SetRequestHeader("Content-Type", "application/json"); www.uploadHandler.contentType = "application/json"; www.uploadHandler = new UploadHandlerRaw(facesData); www.downloadHandler = new DownloadHandlerBuffer(); yield return(www.SendWebRequest()); string jsonResponse = www.downloadHandler.text; Debug.Log($"Get Person - jsonResponse: {jsonResponse}"); Candidate_RootObject[] candidate_RootObject = JsonConvert.DeserializeObject <Candidate_RootObject[]>(jsonResponse); // For each face to identify that ahs been submitted, display its candidate double conf = 0; Candidate_RootObject c = candidate_RootObject[0]; foreach (Candidate_RootObject candidateRO in candidate_RootObject) { if (candidateRO.candidates.Count > 0) { if (candidateRO.candidates[0].confidence > conf) { conf = candidateRO.candidates[0].confidence; c = candidateRO; } } } if (c.candidates.Count > 0) { StartCoroutine(GetPerson(c.candidates[0].personId)); } } }
/// <summary> /// Identify the faces found in the image within the person group /// </summary> internal IEnumerator IdentifyFaces(List <string> listOfFacesIdToIdentify) { // Create the object hosting the faces to identify FacesToIdentify_RootObject facesToIdentify = new FacesToIdentify_RootObject(); facesToIdentify.faceIds = new List <string>(); facesToIdentify.personGroupId = personGroupId; foreach (string facesId in listOfFacesIdToIdentify) { facesToIdentify.faceIds.Add(facesId); } facesToIdentify.maxNumOfCandidatesReturned = 1; facesToIdentify.confidenceThreshold = 0.5; // Serialise to Json format string facesToIdentifyJson = JsonConvert.SerializeObject(facesToIdentify); // Change the object into a bytes array byte[] facesData = Encoding.UTF8.GetBytes(facesToIdentifyJson); WWWForm webForm = new WWWForm(); string detectFacesEndpoint = $"{baseEndpoint}identify"; using (UnityWebRequest www = UnityWebRequest.Post(detectFacesEndpoint, webForm)) { www.SetRequestHeader("Ocp-Apim-Subscription-Key", key); www.SetRequestHeader("Content-Type", "application/json"); www.uploadHandler.contentType = "application/json"; www.uploadHandler = new UploadHandlerRaw(facesData); www.downloadHandler = new DownloadHandlerBuffer(); yield return(www.SendWebRequest()); string jsonResponse = www.downloadHandler.text; Debug.Log($"Get Person - jsonResponse: {jsonResponse}"); //tempText.text = jsonResponse; Candidate_RootObject[] candidate_RootObject = JsonConvert.DeserializeObject <Candidate_RootObject[]>(jsonResponse); // For each face to identify that has been submitted, display its candidate foreach (Candidate_RootObject candidateRO in candidate_RootObject) { if (candidateRO.candidates.Count > 0) { // Delay the next "GetPerson" call, so all faces candidate are displayed properly yield return(new WaitForSeconds(3)); StartCoroutine(GetPerson(candidateRO.candidates[0].personId)); } else { FaceRecName.instance.displayText.text = "Face Not Identified"; } } } }
/// <summary> /// Identify the faces found in the image within the person group /// </summary> internal IEnumerator IdentifyFaces(List <string> listOfFacesIdToIdentify) { CreateLabel3d(); // Create the object hosting the faces to identify FacesToIdentify_RootObject facesToIdentify = new FacesToIdentify_RootObject(); facesToIdentify.faceIds = new List <string>(); facesToIdentify.personGroupId = personGroupId; foreach (string facesId in listOfFacesIdToIdentify) { facesToIdentify.faceIds.Add(facesId); } facesToIdentify.maxNumOfCandidatesReturned = 1; facesToIdentify.confidenceThreshold = 0.5; // Serialise to Json format string facesToIdentifyJson = JsonConvert.SerializeObject(facesToIdentify); // Change the object into a bytes array byte[] facesData = Encoding.UTF8.GetBytes(facesToIdentifyJson); WWWForm webForm = new WWWForm(); string detectFacesEndpoint = $"{baseEndpoint}identify"; using (UnityWebRequest www = UnityWebRequest.Post(detectFacesEndpoint, webForm)) { www.SetRequestHeader("Ocp-Apim-Subscription-Key", key); www.SetRequestHeader("Content-Type", "application/json"); www.uploadHandler.contentType = "application/json"; www.uploadHandler = new UploadHandlerRaw(facesData); www.downloadHandler = new DownloadHandlerBuffer(); yield return(www.SendWebRequest()); string jsonResponse = www.downloadHandler.text; Debug.Log($"Get Person - jsonResponse: {jsonResponse}"); try { Candidate_RootObject[] candidate_RootObject = JsonConvert.DeserializeObject <Candidate_RootObject[]>(jsonResponse); // For each face to identify that ahs been submitted, display its candidate foreach (Candidate_RootObject candidateRO in candidate_RootObject) { try { StartCoroutine(GetPerson(candidateRO.candidates[0].personId)); } catch { lastLabelPlacedText.text = "Person doesn't recognized, please make \n" + "sure that this person is registered in\n" + "the showcase's face API resource."; } // Delay the next "GetPerson" call, so all faces candidate are displayed properly } } catch { lastLabelPlacedText.text = "Please get focus\n" + "in a person and make\n" + "Air Tap gesture"; } yield return(new WaitForSeconds(3)); } }