feat 人脸检测
This commit is contained in:
@@ -2,30 +2,25 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using SkiaSharp;
|
||||
using ViewFaceCore.Core;
|
||||
using ViewFaceCore.Model;
|
||||
using ViewFaceCore.Exceptions;
|
||||
using ViewFaceCore;
|
||||
using ViewFaceCore.Configs;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Dlhis.InfoCheck.Request;
|
||||
using Dlhis.InfoCheck.Response;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
|
||||
namespace Dlhis.InfoCheck.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// </summary>
|
||||
[Authorize]
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
public class FaceController : ControllerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
/// 人脸质量检测
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost("detection")]
|
||||
public object FacialDetection(FaceDetectRequest request)
|
||||
public IEnumerable<string> FacialDetection(FaceDetectRequest request)
|
||||
{
|
||||
var base64Bytes = Convert.FromBase64String(request.Base64);
|
||||
using var stream = new MemoryStream(base64Bytes);
|
||||
@@ -37,34 +32,30 @@ public class FaceController : ControllerBase
|
||||
MarkType = MarkType.Light
|
||||
});
|
||||
|
||||
//todo <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
var info = faceDetector.Detect(bitmap).First();
|
||||
var markPoints = faceMark.Mark(bitmap, info);
|
||||
|
||||
using var faceQuality = new FaceQuality();
|
||||
var brightnessResult = faceQuality.Detect(bitmap, info, markPoints, QualityType.Brightness);
|
||||
var resolutionResult = faceQuality.Detect(bitmap, info, markPoints, QualityType.Resolution);
|
||||
//var clarityResult = faceQuality.Detect(bitmap, info, markPoints, QualityType.Clarity);
|
||||
var clarityExResult = faceQuality.Detect(bitmap, info, markPoints, QualityType.ClarityEx);
|
||||
var integrityExResult = faceQuality.Detect(bitmap, info, markPoints, QualityType.Integrity);
|
||||
var structureeResult = faceQuality.Detect(bitmap, info, markPoints, QualityType.Structure);
|
||||
//var poseResult = faceQuality.Detect(bitmap, info, markPoints, QualityType.Pose);
|
||||
var poseExeResult = faceQuality.Detect(bitmap, info, markPoints, QualityType.PoseEx);
|
||||
var qualityResult = new List<QualityResultEx>(6);
|
||||
qualityResult.Add(faceQuality.DetectEx(bitmap, info, markPoints, QualityType.Brightness));
|
||||
|
||||
return new
|
||||
qualityResult.Add(faceQuality.DetectEx(bitmap, info, markPoints, QualityType.Resolution));
|
||||
//var clarityResult = faceQuality.Detect(bitmap, info, markPoints, QualityType.Clarity);
|
||||
qualityResult.Add(faceQuality.DetectEx(bitmap, info, markPoints, QualityType.ClarityEx));
|
||||
qualityResult.Add(faceQuality.DetectEx(bitmap, info, markPoints, QualityType.Integrity));
|
||||
qualityResult.Add(faceQuality.DetectEx(bitmap, info, markPoints, QualityType.Structure));
|
||||
//var poseResult = faceQuality.Detect(bitmap, info, markPoints, QualityType.Pose);
|
||||
qualityResult.Add(faceQuality.DetectEx(bitmap, info, markPoints, QualityType.PoseEx));
|
||||
|
||||
return request.CheckList.Where(x =>
|
||||
{
|
||||
Brightness = brightnessResult,
|
||||
Resolution = resolutionResult,
|
||||
Clarity = clarityExResult,
|
||||
Integrity = integrityExResult,
|
||||
Structure = structureeResult,
|
||||
Pose = poseExeResult
|
||||
};
|
||||
var r = qualityResult.First(item => item.Type == x.Type);
|
||||
return r.Level < x.Level;
|
||||
}).Select(x => x.Type.GetDescription().Replace("评估", string.Empty) + "不符合");
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD>
|
||||
/// 图片识别对比
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
@@ -79,9 +70,7 @@ public class FaceController : ControllerBase
|
||||
using var secondStream = new MemoryStream(secondBase64Bytes);
|
||||
using var secondBitmap = SKBitmap.Decode(secondStream);
|
||||
|
||||
//<2F><>Ӧ<EFBFBD><D3A6>ֵ FaceType.Normal<61><6C>0.62<EFBFBD><EFBFBD>FaceType.Mask<73><6B>0.4<EFBFBD><EFBFBD>FaceType.Light<68><74>0.55
|
||||
//FaceType = FaceType.Normal,
|
||||
using var recognizer = new FaceRecognizer();
|
||||
using var recognizer = new FaceRecognizer(new FaceRecognizeConfig());
|
||||
|
||||
using var faceDetector = new FaceDetector();
|
||||
using var faceMark = new FaceLandmarker();
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Kurisu.AspNetCore" Version="0.9.11" />
|
||||
<PackageReference Include="Kurisu.AspNetCore" Version="0.9.25" />
|
||||
<PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.0" />
|
||||
<PackageReference Include="ViewFaceCore" Version="0.3.8" />
|
||||
<PackageReference Include="ViewFaceCore.all_models" Version="6.0.7" />
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
namespace Dlhis.InfoCheck.Request;
|
||||
using ViewFaceCore.Model;
|
||||
|
||||
namespace Dlhis.InfoCheck.Request;
|
||||
|
||||
public class FaceDetectRequest
|
||||
{
|
||||
public string Base64 { get; set; }
|
||||
public List<FaceDetectCheckRequest> CheckList { get; set; }
|
||||
}
|
||||
|
||||
public class FaceDetectCheckRequest
|
||||
{
|
||||
public QualityType Type { get; set; }
|
||||
public QualityLevel Level { get; set; }
|
||||
}
|
||||
@@ -2,7 +2,13 @@
|
||||
|
||||
public class FaceRecognizeRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 第一张图片
|
||||
/// </summary>
|
||||
public string FirstBase64 { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 第二张图片
|
||||
/// </summary>
|
||||
public string SecondBase64 { get; set; }
|
||||
}
|
||||
|
||||
36
Src/Dlhis.InfoCheck/Response/FacialDetectionResponse.cs
Normal file
36
Src/Dlhis.InfoCheck/Response/FacialDetectionResponse.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using ViewFaceCore.Model;
|
||||
|
||||
namespace Dlhis.InfoCheck.Response;
|
||||
|
||||
public class FacialDetectionResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// 亮度
|
||||
/// </summary>
|
||||
public QualityResult Brightness { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 分辨率
|
||||
/// </summary>
|
||||
public QualityResult Resolution { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 清晰度
|
||||
/// </summary>
|
||||
public QualityResult Clarity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 完整度
|
||||
/// </summary>
|
||||
public QualityResult Integrity { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 遮挡
|
||||
/// </summary>
|
||||
public QualityResult Structure { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 姿态
|
||||
/// </summary>
|
||||
public QualityResult Pose { get; set; }
|
||||
}
|
||||
27
Src/Dlhis.InfoCheck/faceQualityExtensions.cs
Normal file
27
Src/Dlhis.InfoCheck/faceQualityExtensions.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using ViewFaceCore;
|
||||
using ViewFaceCore.Core;
|
||||
using ViewFaceCore.Model;
|
||||
|
||||
namespace Dlhis.InfoCheck;
|
||||
|
||||
public class QualityResultEx : QualityResult
|
||||
{
|
||||
public QualityType Type { get; set; }
|
||||
}
|
||||
|
||||
public static class FaceQualityExtensions
|
||||
{
|
||||
public static QualityResultEx DetectEx<T>(this FaceQuality faceQuality, T image,
|
||||
FaceInfo info,
|
||||
FaceMarkPoint[] points,
|
||||
QualityType type) where T : class
|
||||
{
|
||||
var result = faceQuality.Detect(image, info, points, type);
|
||||
return new QualityResultEx
|
||||
{
|
||||
Level = result.Level,
|
||||
Score = result.Score,
|
||||
Type = type
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user