[C#]winform利用seetaface6实现C#人脸检测活体检测口罩检测年龄预测性别判断眼睛状态检测

2024-01-08 05:57:02

【官方框架地址】

https://github.com/ViewFaceCore/ViewFaceCore
【算法介绍】

SeetaFace6是由中国科技公司自主研发的一款人脸识别技术,它基于深度学习算法,能够快速、准确地识别出人脸,并且支持多种应用场景,如门禁系统、移动支付、安全监控等。SeetaFace6的识别准确率高达99%以上,并且可以在各种复杂的环境下进行工作,如不同的光照条件、面部朝向、面部表情等。

SeetaFace6的研发背景是基于中国科技公司对于人脸识别技术的长期研究和探索。在过去的几年中,随着深度学习技术的不断发展,人脸识别技术也取得了长足的进步。然而,由于人脸识别的技术难度较大,很多算法和模型都存在着准确率不高、容易受到环境影响等问题。因此,开发一种高效、稳定的人脸识别技术一直是人工智能领域的热门话题。

SeetaFace6的设计原理是通过深度学习算法对大量的人脸数据进行训练,从而得到一个能够自动识别出人脸的模型。这个模型可以自动提取出人脸的特征,并且与数据库中的数据进行比对,最终得到识别结果。SeetaFace6采用了多种技术手段来提高识别准确率和稳定性,如使用卷积神经网络进行特征提取、使用数据增强技术增加训练数据量、使用迁移学习等技术来优化模型等。

SeetaFace6的应用场景非常广泛。在门禁系统方面,它可以用于企业的安全防范、学校的校园安全、小区的住宅管理等场景,通过人脸识别技术来控制人员的进出和访问权限。在移动支付方面,它可以用于手机银行、第三方支付等场景,通过人脸识别技术来完成身份验证和支付操作。在安全监控方面,它可以用于公共场所的安全监控、交通监控等场景,通过人脸识别技术来追踪嫌疑人的行踪和身份。

除了以上应用场景外,SeetaFace6还可以应用于人脸美颜、人脸表情识别、人脸合成等领域。例如,在人脸美颜方面,它可以自动识别出人的面部特征和表情,并且根据不同的场景和需求进行美颜处理,让人像更加美丽动人。在人脸表情识别方面,它可以自动识别出人的面部表情和情感状态,并且根据不同的情感状态进行相应的处理和反馈。在人脸合成方面,它可以自动生成与目标人物相似的虚拟人脸图像,并且可以应用于虚拟现实、游戏开发等领域。

总之,SeetaFace6是一款高效、稳定的人脸识别技术,具有广泛的应用前景和市场前景。它的出现将为人脸识别技术的发展和应用带来新的机遇和挑战。未来,随着人工智能技术的不断发展,我们相信SeetaFace6将会在更多的领域得到应用和发展,并且将不断推动人脸识别技术的创新和进步。

【效果展示】

人脸检测

年龄预测?

口罩检测?

性别判断?

眼睛状态判断?

活体检测(局部)?


【官方部分代码】

注意以下是官方实例,不是我示范代码

using SkiaSharp;
using System;
using System.Diagnostics;
using System.Linq;
using System.Numerics;
using ViewFaceCore.Configs;
using ViewFaceCore.Core;
using ViewFaceCore.Extensions;
using ViewFaceCore.Model;

namespace ViewFaceCore.Example.ConsoleApp
{
    internal class Program
    {
        private readonly static string imagePath0 = @"images/Jay_3.jpg";
        private readonly static string imagePath1 = @"images/Jay_4.jpg";
        private readonly static string maskImagePath = @"images/mask_01.jpeg";

        static void Main(string[] args)
        {
            Console.WriteLine("Hello, ViewFaceCore!\n");

            //人脸识别Demo
            FaceDetectorDemo();

            //关键点标记
            FaceMarkDemo();

            //戴口罩识别Demo
            MaskDetectorDemo();

            //质量检测Demo
            FaceQualityDemo();

            //活体检测Demo
            AntiSpoofingDemo();

            //提取并对比特征值
            FaceRecognizerDemo();

            Console.ReadKey();
        }

        static void FaceDetectorDemo()
        {
            using var bitmap = SKBitmap.Decode(imagePath0);
            using FaceDetector faceDetector = new FaceDetector();
            FaceInfo[] infos = faceDetector.Detect(bitmap);
            Console.WriteLine($"识别到的人脸数量:{infos.Length} 个人脸信息:\n");
            Console.WriteLine($"No.\t人脸置信度\t位置信息");
            for (int i = 0; i < infos.Length; i++)
            {
                Console.WriteLine($"{i}\t{infos[i].Score:f8}\t{infos[i].Location}");
            }
            Console.WriteLine();
        }

        static void MaskDetectorDemo()
        {
            using var bitmap0 = SKBitmap.Decode(imagePath0);
            using var bitmap_mask = SKBitmap.Decode(maskImagePath);

            using MaskDetector maskDetector = new MaskDetector();
            using FaceDetector faceDetector = new FaceDetector();
            //FaceType需要用口罩模型
            using FaceRecognizer faceRecognizer = new FaceRecognizer(new FaceRecognizeConfig()
            {
                FaceType = FaceType.Mask
            });
            using FaceLandmarker faceMark = new FaceLandmarker();

            var info0 = faceDetector.Detect(bitmap0).First();
            var result0 = maskDetector.PlotMask(bitmap0, info0);
            Console.WriteLine($"是否戴口罩:{(result0.Status ? "是" : "否")},置信度:{result0.Score}");

            var info1 = faceDetector.Detect(bitmap_mask).First();
            var result1 = maskDetector.PlotMask(bitmap_mask, info1);
            Console.WriteLine($"是否戴口罩:{(result1.Status ? "是" : "否")},置信度:{result1.Score}");

            var result = faceRecognizer.Extract(bitmap_mask, faceMark.Mark(bitmap_mask, info1));
            Console.WriteLine($"是否识别到人脸:{(result != null && result.Sum() > 1 ? "是" : "否")}");
            Console.WriteLine();
        }

        static void FaceMarkDemo()
        {
            using var bitmap0 = SKBitmap.Decode(imagePath0);
            using var faceImage = bitmap0.ToFaceImage();
            using FaceDetector faceDetector = new FaceDetector();
            using FaceLandmarker faceMark = new FaceLandmarker();
            Stopwatch sw = new Stopwatch();

            var infos = faceDetector.Detect(faceImage);
            var markPoints = faceMark.Mark(faceImage, infos[0]);

            sw.Stop();
            Console.WriteLine($"识别到的关键点个数:{markPoints.Length},耗时:{sw.ElapsedMilliseconds}ms");
            foreach (var item in markPoints)
            {
                Console.WriteLine($"X:{item.X}\tY:{item.Y}");
            }
            Console.WriteLine();
        }

        static void FaceQualityDemo()
        {
            using var bitmap = SKBitmap.Decode(imagePath0);
            using FaceQuality faceQuality = new FaceQuality();
            using FaceDetector faceDetector = new FaceDetector();
            using FaceLandmarker faceMark = new FaceLandmarker();

            var info = faceDetector.Detect(bitmap).First();
            var markPoints = faceMark.Mark(bitmap, info);

            Stopwatch sw = Stopwatch.StartNew();

            var brightnessResult = faceQuality.Detect(bitmap, info, markPoints, QualityType.Brightness);
            Console.WriteLine($"{QualityType.Brightness}评估,结果:{brightnessResult},耗时:{sw.ElapsedMilliseconds}ms");
            sw.Restart();
            var resolutionResult = faceQuality.Detect(bitmap, info, markPoints, QualityType.Resolution);
            Console.WriteLine($"{QualityType.Resolution}评估,结果:{resolutionResult},耗时:{sw.ElapsedMilliseconds}ms");
            sw.Restart();
            var clarityResult = faceQuality.Detect(bitmap, info, markPoints, QualityType.Clarity);
            Console.WriteLine($"{QualityType.Clarity}评估,结果:{clarityResult},耗时:{sw.ElapsedMilliseconds}ms");
            sw.Restart();
            var clarityExResult = faceQuality.Detect(bitmap, info, markPoints, QualityType.ClarityEx);
            Console.WriteLine($"{QualityType.ClarityEx}评估,结果:{clarityExResult},耗时:{sw.ElapsedMilliseconds}ms");
            sw.Restart();
            var integrityExResult = faceQuality.Detect(bitmap, info, markPoints, QualityType.Integrity);
            Console.WriteLine($"{QualityType.Integrity}评估,结果:{integrityExResult},耗时:{sw.ElapsedMilliseconds}ms");
            sw.Restart();
            var structureeResult = faceQuality.Detect(bitmap, info, markPoints, QualityType.Structure);
            Console.WriteLine($"{QualityType.Structure}评估,结果:{structureeResult},耗时:{sw.ElapsedMilliseconds}ms");
            sw.Restart();
            var poseResult = faceQuality.Detect(bitmap, info, markPoints, QualityType.Pose);
            Console.WriteLine($"{QualityType.Pose}评估,结果:{poseResult},耗时:{sw.ElapsedMilliseconds}ms");
            sw.Restart();
            var poseExeResult = faceQuality.Detect(bitmap, info, markPoints, QualityType.PoseEx);
            Console.WriteLine($"{QualityType.PoseEx}评估,结果:{poseExeResult},耗时:{sw.ElapsedMilliseconds}ms");

            sw.Stop();
            Console.WriteLine();
        }

        static void AntiSpoofingDemo()
        {
            using var bitmap = SKBitmap.Decode(imagePath0);

            using FaceDetector faceDetector = new FaceDetector();
            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);
            Console.WriteLine($"活体检测,结果:{result.Status},清晰度:{result.Clarity},真实度:{result.Reality},耗时:{sw.ElapsedMilliseconds}ms");

            sw.Stop();
            Console.WriteLine();
        }

        static void FaceRecognizerDemo()
        {
            Stopwatch sw = Stopwatch.StartNew();

            using var faceImage0 = SKBitmap.Decode(imagePath0).ToFaceImage();
            using var faceImage1 = SKBitmap.Decode(imagePath1).ToFaceImage();
            //检测人脸信息
            using FaceDetector faceDetector = new FaceDetector();
            FaceInfo[] infos0 = faceDetector.Detect(faceImage0);
            FaceInfo[] infos1 = faceDetector.Detect(faceImage1);
            //标记人脸位置
            using FaceLandmarker faceMark = new FaceLandmarker();
            FaceMarkPoint[] points0 = faceMark.Mark(faceImage0, infos0[0]);
            FaceMarkPoint[] points1 = faceMark.Mark(faceImage1, infos1[0]);
            //提取特征值
            using FaceRecognizer faceRecognizer = new FaceRecognizer();
            float[] data0 = faceRecognizer.Extract(faceImage0, points0);
            float[] data1 = faceRecognizer.Extract(faceImage1, points1);
            //对比特征值
            bool isSelf = faceRecognizer.IsSelf(data0, data1);

            Console.WriteLine($"识别到的人脸是否为同一人:{isSelf},对比耗时:{sw.ElapsedMilliseconds}ms");
            Console.WriteLine();
            sw.Stop();
        }

        static void FaceTrackDemo()
        {
            using var faceImage = SKBitmap.Decode(imagePath0).ToFaceImage();
            using FaceLandmarker faceMark = new FaceLandmarker();
            using FaceTracker faceTrack = new FaceTracker(new FaceTrackerConfig(faceImage.Width, faceImage.Height));
            var result = faceTrack.Track(faceImage);
            if (result == null || !result.Any())
            {
                Console.WriteLine("未追踪到任何人脸!");
                return;
            }
            foreach (var item in result)
            {
                FaceInfo faceInfo = item.ToFaceInfo();
                //标记人脸
                var points = faceMark.Mark(faceImage, faceInfo);
            }
        }
    }
}


【视频演示】

https://www.bilibili.com/video/BV1eK411x7wo/
【示范源码下载】

https://download.csdn.net/download/FL1623863129/88713155
【测试环境】

vs2019

netframework4.7.2或者netframework4.8

ViewFaceCore

文章来源:https://blog.csdn.net/FL1623863129/article/details/135437180
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。