Пример #1
0
        public async Task <string> CreatePersonAsync(string id, byte[] byteData)
        {
            string uriDir = "persongroups/" + GroupId + "/persons";
            string uri    = uriBase + uriDir;

            var name = new { name = id };

            HttpContent content = new StringContent(JsonConvert.SerializeObject(name), Encoding.UTF8, "application/json");
            string      c       = await content.ReadAsStringAsync();

            HttpResponseMessage response = await Client.PostAsync(uri, content);

            string contentString = await response.Content.ReadAsStringAsync();

            PersonID _id = JsonConvert.DeserializeObject <PersonID>(contentString);

            uri += "/" + _id.personId + "/persistedfaces";

            using (ByteArrayContent byteContent = new ByteArrayContent(byteData))
            {
                byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");

                response = await Client.PostAsync(uri, byteContent);

                contentString = await response.Content.ReadAsStringAsync();

                uri      = uriBase + "persongroups/" + GroupId + "/train";
                response = await Client.PostAsync(uri, new StringContent(""));

                Console.WriteLine();
                return(contentString);
            }
        }
Пример #2
0
        public async Task <string> Identify(byte[] byteData)
        {
            string data = await DetectAsync(byteData);

            FaceID[] id = JsonConvert.DeserializeObject <FaceID[]>(data);

            if (id.Length == 0)
            {
                return("");
            }

            IdentificationDTO idDTO = new IdentificationDTO();

            idDTO.maxNumOfCandidatesReturned = 1;
            idDTO.personGroupId = GroupId;
            idDTO.faceIds[0]    = id[0].faceId;

            string uri = uriBase + "identify";

            HttpContent         content = new StringContent(JsonConvert.SerializeObject(idDTO), Encoding.UTF8, "application/json");
            HttpResponseMessage message = await Client.PostAsync(uri, content);

            string contentString = await message.Content.ReadAsStringAsync();

            FaceID[] faceID = JsonConvert.DeserializeObject <FaceID[]>(contentString);

            if (faceID[0].candidates.Length == 0)
            {
                return("");
            }

            uri = uriBase + "persongroups/" + GroupId + "/persons/" + faceID[0].candidates[0].personId;

            message = await Client.GetAsync(uri);

            contentString = await message.Content.ReadAsStringAsync();

            PersonID personId = JsonConvert.DeserializeObject <PersonID>(contentString);

            return(personId.name);
        }