基于人脸识别技术实战开发人证比对访客系统

最近有个小区用到了虹软的人脸识别,效果还不错。又有一个项目要用人证访客对比,分享一下项目,希望可以帮到有需要的。

码字前先上项目地址:https://gitee.com/panmingzhi/IdCardFaceIdentifier

首先是读证的问题,我们使用的是华视CVR100U,公司已经用这个型号6年了,以前一卡通的资料都用它录,除了不好看,质量杠杠的。大部人的身份证都是很多年前办理的,所有比对的相似度不要太高。

视频采集还是使用的Aforge,使用 NewFrame 一方面要显示到实时画面,另一方面要异步的与当前读到的证件进行比对。这里请不尝试在NewFrame回调事件中直接显示到pictureBox,请使用如下方式,百试不爽:

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保存一次后再做人证比对,似乎就没问题。

证件比对时还是延续了之前方式,先将证件图片解析成FaceModel,然后将当前视频截图连续与些FaceModel比对,每次读到证件时都更新一次FaceModel。

/**
* 绘制当前帧到控制,必须与获取当前帧互斥
*/
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、提示放证
![在这里插入图片描述](http://ai.arcsoft.com.cn/bbs/data/attachment/forum/201808/02/195358l2385v459xb2w9nb.png)
2、读到证件后立即比对
![在这里插入图片描述](http://ai.arcsoft.com.cn/bbs/data/attachment/forum/201808/02/195404ubbb7irw1wak5fha.png)
3、比对显示结果后将重新回到第一步
![在这里插入图片描述](http://ai.arcsoft.com.cn/bbs/data/attachment/forum/201808/02/195636izfxa2vqbn57qogn.png)
如果有问题的话欢迎多多交流
原帖地址
http://ai.arcsoft.com.cn/bbs/forum.php?mod=viewthread&tid=939&_dsign=fb054263

原文地址:https://www.cnblogs.com/Zzz-/p/10749089.html