Esempio n. 1
0
        // Load Properties and test connection
        private async void frmMain_LoadAsync(object sender, EventArgs e)
        {
            // Testing HoloLens IP
            try
            {
                txtHoloLensIP.Text = Properties.Settings.Default.HoloLensIP;
                // TODO test and get HoloLens FaceInformation Server IP config
            }
            catch (Exception ex)
            {
                Debug.Write(ex);
                label6.ForeColor = Color.Red;
            }

            // Testing FaceInformationServer IP
            try
            {
                txtServerURL.Text = Properties.Settings.Default.hosts;
                var result = await RestfulClient.setBaseAddressAsync(txtServerURL.Text);

                updateStatusAsync();
            } catch (Exception ex)
            {
                Debug.Write(ex);
                label5.ForeColor = Color.Red;
            }
        }
Esempio n. 2
0
        private async void UpdatePersonAsync()
        {
            if (findFace && Person == null)
            {
                Stopwatch timer     = Stopwatch.StartNew();
                var       face_data = new WebEntity.Face(Convert.ToBase64String(humanFace.face.ToJpegData()));
                try
                {
                    var response = await RestfulClient.Recognize(face_data);

                    if (response.ReturnCode == 200)
                    {
                        Person = response.Content;
                    }
                    else if (response.ReturnCode == 404)
                    {
                        FailToRecognize = true;
                    }
                }
                catch (Exception ex)
                {
                    Debug.WriteLine("Error on connecting server: " + ex.Message);
                    Person = null;
                }

                timer.Stop();
                TimeSpan timespan = timer.Elapsed;
            }
        }
Esempio n. 3
0
        private async void BtnCheckFace_ClickAsync(object sender, EventArgs e)
        {
            txtUsrename.Text = "";
            txtDetail.Text   = "";
            txtScore.Text    = "";
            Stopwatch timer     = Stopwatch.StartNew();
            var       face_data = new WebEntity.Face(Convert.ToBase64String(cropedFace));

            try
            {
                var response = await RestfulClient.Recognize(face_data);

                if (response.ReturnCode == 200)
                {
                    txtUsrename.Text     = response.Content.Name;
                    txtScore.Text        = response.Content.Face.Score.ToString();
                    txtDetail.Text       = response.Content.Detail;
                    TxtErrorMessage.Text = response.Message;
                }
                else
                {
                    TxtErrorMessage.Text = response.Message;
                }
            } catch (Exception ex)
            {
                Debug.WriteLine("Error on connecting server: " + ex.Message);
                TxtErrorMessage.Text = "Error on connecting server: " + ex.Message;
            }


            timer.Stop();
            TimeSpan timespan = timer.Elapsed;

            Console.WriteLine(String.Format("{0:00}:{1:00}:{2:00}", timespan.Minutes, timespan.Seconds, timespan.Milliseconds / 10));
        }
Esempio n. 4
0
        private async Task <bool> ImportFaceToServerAsync(Person person)
        {
            var response = await RestfulClient.CreatePerson(person);

            if (response.ReturnCode == 200)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 5
0
        private async void BtnDeletePerson_Click(object sender, EventArgs e)
        {
            var response = await RestfulClient.RemovePerson(selectedPerson);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                TxtErrorMessage.Text = "Remove success.";
            }
            else
            {
                TxtErrorMessage.Text = "Unable to remove person.";
            }

            UpdateFlow(FlowAction.Remove);
        }
Esempio n. 6
0
        private async void ListFaceFromServer()
        {
            try
            {
                TxtErrorMessage.Text = "";
                var response = await RestfulClient.ListPeople();

                if (response.ReturnCode == 200)
                {
                    var l_people  = response.Content;
                    var imageList = new ImageList
                    {
                        ImageSize  = new Size(72, 72),
                        ColorDepth = ColorDepth.Depth32Bit
                    };
                    LvFaceList.Clear();
                    people.Clear();
                    foreach (Person person in l_people)
                    {
                        if (person.Face != null && person.Face.FaceData != null)
                        {
                            people.Add(person.Face.Identify.ToString(), person);
                            imageList.Images.Add(person.Face.Identify.ToString(), Base64ToImage(person.Face.FaceData));
                            LvFaceList.LargeImageList = imageList;
                            LvFaceList.Items.Add(person.Name, person.Face.Identify.ToString());
                        }
                    }
                    LvFaceList.LargeImageList = imageList;
                    TxtErrorMessage.Text      = "Success";
                }
                else
                {
                    TxtErrorMessage.Text = response.Message;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Error on connecting server: " + ex.Message);
                Debug.WriteLine(ex.StackTrace);
                TxtErrorMessage.Text = "Error on connecting server: " + ex.Message;
            }
        }
Esempio n. 7
0
        private async void updateStatusAsync()
        {
            try
            {
                var result = await RestfulClient.setBaseAddressAsync(txtServerURL.Text);

                if (result)
                {
                    label5.ForeColor = Color.Green;
                }
                else
                {
                    label5.ForeColor = Color.Red;
                }
            } catch (Exception ex)
            {
                Debug.Write(ex);
                label5.ForeColor = Color.Red;
            }
        }
Esempio n. 8
0
        private async void BtnAddFace_ClickAsync(object sender, EventArgs e)
        {
            switch (captureImageType)
            {
            case CaptureImageType.NewPerson:
            case CaptureImageType.NewPersonCaptured:
            {
                if (cropedFace != null)
                {
                    try
                    {
                        var person = new Person(txtUsrename.Text, txtDetail.Text, new WebEntity.Face(Convert.ToBase64String(cropedFace)));

                        TxtErrorMessage.Text = "";
                        var response = await RestfulClient.CreatePerson(person);

                        if (response.ReturnCode == 200)
                        {
                            TxtErrorMessage.Text = "Success";
                        }
                        else
                        {
                            TxtErrorMessage.Text = response.Message;
                            return;
                        }
                    } catch (Exception ex)
                    {
                        TxtErrorMessage.Text = ex.Message;
                        return;
                    }
                }
                else
                {
                    MessageBox.Show("Please capture face first.", "No face found", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }
            break;

            case CaptureImageType.CurrentPerson:
            case CaptureImageType.UpdatePerson:
            case CaptureImageType.UpdatePersonCaptured:
            {
                if (selectedPerson != null)
                {
                    selectedPerson.Name   = txtUsrename.Text;
                    selectedPerson.Detail = txtDetail.Text;
                    if (cropedFace != null)
                    {
                        selectedPerson.Face.FaceData = Convert.ToBase64String(cropedFace);
                    }
                }

                TxtErrorMessage.Text = "";
                var response = await RestfulClient.UpdatePerson(selectedPerson);

                if (response.ReturnCode == 200)
                {
                    TxtErrorMessage.Text = "Success";
                }
                else
                {
                    TxtErrorMessage.Text = response.Message;
                    return;
                }
            }
            break;
            }


            UpdateFlow(FlowAction.Save);
        }