Exemplo n.º 1
0
        private void OnCapturingCompleted(IAsyncResult ar)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new AsyncCallback(OnCapturingCompleted), ar);
            }
            else
            {
                try
                {
                    var status = _biometricClient.EndCapture(ar);

                    if (status != NBiometricStatus.Ok)
                    {
                        CaptureFailedFormSettings();
                        _subject.Faces[0].Image = null;
                        _currentop = Ops.Capturingfailed;
                    }
                    else
                    {
                        _currentop = Ops.Ongoing;

                        _biometricClient.BeginVerify(_subjectFromFile, _subject, OnVerifyCompleted, null);
                    }
                }
                catch (Exception)
                {
                    _biometricClient.Cancel();
                    CheckCamera();
                    CheckLicense();
                    Close();
                }
            }
        }
Exemplo n.º 2
0
        private void OnCapturingComplete(IAsyncResult r)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new AsyncCallback(OnCapturingComplete), r);
            }
            else
            {
                try
                {
                    var status = _biometricClient.EndCapture(r);

                    if (status == NBiometricStatus.Ok)
                    {
                        TemplateLoginForm = _subject.GetTemplateBuffer().ToArray();

                        _enumoperation = Modes.Initialization;
                        if (_subject.Faces.Count > 1)
                        {
                            TemplateLoginForm = null;
                            lblInfo.Text      = Resources.ManyFaces;
                            lblInfo.ForeColor = Color.Red;
                            CapturingOperationInit();
                            _subject.Faces[0].Image = null;
                            _biometricClient.BeginCapture(_subject, OnCapturingComplete, null);
                        }
                        else
                        {
                            CloseButtonCapSuccessConfig();
                            _enumoperation = Modes.Capturesuccess;
                        }
                    }
                    else
                    {
                        TemplateLoginForm = null;

                        lblInfo.Text      = Resources.RestartCapture + "\n" + status;
                        lblInfo.ForeColor = Color.Red;
                        CapturingOperationInit();
                        _enumoperation          = Modes.Initialization;
                        _subject.Faces[0].Image = null;
                        _biometricClient.BeginCapture(_subject, OnCapturingComplete, null);
                    }
                }
                catch (InvalidOperationException)
                {
                    CheckCamera();
                    CheckLicense();
                    CapturingOperationInit();
                    _enumoperation = Modes.Initialization;
                }
                catch (Exception)
                {
                    CheckCamera();
                    CheckLicense();
                    CapturingOperationInit();

                    _enumoperation = Modes.Initialization;
                }
            }
        }
Exemplo n.º 3
0
        private void OnCapturingCompleted(IAsyncResult r)
        {
            if (InvokeRequired)
            {
                BeginInvoke(new AsyncCallback(OnCapturingCompleted), r);
            }
            else
            {
                try
                {
                    var status = _biometricClient.EndCapture(r);
                    // If Stop button was pushed
                    if (status == NBiometricStatus.Canceled)
                    {
                        return;
                    }

                    lblStatus.Text = status.ToString();
                    if (status != NBiometricStatus.Ok)
                    {
                        // Since capture failed start capturing again
                        _subject.Faces[0].Image = null;
                        _biometricClient.BeginCapture(_subject, OnCapturingCompleted, null);
                    }
                    else
                    {
                        if (_subject.Faces[0].Image != null)
                        {
                            //facesView.Image = image;
                            var size = new Size {
                                Width = int.Parse(Settings.Default.ImageWidth), Height = int.Parse(Settings.Default.ImageHeight)
                            };
                            var memoryStream = new MemoryStream();
                            _subject.Faces[0].Image.ToBitmap().Save(memoryStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                            var faceBoundingRect = _subject.Faces[0].Objects[0].BoundingRect;
                            //var resizedImage = _subject.Faces[0].Image.Crop(50, 50, 50, 50).ToBitmap();

                            //int widthOffset;
                            //if (faceBoundingRect.Left > faceBoundingRect.Right)
                            //{
                            //    //widthOffset = 2*tt.Right/6 + tt.Width;
                            //    widthOffset = (faceBoundingRect.Left - faceBoundingRect.Right) / 3 + faceBoundingRect.Width + 50;
                            //}
                            //else
                            //{
                            //    //widthOffset = 2*tt.Left/6 + tt.Width;
                            //    //widthOffset = tt.Left + tt.Width + 50;

                            //    widthOffset = (faceBoundingRect.Right - faceBoundingRect.Left) / 3 + faceBoundingRect.Width;
                            //}

                            //if (faceBoundingRect.Left > faceBoundingRect.Right)
                            //{
                            //    //widthOffset = tt.Left - tt.Right;
                            //    widthOffset = (faceBoundingRect.Right - faceBoundingRect.Right) / 2 + faceBoundingRect.Width / 2 + 50;
                            //}
                            //else
                            //{
                            //    widthOffset = faceBoundingRect.Right - faceBoundingRect.Left;
                            //    widthOffset = (faceBoundingRect.Width * 10) / 100 + faceBoundingRect.Width;
                            //}

                            var resizedImage = ResizeImage(memoryStream, (faceBoundingRect.Location.X - faceBoundingRect.Left) + faceBoundingRect.Width, faceBoundingRect.Height + 50, true, faceBoundingRect.X, faceBoundingRect.Top, faceBoundingRect.Right, faceBoundingRect.Bottom);
                            if (resizedImage != null)
                            {
                                pictureBoxCroped.Image = resizedImage;
                                _croppedPhotoImage     = resizedImage;
                            }
                            _template = _subject.GetTemplateBuffer();
                            EnableControls(false);
                        }

                        //UpdateView(_subject.Faces[0], status);
                    }
                }
                catch (Exception ex)
                {
                    AppUtils.ShowException(ex);
                    lblStatus.Text = string.Empty;
                    EnableControls(false);
                }
            }
        }