最近有个小区用到了虹软的人脸识别,效果还不错。又有一个项目要用人证访客对比,分享一下项目,但愿能够帮到有须要的。php
码字前先上项目地址:https://gitee.com/panmingzhi/IdCardFaceIdentifiergit
首先是读证的问题,咱们使用的是华视CVR100U,公司已经用这个型号6年了,之前一卡通的资料都用它录,除了很差看,质量杠杠的。大部人的身份证都是不少年前办理的,全部比对的类似度不要过高。异步
视频采集仍是使用的Aforge,使用 NewFrame 一方面要显示到实时画面,另外一方面要异步的与当前读到的证件进行比对。这里请不尝试在NewFrame回调事件中直接显示到pictureBox,请使用以下方式,百试不爽:ide
private void VideoCaptureDevice_NewFrame(object sender, AForge.Video.NewFrameEventArgs eventArgs) { Bitmap newFrame = (Bitmap)eventArgs.Frame.Clone(); //若是使用视频文件请注释下面的这行代码,表示不对图像进行水平翻转 newFrame.RotateFlip(RotateFlipType.Rotate180FlipY); lock (sync) { if (currentFrame != null) { currentFrame.Dispose(); currentFrame = null; } currentFrame = newFrame; skinPictureBox2.Invalidate(); } }
/** * 绘制当前帧到控制,必须与获取当前帧互斥 */ private void skinPictureBox2_Paint(object sender, PaintEventArgs e) { lock (synCurrentMat) { Bitmap bitmap = GetCurrentFrame(); if (bitmap != null) { e.Graphics.DrawImage(bitmap, new Rectangle(0, 0, skinPictureBox2.Width, skinPictureBox2.Height), new Rectangle(0, 0, bitmap.Width, bitmap.Height), GraphicsUnit.Pixel); } } } //异步的人证对比时,使用此方法再获取实时截图 public Bitmap GetCurrentFrame() { if (captureToken.Token.IsCancellationRequested) return null; lock (sync) { return (currentFrame == null || currentFrame.Width == 0 || currentFrame.Height == 0) ? null : AForge.Imaging.Image.Clone(currentFrame); } }
二代证身份证的读取频率是每1秒读一次,读到证件后,10秒内为人证比对时间,这10秒将再也不读证。10秒内比对成功,显示成功提示2-3秒后,从新再开始读证。 在读证时,若是证件被正确读取到后,要从新拿开再放置证件,这个在华视的产品说明书与SDK都有说明,其它厂家如鼎识也是同样的。 华视阅读器读到的身份证图片与证件信息默认保存在SDK目录下的wz.txt与wz.bmp,使用wz.bmp作比对时,常常报内存出错,后面我将bmp先转成jpg保存一次后再作人证比对,彷佛就没问题。3d
证件比对时仍是延续了以前方式,先将证件图片解析成FaceModel,而后将当前视频截图连续与些FaceModel比对,每次读到证件时都更新一次FaceModel。code
/** * 绘制当前帧到控制,必须与获取当前帧互斥 */ private void skinPictureBox2_Paint(object sender, PaintEventArgs e) { lock (synCurrentMat) { Bitmap bitmap = GetCurrentFrame(); if (bitmap != null) { e.Graphics.DrawImage(bitmap, new Rectangle(0, 0, skinPictureBox2.Width, skinPictureBox2.Height), new Rectangle(0, 0, bitmap.Width, bitmap.Height), GraphicsUnit.Pixel); } } } //异步的人证对比时,使用此方法再获取实时截图 public Bitmap GetCurrentFrame() { if (captureToken.Token.IsCancellationRequested) return null; lock (sync) { return (currentFrame == null || currentFrame.Width == 0 || currentFrame.Height == 0) ? null : AForge.Imaging.Image.Clone(currentFrame); } }
这时截图:(本人不上像,鬼画桃胡将就一下)视频
一、提示放证 二、读到证件后当即比对
三、比对显示结果后将从新回到第一步
若是有问题的话欢迎多多交流 原帖地址 http://ai.arcsoft.com.cn/bbs/forum.php?mod=viewthread&tid=939&_dsign=fb054263blog