C#WinForm安装ViewFaceCore实现人脸识别

C#WinForm安装ViewFaceCore实现人脸识别

编码文章call10242025-03-06 11:48:2837A+A-

ViewFaceCore是基于 SeetaFace6 的 .NET 人脸识别解决方案,受到了 SeetaFaceEngine.Net 的启发;开源、免费、跨平台 (win/linux)

一、效果展示

二、VS2022

界面设计

后台代码

使用 nuget 安装依赖

三、代码实现

引用

using SkiaSharp;
using System.Diagnostics;
using ViewFaceCore;
using ViewFaceCore.Core;
using ViewFaceCore.Model;

人脸识别

string imagePath = pictureBox1.ImageLocation;


//人脸识别
using var bitmap = SKBitmap.Decode(imagePath).ToFaceImage();
using FaceDetector faceDetector = new FaceDetector();
FaceInfo[] infos = faceDetector.Detect(bitmap);


richTextBox1.Clear();
richTextBox1.AppendText($"识别到的人脸数量:{infos.Length} 个人脸信息:"+ "\r\n");
richTextBox1.AppendText($"No\t人脸置信度\t位置信息"+ "\r\n");
for (int i = 0; i < infos.Length; i++)
{
	richTextBox1.AppendText($"{i}\t{infos[i].Score:f8}\t{infos[i].Location}" + "\r\n");
}

画方框,标记人脸

//画方框,标记人脸
var bitmap2 = Image.FromFile(imagePath);
using (Graphics g = Graphics.FromImage(bitmap2))
{
	g.DrawRectangles(new Pen(Color.Red, 4), infos.Select(p => new RectangleF(p.Location.X, p.Location.Y, p.Location.Width, p.Location.Height)).ToArray());
}
var names = imagePath.Split(".");
string newName = names[0] + "2"+"." + names[1];
bitmap2.Save(newName);
pictureBox2.ImageLocation = newName;

活体检测

//活体检测
using FaceLandmarker faceMark = new FaceLandmarker();
using FaceAntiSpoofing faceAntiSpoofing = new FaceAntiSpoofing();
var info = faceDetector.Detect(bitmap).First();
var markPoints = faceMark.Mark(bitmap, info);
Stopwatch sw = Stopwatch.StartNew();
sw.Start();
var result = faceAntiSpoofing.AntiSpoofing(bitmap, info, markPoints);
richTextBox1.AppendText($"活体检测结果:{result.Status},清晰度:{result.Clarity},真实度:{result.Reality},耗时:{sw.ElapsedMilliseconds}ms");
sw.Stop();
点击这里复制本文地址 以上内容由文彬编程网整理呈现,请务必在转载分享时注明本文地址!如对内容有疑问,请联系我们,谢谢!
qrcode

文彬编程网 © All Rights Reserved.  蜀ICP备2024111239号-4