Beispiel #1
0
        public async static Task <string> UploadImageAzureFunction([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequestMessage req, TraceWriter log)
        {
            try
            {
                var    Content     = req.Content;
                string JsonContent = await Content.ReadAsStringAsync();

                FaceIdentificationContext FaceAppContext = JsonConvert.DeserializeObject <FaceIdentificationContext>(JsonContent);
                StorageService.uploadImageAsync(FaceAppContext.ImageUrl, ImageType.image64, FaceAppContext.AppID, FaceAppContext.Context.Id);
                return(StorageService.GetImageUrl(FaceAppContext.AppID, FaceAppContext.Context.Id));
            }
            catch (ErrorMsg ErrorMsgException)
            {
                return(JsonConvert.SerializeObject(ErrorMsgException.error));
            }
        }
Beispiel #2
0
        public static async Task <Tuple <List <Face>, List <User> > > Identify(string personGroupId, List <Face> faces, FaceIdentificationContext appContext)
        {
            var iReturn = new Tuple <List <Face>, List <User> >(faces, new List <User>());

            HttpClient client   = InitializeClient();
            string     facesIds = string.Join("\",\"", faces.Select(f => f.FaceID));

            List <identifyResponse> iResponse = new List <identifyResponse>();

            byte[] byteData = Encoding.UTF8.GetBytes("{\"personGroupId\":\"" + personGroupId + "\",\"faceIds\":[\"" + facesIds + "\"]}");


            using (var content = new ByteArrayContent(byteData))
            {
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                var response = await client.PostAsync(@baseURL + "/identify?maxNumOfCandidatesReturned=1", content);

                var responseString = await response.Content.ReadAsStringAsync();

                iResponse = JsonConvert.DeserializeObject <List <identifyResponse> >(responseString);
            }
            for (int i = 0; i < iResponse.Count; i++)
            {
                identifyResponse item = iResponse[i];
                if (item.Candidates.Count > 0)
                {
                    string personId = item.Candidates[0].PersonId;
                    string userId   = MappingService.GetFromMapping(appContext.AppID + "-" + appContext.Context.Id, personId);
                    User   user     = new User(userId, ""); //TODO:Change to retrive user name appContext.users[i].name);
                    iReturn.Item2.Add(user);                //appid-context, personid
                    iReturn.Item1.RemoveAt(i);
                }
            }

            return(iReturn);
        }