protected override void Capture_ImageGrabbed(object sender, EventArgs e)
 {
     try
     {
         MyMat = null;
         MyMat = new Mat();
         if (MyCapture == null)
         {
             return;
         }
         MyCapture.Retrieve(MyMat, 0);
         if (icPass && white != null)
         {
             FaceOut++;
             if (FaceOut >= FaceOutCount)
             {
                 white.Value.IdNo.ToSaveLog("比对超时,比对失败:");
                 PhotoErr = FaceFun.BitmapToByte(MyMat.Bitmap);
                 icPass   = false;
                 ShowEventMsg("对比失败", MsgType.FaceErr);
                 Dispatcher.InvokeAsync(() => { MiniImg.Source = FaceFun.ByteToBitmapImage(PhotoErr); });
                 ShowEventMsg("失败:当前用户与身份证对比失败", MsgType.Info);
             }
             else
             {
                 ShowEventMsg("识别中" + (FaceOutCount - FaceOut), MsgType.TipErr);
                 CameraRft = Face.FaceTz(MyMat);
                 if (Face.VerifyIr.ToInt32() == 0)
                 {
                     FaceIr = FaceFun.FaceResult(CameraRft, Rft2);
                     if (FaceIr > _confidence)
                     {
                         try
                         {
                             //保存识别到的摄像头图片
                             white.Value.IdNo.ToSaveLog("保存检票成功照片:");
                             //  MyMat.Bitmap.Save(string.Format("{0}{1}.jpg", CamPath, Cvr.Info.Number),ImageFormat.Jpeg);
                             PhotoOk = FaceFun.BitmapToByte(MyMat.Bitmap);
                             ShowEventMsg("比对成功", MsgType.TipOk);
                             FaceIr.ToString().ToSaveLog(white.Value.IdNo + " 比对成功,相似度:");
                             FacePass = true; //当取信值大于80%认为是同一个人比对成功
                         }
                         catch (Exception ex)
                         {
                             ex.ToSaveLog("OnComplete:");
                         }
                     }
                 }
             }
         }
         //摄像头视频流输出
         Dispatcher.Invoke(() => { CameraPic1.ImageView = icPass && !FacePass ? Face.FaceBitmapSource : MyMat.Bitmap; });
     }
     catch (Exception ex)
     {
         ex.ToSaveLog("Capture_ImageGrabbed:");
     }
 }
Пример #2
0
        protected override void Capture_ImageGrabbed(object sender, EventArgs e)
        {
            try
            {
                MyMat = null;
                MyMat = new Mat();
                if (MyCapture == null)
                {
                    return;
                }
                if (Cvr == null)
                {
                    "身份证硬件初始化失败".ToSaveLog("FaceIdView.Cature_ImageGrabbed:"); return;
                }
                MyCapture.Retrieve(MyMat);
                if (CvrPass && !FacePass)
                {
                    FaceOut++;
                    if (FaceOut >= FaceOutCount)
                    {
                        Cvr.Info.Number.ToSaveLog("比对超时,比对失败:");
                        PhotoErr = FaceFun.BitmapToByte(MyMat.Bitmap);

                        CvrPass = false;
                        ShowEventMsg("比对超时:当前用户与身份证对比失败", MsgType.Info);
                        return;
                    }
                    ShowEventMsg("识别中" + (FaceOutCount - FaceOut), MsgType.TipErr);
                    CameraRft = Face.FaceTz(MyMat);
                    if (Face.VerifyIr.ToInt32() == 0)
                    {
                        FaceIr = FaceFun.FaceResult(CameraRft, Rft2);
                        if (FaceIr > _confidence)
                        {
                            try
                            {
                                //保存识别到的摄像头图片
                                Cvr.Info.Number.ToSaveLog("保存检票成功照片:");
                                //  MyMat.Bitmap.Save(string.Format("{0}{1}.jpg", CamPath, Cvr.Info.Number),ImageFormat.Jpeg);
                                PhotoOk = FaceFun.BitmapToByte(MyMat.Bitmap);
                                ShowEventMsg("比对成功", MsgType.TipOk);
                                FaceIr.ToString().ToSaveLog(Cvr.Info.Number + " 比对成功,相似度:");
                                FacePass = true; //当取信值大于80%认为是同一个人比对成功
                            }
                            catch (Exception ex)
                            {
                                ex.ToSaveLog("OnComplete:");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ex.ToSaveLog("Capture_ImageGrabbed:");
            }
        }
Пример #3
0
 /// <summary> 获取实时摄像头视频流 </summary>
 protected virtual Bitmap GetCamBitmap()
 {
     try
     {
         lock (Obj)
         {
             var mat = MyCapture.QueryFrame();
             if (CvrPass && !FacePass)
             {
                 FaceOut++;
                 if (FaceOut >= FaceOutCount)
                 {
                     FaceOut = 0;
                     //var errPhoto = string.Format("{0}CamPhoto\\Err_{1}.jpg", FaceFun.BaseDir, Cvr.Info.Number);
                     //mat.Bitmap.Save(errPhoto, ImageFormat.Jpeg);
                     //Thread.Sleep(100);
                     return(mat.Bitmap);
                 }
                 ShowEventMsg("识别中" + (FaceOutCount - FaceOut), MsgType.TipErr);
                 CameraRft = Face.FaceTz(mat);
                 if (Face.VerifyIr.ToInt32() == 0)
                 {
                     FaceIr = FaceFun.FaceResult(CameraRft, Rft2);
                     if (FaceIr > _confidence)
                     {
                         try
                         {
                             //保存识别到的摄像头图片
                             //   mat.Bitmap.Save(string.Format("{0}CamPhoto\\{1}.jpg", FaceFun.BaseDir, Cvr.Info.Number),ImageFormat.Jpeg);
                             ShowEventMsg("比对成功", MsgType.TipOk);
                             FaceIr.ToString().ToSaveLog(Cvr.Info.Number + " 比对成功,相似度:");
                             FacePass = true; //当取信值大于80%认为是同一个人比对成功
                         }
                         catch (Exception ex)
                         {
                             ex.ToSaveLog("OnComplete:");
                         }
                     }
                 }
                 return(Face.FaceBitmapSource);
             }
             return(mat.Bitmap);
         }
     }
     catch (Exception ex)
     {
         ex.ToSaveLog("Capture_ImageGrabbed:");
     }
     return(null);
 }