之前的文章介绍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(攻击人脸(假人脸))。文章来源:https://www.toymoban.com/news/detail-814568.html
参考文献:
[1]https://github.com/ViewFaceCore/ViewFaceCore
[2]https://blog.csdn.net/gc_2299/article/details/131880084文章来源地址https://www.toymoban.com/news/detail-814568.html
到了这里,关于测试开源C#人脸识别模块ViewFaceCore(6:视频活体检测)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!