最近有個小區用到了虹軟的人臉識別,效果還不錯。又有一個項目要用人證訪客對比,分享一下項目,但願能夠幫到有須要的。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