Beispiel #1
0
        public async Task SignIn()
        {
            try
            {
                // 1. Try to identify the person
                await customerFace.DetectFacesAsync();

                await customerFace.IdentifyFacesAsync();

                // TODO: consider looping over identified persons to find matching DB record
                customerInfo = new CustomerRegistrationInfo();
                customerInfo.CustomerFaceHash = customerFace.IdentifiedPersons.First().Person.PersonId.ToString();
                customerInfo.CustomerName     = customerFace.IdentifiedPersons.First().Person.Name;

                // 2. Try to obtain customer info from DB
                CustomerInfo dbCustomerInfo = IgniteDataAccess.GetCustomerInfo(customerInfo.CustomerFaceHash);
                customerInfo.RegistrationDate = dbCustomerInfo.PreviousVisitDate;

                // 3. Update status
                StatusText      = $"Welcome, {customerInfo.CustomerName}!";
                StatusTextColor = Util.ToBrush("green");
                PauseCamera?.Invoke(this, EventArgs.Empty);
            }
            catch (Exception)
            {
                customerInfo    = null;
                StatusText      = "Please try again.";
                StatusTextColor = Util.ToBrush("red");
                ResumeCamera?.Invoke(this, EventArgs.Empty);
            }
        }
Beispiel #2
0
        private CustomerRegistrationInfo customerRegistrationInfo; // obtained form registration UI
        public void UpdateCustomer(CustomerRegistrationInfo info)
        {
            customerRegistrationInfo = info;

            if (info != null && info.CustomerName.Length > 0)
            {
                customerInfo = IgniteDataAccess.GetCustomerInfo(info.CustomerFaceHash);

                if (customerInfo == null)  // first visit
                {
                    IsRecognized       = true;
                    IsUnrecognized     = false;
                    CustomerName       = info.CustomerName;
                    VisitDateStr       = "";
                    PreviousPurchase   = "";
                    RecommendedActions = IgniteDataServices.GetRecommendedActions(customerInfo);

                    IsWarningNoCheckout = true;  // we want to avoid having registered customers without transactions
                }
                else  // second visit
                {
                    IsRecognized       = true;
                    IsUnrecognized     = false;
                    CustomerName       = customerInfo.CustomerName;
                    VisitDateStr       = customerInfo.PreviousVisitDate.ToString("MM/dd/yyyy");
                    PreviousPurchase   = ProductCatalog.Instance.GetProductById(customerInfo.SourceItemId).ItemDescription;
                    RecommendedActions = IgniteDataServices.GetRecommendedActions(customerInfo);
                }
            }
            else
            {
                customerInfo       = null;
                IsRecognized       = false;
                IsUnrecognized     = true;
                CustomerName       = "";
                VisitDateStr       = "";
                PreviousPurchase   = "";
                RecommendedActions = "";
            }
        }
Beispiel #3
0
        public async Task Register()
        {
            IsRegistrationEnabled = false;
            try
            {
                IEnumerable <PersonGroup> PersonGroups = null;
                int i = 3; //retry count

                // 1. Select group
                // If the group is full, another one needs to added manually with alphabetically preceeding name
                do
                {
                    PersonGroups = await FaceServiceHelper.ListPersonGroupsAsync(SettingsHelper.Instance.WorkspaceKey);

                    if (PersonGroups.Count() > 0)
                    {
                        CurrentPersonGroup = PersonGroups.OrderBy(pg => pg.Name).First();
                    }
                    // Do not forget to create a persons group if there is not one
                    else
                    {
                        await FaceServiceHelper.CreatePersonGroupAsync(Guid.NewGuid().ToString(), "DefaultGroup", SettingsHelper.Instance.WorkspaceKey);
                    }

                    i--;
                } while (PersonGroups.Count() < 1 && i >= 0);

                // 2. Create a person in that group
                CurrentPerson = await FaceServiceHelper.CreatePersonAsync(this.CurrentPersonGroup.PersonGroupId, FullName);

                // 3. Add face to that person
                CurrentFace = await FaceServiceHelper.AddPersonFaceFromStreamAsync(
                    CurrentPersonGroup.PersonGroupId,
                    CurrentPerson.PersonId,
                    imageStreamCallback : customerFace.GetImageStreamCallback,
                    userData : customerFace.LocalImagePath,
                    targetFaceRect : null);

                // 4. Train model
                await FaceServiceHelper.TrainPersonGroupAsync(CurrentPersonGroup.PersonGroupId);

                bool trainingSucceeded = false;
                bool recordAdded       = false;

                while (true)
                {
                    TrainingStatus trainingStatus = await FaceServiceHelper.GetPersonGroupTrainingStatusAsync(CurrentPersonGroup.PersonGroupId);

                    if (trainingStatus.Status == TrainingStatusType.Succeeded)
                    {
                        trainingSucceeded = true;
                        break;
                    }
                    else if (trainingStatus.Status == TrainingStatusType.Failed)
                    {
                        break;
                    }

                    await Task.Delay(100);
                }

                // 5. Add record to the database
                if (trainingSucceeded)
                {
                    customerInfo = new CustomerRegistrationInfo
                    {
                        CustomerFaceHash = CurrentPerson.PersonId.ToString(),
                        CustomerName     = FullName,
                        RegistrationDate = DateTime.Now
                    };

                    recordAdded = IgniteDataAccess.CreateCustomerRecord(customerInfo.CustomerFaceHash, customerInfo.CustomerName);
                }

                // 6. Update status
                if (trainingSucceeded && recordAdded)
                {
                    StatusText      = "Success!";
                    StatusTextColor = Util.ToBrush("green");
                }
                else
                {
                    customerInfo          = null;
                    IsRegistrationEnabled = true;
                    StatusText            = "Please try again later";
                    StatusTextColor       = Util.ToBrush("red");
                    ResumeCamera?.Invoke(this, EventArgs.Empty);
                }
            }
            catch (Exception)
            {
                customerInfo          = null;
                IsRegistrationEnabled = true;
                StatusText            = "Please try again";
                StatusTextColor       = Util.ToBrush("red");
                ResumeCamera?.Invoke(this, EventArgs.Empty);
            }
        }