Пример #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;
     }
 }
Пример #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);
        }
Пример #3
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));
            }
        }
Пример #4
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);
        }