예제 #1
0
        //private void disposeMic()
        //{
        //this.micClient.EndMicAndRecognition();
        //this.micClient.Dispose();
        //this.micClient = null;
        //}

        private void btnNormalLogin_Click(object sender, RoutedEventArgs e)
        {
            if (String.Equals(txtUsername.Text, "Username") || String.Equals(txtUsername.Text.Trim(), ""))
            {
                MessageBox.Show("Please enter your username!", "Error", MessageBoxButton.OK);
            }
            else
            {
                //Login
                UserTableDataContext dataContext = new UserTableDataContext();
                var usr = dataContext.Users.SingleOrDefault(x => x.username == txtUsername.Text && x.password == txtPassword.Password);
                if (usr != null)
                {
                    MessageBox.Show("Login successful", "Login successful", MessageBoxButton.OK);
                    txtUsername.Focus();
                    //GC.Collect();
                    //disposeMic();

                    MainMenuWIthLights ss = new MainMenuWIthLights(usr);
                    ss.Show();
                    this.Close();
                    return;
                }
                else
                {
                    MessageBox.Show("Login Failed", "Login Failed", MessageBoxButton.OK);
                }
            }
        }
        private async void verifySpeaker(Stream audioStream)
        {
            try
            {
                lblStatus.Content = "Verifying..";
                Verification response = await _serviceClient.VerifyAsync(audioStream, _speakerId);

                //statusResTxt.Text = response.Result.ToString();
                //confTxt.Text = response.Confidence.ToString();
                if (response.Result == Result.Accept)
                {
                    MessageBox.Show("Login successful, with confidence: " + response.Confidence.ToString(), "Successful", MessageBoxButton.OK);
                    lblStatus.Content = "Verification successful";

                    MainMenuWIthLights ss = new MainMenuWIthLights(user);
                    ss.Show();
                    this.Close();
                    return;
                }
                else
                {
                    MessageBox.Show("Login failed, with confidence: " + response.Confidence.ToString(), "Failed", MessageBoxButton.OK);
                    lblStatus.Content = "Verification failed";
                }
            }
            catch (VerificationException exception)
            {
                lblStatus.Content = "Cannot verify speaker: " + exception.Message;
            }
            catch (Exception e)
            {
                lblStatus.Content = "Error: " + e;
            }
        }
        private async void btnCapture_Click(object sender, RoutedEventArgs e)
        {
            image2.Visibility = Visibility.Visible;
            image2.Source     = image1.Source;
            image1.Visibility = Visibility.Hidden;

            tempfilename = Helper.SaveTempImageCapture((BitmapSource)image2.Source);
            webcam.Stop();

            //Login
            UserTableDataContext dataContext = new UserTableDataContext();
            var usr = dataContext.Users.SingleOrDefault(x => x.username == this.username);

            ////label.Content = "Please wait...";
            if (usr != null)
            {
                FaceAPIHelper tempImage = new FaceAPIHelper();
                string        result    = await tempImage.UploadOneFace(tempfilename);

                if (String.IsNullOrEmpty(result))
                {
                    tempFaceCollection = tempImage.faceResultCollection;
                }
                else
                {
                    MessageBox.Show(result, "Error", MessageBoxButton.OK);
                    redo();
                    return;
                }


                //Get comparison face for verify
                //CHANGE HERE TO BE DYNAMIC
                string        imagepath = usr.photofile; // dt.Rows[0][0].ToString();
                FaceAPIHelper realImage = new FaceAPIHelper();
                result = await realImage.UploadOneFace(imagepath);

                if (String.IsNullOrEmpty(result))
                {
                    databaseFaceCollection = realImage.faceResultCollection;
                }
                else
                {
                    MessageBox.Show(result, "Error", MessageBoxButton.OK);
                    redo();
                    return;
                }

                //Verify
                string res = await realImage.Verify2Faces(tempFaceCollection, databaseFaceCollection);

                if (res.ToLower().Contains("successful"))
                {
                    MessageBox.Show(res, "Successful", MessageBoxButton.OK);
                    webcam.Stop();

                    MainMenuWIthLights ss = new MainMenuWIthLights(usr);
                    ss.Show();
                    this.Close();
                    return;
                }
                else
                {
                    MessageBox.Show(res, "Error", MessageBoxButton.OK);
                    redo();
                    return;
                }
            }
            else
            {
                MessageBox.Show("User not found", "Error", MessageBoxButton.OK);
                MainWindow mw = new MainWindow();
                mw.Show();
                webcam.Stop();
                this.Close();
            }
        }