Пример #1
0
        private async Task startTraining()
        {
            await ensurePersonGroup(txtPersonGroupId.Text, txtPersonGroupName.Text);

            if (-1 == lstPersons.SelectedIndex)
            {
                await WaitCallLimitPerSecondAsync();

                if ("" == txtPersonName.Text)
                {
                    ShowErrorMsg("Select from the list or add a new person name");
                }
                else
                {
                    CreatePersonResult personResult = await faceServiceClient.CreatePersonInPersonGroupAsync(txtPersonGroupId.Text, txtPersonName.Text);

                    MessageBox.Show("Please load persons list and select from there and upload.", "Person Added");
                }
            }
            else
            {
                await uploadImages(txtPersonGroupId.Text, prsns[lstPersons.SelectedIndex].PersonId, txtImgFolder.Text);

                beginTraining(txtPersonGroupId.Text);
            }
        }
Пример #2
0
        private async void CreatePerson(String personName)
        {
            var db = dbFactory.Open();

            PersonModel person = db.Single <PersonModel>(x => x.name == personName);

            if (person == null)
            {
                person         = new PersonModel();
                person.name    = personName;
                person.groupId = group.id;

                try
                {
                    CreatePersonResult rPerson = await faceServiceClient.CreatePersonInPersonGroupAsync(group.groupId, personName);

                    _(String.Format("{0} created with id {1}", personName, rPerson.PersonId));
                    person.personId = rPerson.PersonId.ToString();
                    db.Insert(person);

                    DataTable result = LoadPersonsData();
                    GridPersonModel.ItemsSource = result.DefaultView;
                }
                catch (FaceAPIException e)
                {
                    _(e.Message);
                }
                db.Close();
            }
            else
            {
                MessageBox.Show("That person already exists!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private async Task CreatePerson(string personname, string groupId, string imagePath)
        {
            CreatePersonResult person = await fsClient.CreatePersonInPersonGroupAsync(groupId, personname);

            Stream s = File.OpenRead(imagePath);
            await fsClient.AddPersonFaceInPersonGroupAsync(groupId, person.PersonId, s);
        }
Пример #4
0
        private async void addPersonButton_Click(object sender, EventArgs e)
        {
            PersonGroup selectedPersonGroup = personGroups[personGroupSelector.SelectedIndex];

            if (personSelector.Text.Length != 0)
            {
                if (personSelector.Text.Length > 0)
                {
#if USE_OPENCV
                    int maxPersonNum = 0;
                    try
                    {
                        using (StreamReader r = new StreamReader(selectedPersonGroup.PersonGroupId + "/Persons.dat"))
                        {
                            while (!r.EndOfStream)
                            {
                                string   line      = r.ReadLine();
                                string[] parts     = line.Split('|');
                                int      personNum = Convert.ToInt32(parts[1]);
                                if (personNum > maxPersonNum)
                                {
                                    maxPersonNum = personNum;
                                }
                            }
                            r.Close();
                            maxPersonNum++;
                        }
                    }
                    catch (Exception)
                    {
                    }
                    try
                    {
                        using (StreamWriter s = new StreamWriter(selectedPersonGroup.PersonGroupId + "/Persons.dat", true))
                        {
                            s.WriteLine(personSelector.Text + "|" + maxPersonNum);
                            s.Close();
                        }
                    }
                    catch (Exception)
                    {
                    }
#else
                    await faceServiceClient.CreatePersonInPersonGroupAsync(selectedPersonGroup.PersonGroupId, personSelector.Text);
#endif
                    persons = await GetPersonsInPersonGroup(selectedPersonGroup.PersonGroupId);

                    personSelector.SelectedIndex = -1;
                    personSelector.Items.Clear();
                    foreach (Person person in persons)
                    {
                        personSelector.Items.Add(person.Name);
                    }
                }
            }
            deletePersonButton.Enabled = true;
            addPersonButton.Enabled    = false;
        }
        /// <summary>
        /// Used to add a person to a group before adding photos.
        /// </summary>
        /// <param name="employeeObjectId">Immutable record identifier for person.</param>
        /// <param name="employeeId">Context-specific employee ID</param>
        /// <param name="personName">Person's display name</param>
        /// <param name="groupId">PersonGroup Id, if different from initialized default</param>
        /// <returns></returns>
        public async Task <Guid> CreatePersonInPersonGroupAsync(string employeeObjectId, string employeeId, string personName, string groupId = "")
        {
            var targetGroup = string.IsNullOrEmpty(groupId) ? _defaultPersonGroupId : groupId;
            var group       = await GetPersonGroupOrCreateAsync(targetGroup);

            var creationResult = await _client.CreatePersonInPersonGroupAsync(group.PersonGroupId, personName, JsonConvert.SerializeObject(new { EmployeeObjectId = employeeObjectId, EmployeeId = employeeId }));

            return(creationResult.PersonId);
        }
        private async Task <CreatePersonResult> createPersonAsync(PersonalItem personalItem)
        {
            CreatePersonResult personResult = await faceServiceClient.CreatePersonInPersonGroupAsync(
                personalItem.personGroupId,
                personalItem.name
                );

            return(personResult);
        }
Пример #7
0
        public async Task <string> RegisterUser(List <Stream> listUserImages, string personName = "")
        {
            try
            {
                #region TestBed
                if (listUserImages == null)
                {
                    listUserImages = new List <Stream>();

                    string directoryPath = @"C:\Users\Sachin13390\Desktop\Face_Data";

                    string[] allDirectory = Directory.GetDirectories(directoryPath);

                    foreach (string dir in allDirectory)
                    {
                        personName = Path.GetFileName(dir);
                        string[] file_Paths = Directory.GetFiles(dir);
                        foreach (string filePath in file_Paths)
                        {
                            listUserImages.Add(GetImageStream(filePath));
                        }
                    }
                }
                #endregion

                #region Images

                CreatePersonResult person = await faceServiceClient.CreatePersonInPersonGroupAsync(personGroupId, personName);

                foreach (Stream imageStream in listUserImages)
                {
                    await faceServiceClient.AddPersonFaceInPersonGroupAsync(personGroupId, person.PersonId, imageStream);
                }

                await faceServiceClient.TrainPersonGroupAsync(personGroupId);

                TrainingStatus trainingStatus = null;
                while (true)
                {
                    trainingStatus = await faceServiceClient.GetPersonGroupTrainingStatusAsync(personGroupId);

                    if (trainingStatus.Status != Status.Running)
                    {
                        break;
                    }
                    await Task.Delay(1000);
                }
                #endregion

                return(SUCCESSFULL);
            }
            catch (Exception exception)
            {
                return(FAILURE);
            }
        }
Пример #8
0
        public async void AddNewUser(string newUserName, string imagesFolderPath, string groupId)
        {
            CreatePersonResult person = await faceServiceClient.CreatePersonInPersonGroupAsync(groupId, newUserName);

            foreach (string imagePath in Directory.GetFiles(imagesFolderPath))
            {
                using (Stream s = File.OpenRead(imagePath))
                {
                    await faceServiceClient.AddPersonFaceInPersonGroupAsync(groupId, person.PersonId, s);
                }
            }
        }
Пример #9
0
        public static async Task <string> CreatePersonInPersonGroup(PersonBindingModel model)
        {
            var createPersonResult =
                await FaceServiceClient.CreatePersonInPersonGroupAsync(model.PersonGroupId, model.Name);

            foreach (var faceUrl in model.FacesUrl)
            {
                await FaceServiceClient.AddPersonFaceInPersonGroupAsync(model.PersonGroupId,
                                                                        createPersonResult.PersonId, faceUrl);
            }

            return(createPersonResult.PersonId.ToString());
        }
        public async void TrainFaces(string[] trainImages)
        {
            //await faceServiceClient.CreatePersonGroupAsync(personGroupId, "Admins");
            CreatePersonResult admin = await faceServiceClient.CreatePersonInPersonGroupAsync(personGroupId, "Akos");

            foreach (string imagePath in trainImages)
            {
                using (Stream s = File.OpenRead(imagePath))
                {
                    await faceServiceClient.AddPersonFaceInPersonGroupAsync(personGroupId, admin.PersonId, s);
                }
            }

            await faceServiceClient.TrainPersonGroupAsync(personGroupId);
        }
Пример #11
0
        public async Task <String> ProcessRegistrationImage()
        {
            Stream userRegisterImage = await this.Request.Content.ReadAsStreamAsync();

            userRegisterImage.Position = 0;
            string imageRegistrationStatus = string.Empty;

            if (userRegisterImage == null)
            {
            }
            else
            {
                try
                {
                    string             personImageName = string.Format("UserImage_{0}", new Random().Next(0, 999).ToString("D3"));
                    CreatePersonResult person          = await faceServiceClient.CreatePersonInPersonGroupAsync(personGroupId, personImageName);

                    await faceServiceClient.AddPersonFaceInPersonGroupAsync(personGroupId, person.PersonId, userRegisterImage);

                    await faceServiceClient.TrainPersonGroupAsync(personGroupId);

                    TrainingStatus trainingStatus = null;
                    while (true)
                    {
                        trainingStatus = await faceServiceClient.GetPersonGroupTrainingStatusAsync(personGroupId);

                        if (trainingStatus.Status != Microsoft.ProjectOxford.Face.Contract.Status.Running)
                        {
                            break;
                        }
                        await Task.Delay(1000);
                    }
                    imageRegistrationStatus = trainingStatus.Status.ToString();
                }
                catch (Exception ex)
                {
                    imageRegistrationStatus = ex.Message;
                }
            }

            return(imageRegistrationStatus);
        }
Пример #12
0
 public async Task <Guid> PersonCreateAsync(string groupCode, string personName)
 {
     // ToDo: Invoke the API method to create a new person in an existing person group
     return((await faceServiceClient.CreatePersonInPersonGroupAsync(groupCode, personName)).PersonId);
 }