Ejemplo n.º 1
0
 private void ReadImage()
 {
     try
     {
         Image image = imagePath.StartsWith("http") ? Image.FromStream(WebRequest.Create(imagePath).GetResponse().GetResponseStream()) : Image.FromFile(imagePath);
         this.pictureBox1.Image = image;
         InitTimer();
         this.textBox1.Text = "人脸核验中";
         //调整图像宽度,图像宽度必须为4的倍数
         if (image.Width % 4 != 0)
         {
             image = ImageUtil.ScaleImage(image, image.Width - (image.Width % 4), image.Height);
         }
         int result = IDCardUtil.IdCardDataFeatureExtraction(pEngine, image);
         if (result != 0)
         {
             MessageBox.Show("图片特征提取失败");
         }
     }
     catch (Exception e)
     {
         formReturnValue = NOSAVEDIMG;
         closeForm       = true;
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 读卡器读取内容
        /// </summary>
        /// <returns></returns>
        private bool readContent()
        {
            isShow = false;
            //读取身份证信息,这里默认读取成功,具体信息需要根据读卡器内容进行具体实现
            BeginInvoke(new Action(delegate
            {
                IDCardPic.Visible = true;
                Image image       = Image.FromFile(@"替换为当前可用图片绝对地址");
                //调整图像宽度,图像宽度必须为4的倍数
                if (image.Width % 4 != 0)
                {
                    image = ImageUtil.ScaleImage(image, image.Width - (image.Width % 4), image.Height);
                }
                IDCardPic.Image = image;

                nameLabel.Text     = "姓名:张三";
                IdCardLabel.Text   = "证件号:" + IDCardUtil.repleaseIDCard("111111888888888888");
                msgLabel.ForeColor = Color.Red;
                msgLabel.Text      = "请正对摄像机!";
                isRead             = true;
                //提取图片特征值
                int result = IDCardUtil.IdCardDataFeatureExtraction(pEngine, image);
                if (result == 0)
                {
                    isShow = true;
                }
            }));
            return(true);
        }
Ejemplo n.º 3
0
        private void txtCardID_Validated(object sender, EventArgs e)
        {
            //获取得到输入的身份证号码
            string identityCard = txtCardID.Text.Trim();

            if (string.IsNullOrEmpty(identityCard))
            {
                //身份证号码不能为空,如果为空返回
                MessageBox.Show("身份证号码不能为空!");
                if (txtCardID.CanFocus)
                {
                    txtCardID.Focus();//设置当前输入焦点为txtCardID_identityCard
                }
                return;
            }
            else
            {
                //身份证号码只能为15位或18位其它不合法
                if (identityCard.Length != 15 && identityCard.Length != 18)
                {
                    MessageBox.Show("身份证号码为15位或18位,请检查!");
                    if (txtCardID.CanFocus)
                    {
                        txtCardID.Focus();
                    }
                    return;
                }
            }
            string birthday = "";
            string sex      = "";

            if (identityCard.Length == 18)
            {
                var result  = new IDCardUtil().SelectCardCode(identityCard);
                var address = result.Replace(",", "").ToString();
                birthday            = identityCard.Substring(6, 4) + "-" + identityCard.Substring(10, 2) + "-" + identityCard.Substring(12, 2);
                sex                 = identityCard.Substring(14, 3);
                txtCustoAdress.Text = address;
                //性别代码为偶数是女性奇数为男性
                if (int.Parse(sex) % 2 == 0)
                {
                    cbSex.Text = "女";
                }
                else
                {
                    cbSex.Text = "男";
                }
            }
            try
            {
                dtpBirthday.Value = Convert.ToDateTime(birthday);
            }
            catch
            {
                MessageBox.Show("请正确输入证件号码!");
            }
            //cbPassportType.SelectedIndex = 0;
        }
Ejemplo n.º 4
0
 /// <summary>
 ///图像显示到窗体上,得到每一帧图像,并进行处理
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void videoSourcePlayer_Paint(object sender, PaintEventArgs e)
 {
     if (videoSource.IsRunning)
     {
         Bitmap bitmap = videoSource.GetCurrentVideoFrame();
         if (bitmap == null)
         {
             return;
         }
         Graphics          g        = e.Graphics;
         float             offsetX  = videoSource.Width * 1f / bitmap.Width;
         float             offsetY  = videoSource.Height * 1f / bitmap.Height;
         AFIC_FSDK_FACERES faceInfo = new AFIC_FSDK_FACERES();
         int result = IDCardUtil.FaceDataFeatureExtraction(pEngine, true, bitmap, ref faceInfo);
         if (result == 0 && faceInfo.nFace > 0)
         {
             string message = "";
             if (isShow && isRead)
             {
                 float pSimilarScore = 0;
                 int   pResult       = 0;
                 float threshold     = 0.82f;
                 float.TryParse(scoreText.Text, out threshold);
                 result = IDCardUtil.FaceIdCardCompare(ref pSimilarScore, ref pResult, pEngine, threshold);
                 if (result == 0)
                 {
                     if (threshold > pSimilarScore)
                     {
                         msgLabel.ForeColor = Color.Red;
                         msgLabel.Text      = "人证核验失败";
                     }
                     else
                     {
                         msgLabel.ForeColor = Color.Green;
                         msgLabel.Text      = "人证核验成功";
                     }
                 }
                 message = "相似度:" + pSimilarScore;
             }
             else
             {
                 msgLabel.ForeColor = Color.Red;
                 msgLabel.Text      = "请放置身份证";
             }
             ASF_SingleFaceInfo maxFace = IDCardUtil.GetMaxFace(faceInfo);
             RECT  rect   = maxFace.faceRect;
             float x      = rect.left * offsetX;
             float width  = rect.right * offsetX - x;
             float y      = rect.top * offsetY;
             float height = rect.bottom * offsetY - y;
             using (Pen pen = new Pen(Color.Red))
             {
                 g.DrawRectangle(pen, x, y, width, height);
             }
         }
     }
 }
Ejemplo n.º 5
0
        private void CompareTest(string sfzImg, string paiZhaoImg)
        {
            Bitmap Bitmap = new Bitmap(paiZhaoImg);

            int res = IDCardUtil.IdCardDataFeatureExtraction(pEngine, Image.FromFile(sfzImg));

            if (res == 0)
            {
                AFIC_FSDK_FACERES faceInfo = new AFIC_FSDK_FACERES();
                int result2 = IDCardUtil.FaceDataFeatureExtraction(pEngine, false, Bitmap, ref faceInfo);
                if (result2 == 0 && faceInfo.nFace > 0)
                {
                    float pSimilarScore = 0;
                    int   pResult       = 0;
                    float threshold     = 0.82f;
                    int   result3       = IDCardUtil.FaceIdCardCompare(ref pSimilarScore, ref pResult, pEngine, threshold);
                    if (result3 == 0)
                    {
                        Console.WriteLine("相似度:" + pSimilarScore);
                        if (pSimilarScore >= GetFaceThreshold())
                        {
                            timer.Close();
                            MessageBox.Show("活体,相似度" + pSimilarScore + ",人脸验证通过!");
                            App.Current.Dispatcher.Invoke((Action)(() =>
                            {
                                this.Close();
                                CameraHelper.CloseDevice();
                                Console.WriteLine("关闭摄像头");
                                int retCode = ASIDCardFunctions.ArcSoft_FIC_UninitialEngine(pEngine);
                                Console.WriteLine("UninitEngine Result:" + retCode);
                                Window_Closed();
                            }));
                        }
                        else
                        {
                            MessageBox.Show("相似度" + pSimilarScore + ",人脸验证未通过!");
                            timer.Start();
                        }
                    }
                    else
                    {
                        MessageBox.Show("识别失败,请重试!");
                        timer.Start();
                    }
                }
                else
                {
                    MessageBox.Show("未检测到人脸,请重试!");
                    timer.Start();
                }
            }
            else
            {
                MessageBox.Show("1" + Convert.ToString(res));
            }
        }
Ejemplo n.º 6
0
        public void IDNumber15Test()
        {
            Assert.True(IDCardUtil.IsIDNumber15("110101000101100"));

            Assert.False(IDCardUtil.IsIDNumber15("990101000101100"));
            Assert.False(IDCardUtil.IsIDNumber15("119901001301100"));
            Assert.False(IDCardUtil.IsIDNumber15("11990100130110A"));
            Assert.False(IDCardUtil.IsIDNumber15("11010100010110"));
            Assert.False(IDCardUtil.IsIDNumber15("1101010001011000"));
        }
Ejemplo n.º 7
0
        private void videoSourcePlayer1_Paint(object sender, PaintEventArgs e)
        {
            if (closeForm)
            {
                this.Close();
                return;
            }
            if (videoSourcePlayer1.IsRunning)
            {
                Bitmap bitmap = videoSourcePlayer1.GetCurrentVideoFrame();
                if (bitmap == null)
                {
                    return;
                }
                Graphics          g        = e.Graphics;
                float             offsetX  = videoSourcePlayer1.Width * 1f / bitmap.Width;
                float             offsetY  = videoSourcePlayer1.Height * 1f / bitmap.Height;
                AFIC_FSDK_FACERES faceInfo = new AFIC_FSDK_FACERES();
                int result = IDCardUtil.FaceDataFeatureExtraction(pEngine, true, bitmap, ref faceInfo);
                if (result == 0 && faceInfo.nFace > 0)
                {
                    float pSimilarScore = 0;
                    int   pResult       = 0;
                    float threshold     = 0.82f;
                    result = IDCardUtil.FaceIdCardCompare(ref pSimilarScore, ref pResult, pEngine, threshold);
                    if (result == 0)
                    {
                        if (threshold <= pSimilarScore)
                        {
                            verifyCounts++;
                            this.textBox1.Text = "成功核对; " + verifyCounts.ToString();
                            //this.textBox1.Text = deviceVideo.VideoResolution.FrameSize.Width.ToString() + " " + deviceVideo.VideoResolution.FrameSize.Height.ToString();
                            //定时关闭启动
                            if (!timer.Enabled && verifyCounts > 8)
                            {
                                formReturnValue = FACEMATCHED;
                                timer.Enabled   = true;
                            }
                        }
                    }

                    ASF_SingleFaceInfo maxFace = IDCardUtil.GetMaxFace(faceInfo);
                    RECT  rect   = maxFace.faceRect;
                    float x      = rect.left * offsetX;
                    float width  = rect.right * offsetX - x;
                    float y      = rect.top * offsetY;
                    float height = rect.bottom * offsetY - y;
                    using (Pen pen = new Pen(Color.Red))
                    {
                        g.DrawRectangle(pen, x, y, width, height);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        static void start(Img imgInfo)
        {
            var image = GetImageFromBase64(imgInfo.srcImg.Replace("data:image/png;base64,", "").Replace("data:image/jgp;base64,", "")
                                           .Replace("data:image/jpg;base64,", "").Replace("data:image/jpeg;base64,", ""));
            // Image image = Image.FromFile("C:/xxx/1.jpg");
            int result2 = IDCardUtil.IdCardDataFeatureExtraction(pEngine, image);

            if (result2 != 0)
            {
                Console.WriteLine("idCard失败");
                allSockets.ToList().ForEach(s => s.Send("idCard失败"));
            }
            var bitmap = GetImageFromBase64(imgInfo.faceImg.Replace("data:image/png;base64,", "").Replace("data:image/jgp;base64,", "")
                                            .Replace("data:image/jpg;base64,", "").Replace("data:image/jpeg;base64,", ""));

            // Bitmap bitmap = new Bitmap(@"C:\xxx\xxx.bmp");
            if (bitmap == null)
            {
                return;
            }
            float             offsetX  = image.Width * 1f / bitmap.Width;
            float             offsetY  = image.Height * 1f / bitmap.Height;
            AFIC_FSDK_FACERES faceInfo = new AFIC_FSDK_FACERES();
            int result = IDCardUtil.FaceDataFeatureExtraction(pEngine, false, bitmap, ref faceInfo);

            if (result == 0 && faceInfo.nFace > 0)
            {
                float pSimilarScore = 0;
                int   pResult       = 0;
                float threshold     = 0.82f;
                result = IDCardUtil.FaceIdCardCompare(ref pSimilarScore, ref pResult, pEngine, threshold);
                if (result == 0)
                {
                    Console.WriteLine(pSimilarScore);
                    allSockets.ToList().ForEach(s => s.Send("相似度:" + pSimilarScore.ToString()));
                    if (threshold > pSimilarScore)
                    {
                        Console.WriteLine("失败");
                    }
                    else
                    {
                        Console.WriteLine("成功");
                    }
                }
            }
            else
            {
                allSockets.ToList().ForEach(s => s.Send("不存在人脸"));
                Console.WriteLine("不存在人脸");
            }
        }
        private int ReadImage(string picPath)
        {
            int   status = 0;
            Image image  = ImageUtil.ResizeImage(500, 500, picPath);

            //调整图像宽度,图像宽度必须为4的倍数
            if (image.Width % 4 != 0)
            {
                image = ImageUtil.ScaleImage(image, image.Width - (image.Width % 4), image.Height);
            }
            int result = IDCardUtil.IdCardDataFeatureExtraction(pEngine, image);

            if (result != 0)
            {
                status = 1;
            }
            return(status);
        }
Ejemplo n.º 10
0
        private void Huoti(string sfzImg, string paiZhaoImg)
        {
            MessageBox.Show(paiZhaoImg);

            Bitmap bitmap = new Bitmap(paiZhaoImg);

            ASF_MultiFaceInfo multiFaceInfo = IDCardUtil.DetectFace(pVideoEngine, bitmap);

            ASF_SingleFaceInfo2 maxFace = IDCardUtil.GetMaxFace(multiFaceInfo);

            MRECT rect = maxFace.faceRect;

            if (isRGBLock == false)
            {
                isRGBLock = true;

                ThreadPool.QueueUserWorkItem(new WaitCallback(delegate
                {
                    if (rect.left != 0 && rect.right != 0 && rect.top != 0 && rect.bottom != 0)
                    {
                        try
                        {
                            bool isLiveness = false;


                            ImageInfo imageInfo = IDCardUtil.ReadBMP(bitmap);
                            if (imageInfo == null)
                            {
                                return;
                            }
                            int retCode_Liveness = -1;
                            //RGB活体检测
                            ASF_LivenessInfo liveInfo = IDCardUtil.LivenessInfo_RGB(pVideoRGBImageEngine, imageInfo, multiFaceInfo, out retCode_Liveness);

                            if (retCode_Liveness == 0 && liveInfo.num > 0)
                            {
                                int isLive = MemoryUtil.PtrToStructure <int>(liveInfo.isLive);
                                isLiveness = (isLive == 1) ? true : false;
                            }
                            if (imageInfo != null)
                            {
                                MemoryUtil.Free(imageInfo.imgData);
                            }
                            if (isLiveness)
                            {
                                CompareTest(sfzImg, paiZhaoImg);
                            }
                            else
                            {
                                //显示消息
                                MessageBox.Show("假体!");
                                timer.Start();
                            }
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                        finally
                        {
                            if (bitmap != null)
                            {
                                bitmap.Dispose();
                            }
                            isRGBLock = false;
                        }
                    }
                    else
                    {
                        lock (rectLock)
                        {
                            allRect.left   = 0;
                            allRect.top    = 0;
                            allRect.right  = 0;
                            allRect.bottom = 0;
                        }
                    }
                    isRGBLock = false;
                }));
            }
        }