Exemple #1
0
 /// <summary>
 /// Creates a <see cref="TrainingStatus"/> from a <see cref="TrainingStatusType"/>
 /// </summary>
 /// <returns>The <see cref="TrainingStatus"/>.</returns>
 /// <param name="status">The status to use.</param>
 public static TrainingStatus FromStatus(TrainingStatusType status)
 {
     return(new TrainingStatus
     {
         Status = status
     });
 }
            public async Task <List <Identification> > Identify(string personGroupId, StorageFile file)
            {
                var result = new List <Identification>();

                try
                {
                    var faces = await Detect(file);

                    var faceIds = faces.Select(face => face.FaceId.GetValueOrDefault()).ToList();

                    if (faceIds.Count == 0)
                    {
                        Debug.WriteLine("No Faces Found");
                        return(result);
                    }

                    TrainingStatusType status = await IsTrainingComplete(personGroupId);

                    IList <IdentifyResult> identities = new List <IdentifyResult>();
                    if (status != TrainingStatusType.Failed)
                    {
                        identities = await _faceClient.Face.IdentifyAsync(personGroupId, faceIds);
                    }

                    foreach (var face in faces)
                    {
                        var identifyResult = identities.Where(i => i.FaceId == face.FaceId).FirstOrDefault();

                        var identification = new Identification
                        {
                            Person = new Person {
                                Name = "Unknown"
                            },
                            Confidence     = 1,
                            Face           = face,
                            IdentifyResult = identifyResult
                        };

                        result.Add(identification);

                        if (identifyResult != null && identifyResult.Candidates.Count > 0)
                        {
                            // Get top 1 among all candidates returned
                            IdentifyCandidate candidate = identifyResult.Candidates[0];

                            var person = await _faceClient.PersonGroupPerson.GetAsync(personGroupId, candidate.PersonId);

                            identification.Person     = person;
                            identification.Confidence = candidate.Confidence;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }

                return(result);
            }
 /// <summary>
 /// Initializes a new instance of the TrainingStatus class.
 /// </summary>
 /// <param name="status">Training status: notstarted, running,
 /// succeeded, failed. If the training process is waiting to perform,
 /// the status is notstarted. If the training is ongoing, the status is
 /// running. Status succeed means this person group or large person
 /// group is ready for Face - Identify, or this large face list is
 /// ready for Face - Find Similar. Status failed is often caused by no
 /// person or no persisted face exist in the person group or large
 /// person group, or no persisted face exist in the large face list.
 /// Possible values include: 'nonstarted', 'running', 'succeeded',
 /// 'failed'</param>
 /// <param name="created">A combined UTC date and time string that
 /// describes the created time of the person group, large person group
 /// or large face list.</param>
 /// <param name="lastAction">A combined UTC date and time string that
 /// describes the last modify time of the person group, large person
 /// group or large face list, could be null value when the group is not
 /// successfully trained.</param>
 /// <param name="lastSuccessfulTraining">A combined UTC date and time
 /// string that describes the last successful training time of the
 /// person group, large person group or large face list.</param>
 /// <param name="message">Show failure message when training failed
 /// (omitted when training succeed).</param>
 public TrainingStatus(TrainingStatusType status, System.DateTime created, System.DateTime?lastAction = default(System.DateTime?), System.DateTime?lastSuccessfulTraining = default(System.DateTime?), string message = default(string))
 {
     Status                 = status;
     Created                = created;
     LastAction             = lastAction;
     LastSuccessfulTraining = lastSuccessfulTraining;
     Message                = message;
     CustomInit();
 }
        internal static string ToSerializedValue(this TrainingStatusType value)
        {
            switch (value)
            {
            case TrainingStatusType.Nonstarted:
                return("nonstarted");

            case TrainingStatusType.Running:
                return("running");

            case TrainingStatusType.Succeeded:
                return("succeeded");

            case TrainingStatusType.Failed:
                return("failed");
            }
            return(null);
        }