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
 void irSeialPort_DataReceived(object sender, string e)
 {
     try
     {
         _qrInfo = OnlyQr.ReadData(e, MyMatch.Key);
         if (_qrInfo != null)
         {
             if (!_qrInfo.Value.IdNo.IsNullOrEmpty())
             {
                 BarIdNo = _qrInfo.Value.IdNo;
             }
             //黑名单检查
             if (IsCheckBlack && FaceFun.IsInBlack(BarIdNo))
             {
                 LeftImg.Visibility = Visibility.Visible;
             }
             //校验身份证是否为空
             if (IsCheckIdNo && BarIdNo.IsNullOrEmpty())
             {
                 ShowEventMsg("请录入身份证号码.", MsgType.TipErr); return;
             }
             //白名单校验
             var white = CheckWhite(_qrInfo.Value.IdNo);
             //入场校验
             var session = CheckSession(_qrInfo.Value.TicketNo, false);
             if (white && session)
             {
                 if (MyCapture != null)
                 {
                     //取得人脸识别特征码
                     "拍照获取Photo.".ToSaveLog("");
                     using (var myMap = MyCapture.QueryFrame())
                     {
                         if (myMap != null)
                         {
                             PhotoOk = FaceFun.BitmapToByte(myMap.Bitmap);
                         }
                         else
                         {
                             "未取得摄像头Mat数据".ToSaveLog("OnlyQrView.BarCode_OnKeyUp:");
                         }
                     }
                 }
                 InSession();
             }
         }
         else
         {
             ShowEventMsg("检票失败,解码未通过.", MsgType.FaceErr);
         }
     }
     catch (Exception ex)
     {
         ex.ToSaveLog("BarCode_OnKeyUp:");
     }
 }
Пример #4
0
        void irSeialPort_DataReceived(object sender, string e)
        {
            try
            {
                _qrInfo = OnlyQr.ReadData(e, MyMatch.Key);
                if (_qrInfo != null)
                {
                    //白名单校验
                    var white = CheckWhite(_qrInfo.Value.IdNo);
                    //入场校验
                    var session = CheckSession(_qrInfo.Value.TicketNo, false);
                    if (white && session)
                    {
                        Dispatcher.Invoke(() =>
                        {
                            MyArea.Text = string.Format("区域:{0}{1}排{2}座", _qrInfo.Value.Area, _qrInfo.Value.Row, _qrInfo.Value.Seat);
                            MyNum.Text  = "票号:" + _qrInfo.Value.TicketNo;
                            MyType.Text = "类型:散票";
                            MyTime.Text = "时间:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                        });

                        //取得人脸识别特征码
                        Mat myMap = MyCapture.QueryFrame();
                        if (myMap != null)
                        {
                            PhotoOk = FaceFun.BitmapToByte(myMap.Bitmap);
                        }
                        else
                        {
                            "未取得摄像头Mat数据".ToSaveLog("OnlyQrView.BarCode_OnKeyUp:");
                        }
                    }
                }
                else
                {
                    ShowEventMsg("检票失败,解码未通过.", MsgType.FaceErr);
                }
            }
            catch (Exception ex)
            {
                ex.ToSaveLog("BarCode_OnKeyUp:");
            }
        }
Пример #5
0
        /// <summary> 读写IC卡 </summary>
        private int CheckICard()
        {
            try
            {
                "准备请求读卡".ToSaveLog("CheckIcard:");
                FaceFun.TimeStart();
                var icInfo = new IdCardFunc.TicketCardInfo();
                int i      = IdCardFunc.GetTicketData_New(ref icInfo);
                if (i == 0)
                {
                    tempTime = DateTime.Now;
                    icInfo.IDCard.ToSaveLog("读取到IC卡:");
                    //判断是否超过时限
                    if (!icInfo.IDCard.IsNullOrEmpty())
                    {
                        Dispatcher.Invoke(() => MyIdNo.Text = icInfo.IDCard);
                    }
                    var flag = true;
                    Dispatcher.Invoke(() =>
                    { //黑名单检查
                        if (IsCheckBlack && FaceFun.IsInBlack(MyIdNo.Text))
                        {
                            LeftImg.Visibility = Visibility.Visible;
                        }
                        if (IsCheckIdNo && MyIdNo.Text.IsNullOrEmpty())
                        {
                            flag = false;
                        }
                    });
                    if (!flag)
                    {
                        ShowEventMsg("请录入身份证号码.", MsgType.TipErr); return(1);
                    }
                    //检查白名单验证
                    if (!CheckWhite(icInfo.IDCard))
                    {
                        return(1);
                    }
                    PhotoOk = null;
                    lock (Obj)
                    {
                        if (MyCapture != null)
                        {
                            "拍照获取Photo.".ToSaveLog("");
                            using (var myMap = MyCapture.QueryFrame())
                            {
                                if (myMap != null)
                                {
                                    PhotoOk = FaceFun.BitmapToByte(myMap.Bitmap);
                                }
                                else
                                {
                                    "未取得摄像头Mat数据".ToSaveLog("OnlyQrView.BarCode_OnKeyUp:");
                                }
                            }
                        }
                    }
                    //写入本地记录并且通知
                    var info = new SessionsInfo
                    {
                        SessionId    = MyMatch.SessionId,
                        CreateDate   = DateTime.Now,
                        Name         = MyMatch.SessionName,
                        IdNo         = icInfo.IDCard,
                        IdCardPhoto  = null,
                        TakePhoto    = PhotoOk,
                        FaceData     = null,
                        IdAddress    = "",
                        TicketType   = 1,
                        TicketNo     = icInfo.CardNo,
                        Area         = icInfo.StadiumArea,
                        Row          = icInfo.Row,
                        Seat         = icInfo.Position,
                        TelNo        = IrAdvanced.ReadString("TelNo"),
                        TelArea      = IrAdvanced.ReadString("TelArea"),
                        BuyName      = icInfo.Name,
                        BuyPhoto     = null,
                        BuyDate      = null,
                        ValidateType = 4,
                        SyncTime     = null,
                        Status       = 0,
                        Remark       = "",
                        UserName     = AftUserName,
                    };
                    if (FaceFun.AddSessions(info) > 0)
                    {
                        Dispatcher.Invoke(() =>
                        {
                            MyArea.Text = string.Format("区域:{0}区{1}排{2}座", info.Area, info.Row, info.Seat);
                            MyNum.Text  = "票号:" + info.TicketNo;
                            MyType.Text = "类型:年票";
                            MyTime.Text = "时间:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
                        });
                        ShowEventMsg("检票成功", MsgType.FaceOk);
                        Thread.Sleep(500);
                    }

                    FaceFun.TimeStop("IC读写耗时:");
                }
                else if (i == 16)
                {
                    i.ToString().ToSaveLog("已刷卡:");
                    var str = (tempTime == null) ? "拒绝入场" : string.Format("{0}入场", tempTime);
                    ShowEventMsg("一天只能入场一次!\n" + str, MsgType.FaceErr);
                    Thread.Sleep(500);
                }
                else if (i == 1)    //未放卡
                {
                    tempTime = null;
                }
                else
                {
                    i.ToString().ToSaveLog("IC卡读卡失败:");
                    Thread.Sleep(300);
                }

                icPass = false;
                return(i);
            }
            catch (Exception ex)
            {
                ex.ToSaveLog("CheckICard失败:");
            }
            icPass = false;
            return(0);
        }
Пример #6
0
        private void FaceCompare()
        {
            Dispatcher.InvokeAsync(() =>
            {
                ShowEventMsg("识别中", MsgType.TipErr);
                this.MyName.Text = "购票者:";
                this.MyTime.Text = "检票时间:";
                CvrImg.Source    = null;
            });
            try
            {
                "开始识别".ToSaveLog("FaceVerify");
                FaceVerifyData faceVerifyData = faceFactory.FaceVerify(MyMat);

                "识别完成".ToSaveLog("FaceVerify");
                if (faceVerifyData.Success)
                {
                    DateTime checkTime = DateTime.Now;
                    foreach (WhiteNameInfo item in AFT_System.Face.FaceFun.WhiteList)
                    {
                        FaceIr = faceFactory.FaceResult(faceVerifyData.rr_Feature, item.rrfeature);
                        if (FaceIr > _confidence)
                        {
                            if (AFT_System.Face.FaceFun.IsInSessions(item.IdNo, MyMatch.SessionId, out checkTime))
                            {
                                Dispatcher.InvokeAsync(() =>
                                {
                                    CvrImg.Source    = null;
                                    CvrImg.Source    = new BitmapImage(new Uri(item.IdCardPhotoPath, UriKind.Absolute));
                                    this.MyName.Text = "购票者:" + item.BuyName;
                                    this.MyTime.Text = "检票时间:" + checkTime.ToString("yyyy-MM-dd hh:mm");
                                    ShowEventMsg("该人员已检票", MsgType.TipErr);
                                });
                            }
                            else
                            {
                                Dispatcher.InvokeAsync(() =>
                                {
                                    CvrImg.Source = null;
                                    CvrImg.Source = new BitmapImage(new Uri(item.IdCardPhotoPath, UriKind.Absolute));

                                    //CameraPic2.ImageView2 = null;
                                    //CameraPic2.ImageView2 = Face.FaceBitmapSource;


                                    //保存识别到的摄像头图片
                                    item.IdNo.ToSaveLog("保存检票成功照片:");
                                    PhotoOk = FaceFun.BitmapToByte(MyMat.Bitmap);
                                    ShowEventMsg("比对成功", MsgType.FaceOk);
                                    FaceIr.ToString().ToSaveLog(item.IdNo + " 比对成功,相似度:");
                                    if (Cvr != null)
                                    {
                                        Cvr.Info = new CvrInfo()
                                        {
                                            Name      = item.BuyName,
                                            Number    = item.IdNo,
                                            PeopleImg = item.IdCardPhotoPath
                                        };
                                        this.MyName.Text = "购票者:" + item.BuyName;
                                        this.MyTime.Text = "检票时间:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm");
                                        InSession();
                                    }
                                });
                            }
                            FacePass   = true; //当取信值大于80%认为是同一个人比对成功
                            sucessTime = DateTime.Now;
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                ex.ToSaveLog("OnComplete:");
            }
            Compareing = false;
        }