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