??之前的文章介绍ViewFaceCore模块的FaceAntiSpoofing类支持单帧活体检测(AntiSpoofing函数)及视频活体检测(AntiSpoofingVideo函数),视频活体检测时从摄像头中抓取一帧图片进行检测,当检测结果状态为Detecting时,继续从摄像头中抓取图片,直至检测结果不为Detecting。本文中主要测试视频活体检测函数AntiSpoofingVideo。
??新建Winform项目,添加以下程序集以支持从摄像头中获取图片及人脸识别。
Hompus.VideoInputDevices DirectShowLib.Standard OpenCvSharp4 OpenCvSharp4.Extensions OpenCvSharp4.runtime.win ViewFaceCore ViewFaceCore.all_models ViewFaceCore.Extension.SkiaSharp ViewFaceCore.runtime.win.x64
??操作摄像头获取图片的示例详见《测试C#使用OpenCvSharp从摄像头获取图片》,调用ViewFaceCore进行视频活体检测的代码如下所示:
FaceDetector faceDetector = new FaceDetector(); FaceLandmarker faceMark = new FaceLandmarker(); FaceAntiSpoofing faceAntiSpoofing = new FaceAntiSpoofing(); AntiSpoofingResult result = null; do { m_capture.Read(m_image); if (m_image.Empty()) continue; var bitmap = SKBitmap.Decode(m_image.ToBytes()); var info = faceDetector.Detect(bitmap).First(); var markPoints = faceMark.Mark(bitmap, info); result = faceAntiSpoofing.AntiSpoofingVideo(bitmap, info, markPoints); } while (result != null && result.Status== AntiSpoofingStatus.Detecting); MessageBox.Show($"活体检测,结果:{result.Status},清晰度:{result.Clarity},真实度:{result.Reality}");
??实际测试过程中人不能移动的太快或完全静止,否则从图片中获取的人脸的清晰度或真实度较低,从而导致活体检测为Spoof(攻击人脸(假人脸))。
参考文献:
[1]https://github.com/ViewFaceCore/ViewFaceCore
[2]https://blog.csdn.net/gc_2299/article/details/131880084