Beispiel #1
0
        private async Task <SimilarFaceMatch> GetSimilarFace(Face detectedFace)
        {
            SimilarFaceMatch result = new SimilarFaceMatch();

            try
            {
                Tuple <SimilarPersistedFace, string> similarPersistedFace = await FaceListManager.FindSimilarPersistedFaceAsync(await this.GetImageStreamCallback(), detectedFace.FaceId, detectedFace.FaceRectangle);

                if (similarPersistedFace != null)
                {
                    bool isNew = (similarPersistedFace.Item2 == null);
                    result = new SimilarFaceMatch()
                    {
                        Face = detectedFace, SimilarPersistedFace = similarPersistedFace.Item1, isNew = isNew
                    };
                }
            }
            catch (Exception e)
            {
                ErrorTrackingHelper.TrackException(e, "FaceListManager.FindSimilarPersistedFaceAsync error");

                if (this.ShowDialogOnFaceApiErrors)
                {
                    await ErrorTrackingHelper.GenericApiCallExceptionHandler(e, "Failure finding similar faces");
                }
            }

            return(result);
        }
        public async Task FindSimilarPersistedFacesAsync()
        {
            this.SimilarFaceMatches = Enumerable.Empty <SimilarFaceMatch>();

            if (this.DetectedFaces == null || !this.DetectedFaces.Any())
            {
                return;
            }

            List <SimilarFaceMatch> result = new List <SimilarFaceMatch>();

            foreach (DetectedFace detectedFace in this.DetectedFaces)
            {
                try
                {
                    SimilarFace similarPersistedFace = null;
                    if (this.ImageUrl != null)
                    {
                        similarPersistedFace = await FaceListManager.FindSimilarPersistedFaceAsync(ImageUrl, detectedFace.FaceId.GetValueOrDefault(), detectedFace);
                    }
                    else
                    {
                        similarPersistedFace = await FaceListManager.FindSimilarPersistedFaceAsync(this.GetImageStreamCallback, detectedFace.FaceId.GetValueOrDefault(), detectedFace);
                    }
                    if (similarPersistedFace != null)
                    {
                        result.Add(new SimilarFaceMatch {
                            Face = detectedFace, SimilarPersistedFace = similarPersistedFace
                        });
                    }
                }
                catch (Exception e)
                {
                    ErrorTrackingHelper.TrackException(e, "FaceListManager.FindSimilarPersistedFaceAsync error");

                    if (this.ShowDialogOnFaceApiErrors)
                    {
                        await ErrorTrackingHelper.GenericApiCallExceptionHandler(e, "Failure finding similar faces");
                    }
                }
            }

            this.SimilarFaceMatches = result;
        }
Beispiel #3
0
        public async Task <List <FaceSendInfo> > FindSimilarPersonWithEmotion()
        {
            var facesInfo = new List <FaceSendInfo>();
            List <SimilarFaceMatch> result = new List <SimilarFaceMatch>();

            //Loop thru all detected faces from previous steps and fill the facesInfo array
            //For ease of processing in Azure Stream Analytics we create single level object
            foreach (var f in this.DetectedFaces)
            {
                var fsi = new FaceSendInfo();

                //Add emotions
                var e = CoreUtil.FindEmotionForFace(f, this.DetectedEmotion);
                FeedFaceInfo(f, fsi, e);
                //We sen also info how many faces in total were recognized on the picture with current face
                fsi.facesNo = this.DetectedFaces.Count();



                Tuple <SimilarPersistedFace, string> similarPersistedFace = await FaceListManager.FindSimilarPersistedFaceAsync(await this.GetImageStreamCallback(), f.FaceId, f.FaceRectangle);

                if (similarPersistedFace != null)
                {
                    result.Add(new SimilarFaceMatch {
                        Face = f, SimilarPersistedFace = similarPersistedFace.Item1
                    });
                    fsi.canid   = similarPersistedFace.Item1.PersistedFaceId.ToString();
                    fsi.canconf = similarPersistedFace.Item1.Confidence;

                    //In order to get also name we need to obtain Person
                    //p = await FaceServiceHelper.GetPersonAsync(groupId, can.PersonId);
                    fsi.canname = similarPersistedFace.Item1.PersistedFaceId.ToString();
                }

                facesInfo.Add(fsi);
            }
            SimilarFaceMatches = result;
            return(facesInfo);
        }