feat 检测
This commit is contained in:
@@ -47,6 +47,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Message", "Message", "{65E7
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dlhis.Message", "Src\Dlhis.Message\Dlhis.Message.csproj", "{053BF7B2-B1A0-435F-9C77-2EF5622CC5C5}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dlhis.Message", "Src\Dlhis.Message\Dlhis.Message.csproj", "{053BF7B2-B1A0-435F-9C77-2EF5622CC5C5}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dlhis.InfoCheck", "Src\Dlhis.InfoCheck\Dlhis.InfoCheck.csproj", "{4D656761-8CE7-4316-A3DF-8C1722D69CCE}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -117,6 +119,10 @@ Global
|
|||||||
{053BF7B2-B1A0-435F-9C77-2EF5622CC5C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{053BF7B2-B1A0-435F-9C77-2EF5622CC5C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{053BF7B2-B1A0-435F-9C77-2EF5622CC5C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{053BF7B2-B1A0-435F-9C77-2EF5622CC5C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{053BF7B2-B1A0-435F-9C77-2EF5622CC5C5}.Release|Any CPU.Build.0 = Release|Any CPU
|
{053BF7B2-B1A0-435F-9C77-2EF5622CC5C5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{4D656761-8CE7-4316-A3DF-8C1722D69CCE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{4D656761-8CE7-4316-A3DF-8C1722D69CCE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{4D656761-8CE7-4316-A3DF-8C1722D69CCE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{4D656761-8CE7-4316-A3DF-8C1722D69CCE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
@@ -136,6 +142,7 @@ Global
|
|||||||
{D4043506-7247-4DDC-9751-927403515669} = {3D8A98C1-83C9-4375-AEAB-4F72AFAF365B}
|
{D4043506-7247-4DDC-9751-927403515669} = {3D8A98C1-83C9-4375-AEAB-4F72AFAF365B}
|
||||||
{69E8A91A-5D05-4327-BC24-038523C7628C} = {489252FB-A44B-46EE-B065-21CDCB724441}
|
{69E8A91A-5D05-4327-BC24-038523C7628C} = {489252FB-A44B-46EE-B065-21CDCB724441}
|
||||||
{053BF7B2-B1A0-435F-9C77-2EF5622CC5C5} = {65E76F97-E78A-4C95-B788-4091236B1A79}
|
{053BF7B2-B1A0-435F-9C77-2EF5622CC5C5} = {65E76F97-E78A-4C95-B788-4091236B1A79}
|
||||||
|
{4D656761-8CE7-4316-A3DF-8C1722D69CCE} = {4EBCE46B-CE3A-4A47-9432-82A1854CA58A}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
SolutionGuid = {7439494A-E2FD-4FEA-8ABF-74AE57A4A5A0}
|
SolutionGuid = {7439494A-E2FD-4FEA-8ABF-74AE57A4A5A0}
|
||||||
|
|||||||
104
Src/Dlhis.InfoCheck/Controllers/FaceController.cs
Normal file
104
Src/Dlhis.InfoCheck/Controllers/FaceController.cs
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
namespace Dlhis.InfoCheck.Controllers;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
[Authorize]
|
||||||
|
[ApiController]
|
||||||
|
[Route("[controller]")]
|
||||||
|
public class FaceController : ControllerBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("detection")]
|
||||||
|
public object FacialDetection(FaceDetectRequest request)
|
||||||
|
{
|
||||||
|
var base64Bytes = Convert.FromBase64String(request.Base64);
|
||||||
|
using var stream = new MemoryStream(base64Bytes);
|
||||||
|
using var bitmap = SKBitmap.Decode(stream);
|
||||||
|
using var faceDetector = new FaceDetector();
|
||||||
|
|
||||||
|
using var faceMark = new FaceLandmarker(new FaceLandmarkConfig
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
|
||||||
|
return new
|
||||||
|
{
|
||||||
|
Brightness = brightnessResult,
|
||||||
|
Resolution = resolutionResult,
|
||||||
|
Clarity = clarityExResult,
|
||||||
|
Integrity = integrityExResult,
|
||||||
|
Structure = structureeResult,
|
||||||
|
Pose = poseExeResult
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <20><><EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD>
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="request"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("recognize")]
|
||||||
|
public FaceRecognizeResponse FacialRecognize(FaceRecognizeRequest request)
|
||||||
|
{
|
||||||
|
var firstBase64Bytes = Convert.FromBase64String(request.FirstBase64);
|
||||||
|
using var firstStream = new MemoryStream(firstBase64Bytes);
|
||||||
|
using var firstBitmap = SKBitmap.Decode(firstStream);
|
||||||
|
|
||||||
|
var secondBase64Bytes = Convert.FromBase64String(request.SecondBase64);
|
||||||
|
using var secondStream = new MemoryStream(secondBase64Bytes);
|
||||||
|
using var secondBitmap = SKBitmap.Decode(secondStream);
|
||||||
|
|
||||||
|
using var recognizer = new FaceRecognizer(new FaceRecognizeConfig
|
||||||
|
{
|
||||||
|
//<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 faceDetector = new FaceDetector();
|
||||||
|
using var faceMark = new FaceLandmarker();
|
||||||
|
|
||||||
|
//todo
|
||||||
|
var lft = recognizer.Extract(firstBitmap, faceMark.Mark(firstBitmap, faceDetector.Detect(firstBitmap).First()));
|
||||||
|
var rft = recognizer.Extract(secondBitmap, faceMark.Mark(secondBitmap, faceDetector.Detect(secondBitmap).First()));
|
||||||
|
|
||||||
|
var similarity = recognizer.Compare(lft, rft);
|
||||||
|
var isSelf = recognizer.IsSelf(similarity);
|
||||||
|
|
||||||
|
return new FaceRecognizeResponse
|
||||||
|
{
|
||||||
|
Similarity = similarity,
|
||||||
|
IsSelf = isSelf
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
23
Src/Dlhis.InfoCheck/Dlhis.InfoCheck.csproj
Normal file
23
Src/Dlhis.InfoCheck/Dlhis.InfoCheck.csproj
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<Nullable>disable</Nullable>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||||
|
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||||
|
<DockerfileContext>..\..</DockerfileContext>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Kurisu.AspNetCore" Version="0.8.8" />
|
||||||
|
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
|
||||||
|
<PackageReference Include="SkiaSharp" Version="2.88.8" />
|
||||||
|
<PackageReference Include="ViewFaceCore" Version="0.3.8" />
|
||||||
|
<PackageReference Include="ViewFaceCore.all_models" Version="6.0.7" />
|
||||||
|
<PackageReference Include="ViewFaceCore.Extension.SkiaSharp" Version="0.3.7" />
|
||||||
|
<PackageReference Include="ViewFaceCore.runtime.linux.arm64" Version="6.0.7" />
|
||||||
|
<PackageReference Include="ViewFaceCore.runtime.win.x64" Version="6.0.7" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
23
Src/Dlhis.InfoCheck/Dockerfile
Normal file
23
Src/Dlhis.InfoCheck/Dockerfile
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
|
||||||
|
WORKDIR /app
|
||||||
|
EXPOSE 80
|
||||||
|
|
||||||
|
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
|
||||||
|
ARG BUILD_CONFIGURATION=Release
|
||||||
|
WORKDIR /src
|
||||||
|
COPY ["Src/Dlhis.InfoCheck/Dlhis.InfoCheck.csproj", "Src/Dlhis.InfoCheck/"]
|
||||||
|
RUN dotnet restore "./Src/Dlhis.InfoCheck/./Dlhis.InfoCheck.csproj"
|
||||||
|
COPY . .
|
||||||
|
WORKDIR "/src/Src/Dlhis.InfoCheck"
|
||||||
|
RUN dotnet build "./Dlhis.InfoCheck.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||||
|
|
||||||
|
FROM build AS publish
|
||||||
|
ARG BUILD_CONFIGURATION=Release
|
||||||
|
RUN dotnet publish "./Dlhis.InfoCheck.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||||
|
|
||||||
|
FROM base AS final
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=publish /app/publish .
|
||||||
|
ENTRYPOINT ["dotnet", "Dlhis.InfoCheck.dll"]
|
||||||
19
Src/Dlhis.InfoCheck/Program.cs
Normal file
19
Src/Dlhis.InfoCheck/Program.cs
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
using Kurisu.AspNetCore.Startup;
|
||||||
|
using Kurisu.AspNetCore.Utils.Extensions;
|
||||||
|
using Microsoft.IdentityModel.Logging;
|
||||||
|
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
KurisuHost.Run<Startup>(args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class Startup : DefaultStartup
|
||||||
|
{
|
||||||
|
public Startup(IConfiguration configuration) : base(configuration)
|
||||||
|
{
|
||||||
|
IdentityModelEventSource.ShowPII = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
38
Src/Dlhis.InfoCheck/Properties/launchSettings.json
Normal file
38
Src/Dlhis.InfoCheck/Properties/launchSettings.json
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"profiles": {
|
||||||
|
"Dlhis.InfoCheck": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"launchUrl": "weatherforecast",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
},
|
||||||
|
"dotnetRunMessages": true,
|
||||||
|
"applicationUrl": "http://localhost:5048"
|
||||||
|
},
|
||||||
|
"IIS Express": {
|
||||||
|
"commandName": "IISExpress",
|
||||||
|
"launchBrowser": true,
|
||||||
|
"launchUrl": "weatherforecast",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Docker": {
|
||||||
|
"commandName": "Docker",
|
||||||
|
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/weatherforecast",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_URLS": "http://+:80"
|
||||||
|
},
|
||||||
|
"publishAllPorts": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||||
|
"iisSettings": {
|
||||||
|
"windowsAuthentication": false,
|
||||||
|
"anonymousAuthentication": true,
|
||||||
|
"iisExpress": {
|
||||||
|
"applicationUrl": "http://localhost:53902",
|
||||||
|
"sslPort": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
6
Src/Dlhis.InfoCheck/Request/FaceDetectRequest.cs
Normal file
6
Src/Dlhis.InfoCheck/Request/FaceDetectRequest.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace Dlhis.InfoCheck.Request;
|
||||||
|
|
||||||
|
public class FaceDetectRequest
|
||||||
|
{
|
||||||
|
public string Base64 { get; set; }
|
||||||
|
}
|
||||||
8
Src/Dlhis.InfoCheck/Request/FaceRecognizeRequest.cs
Normal file
8
Src/Dlhis.InfoCheck/Request/FaceRecognizeRequest.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
namespace Dlhis.InfoCheck.Request;
|
||||||
|
|
||||||
|
public class FaceRecognizeRequest
|
||||||
|
{
|
||||||
|
public string FirstBase64 { get; set; }
|
||||||
|
|
||||||
|
public string SecondBase64 { get; set; }
|
||||||
|
}
|
||||||
14
Src/Dlhis.InfoCheck/Response/FaceRecognizeResponse.cs
Normal file
14
Src/Dlhis.InfoCheck/Response/FaceRecognizeResponse.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
namespace Dlhis.InfoCheck.Response;
|
||||||
|
|
||||||
|
public class FaceRecognizeResponse
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 相似度
|
||||||
|
/// </summary>
|
||||||
|
public float Similarity { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 同一人
|
||||||
|
/// </summary>
|
||||||
|
public bool IsSelf { get; set; }
|
||||||
|
}
|
||||||
31
Src/Dlhis.InfoCheck/appsettings.Development.json
Normal file
31
Src/Dlhis.InfoCheck/appsettings.Development.json
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"SwaggerOptions": {
|
||||||
|
"Enable": true,
|
||||||
|
"Authority": "https://yikatong.isawesome.cn/oauth2",
|
||||||
|
"ClientId": "4fb184324eac4180",
|
||||||
|
"ClientSecret": "8ac8f235152f1524",
|
||||||
|
"Scopes": {
|
||||||
|
"openid": "openid",
|
||||||
|
"profile": "profile",
|
||||||
|
"yikatong": "yikatong"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"IdentityServerOptions": {
|
||||||
|
"Authority": "https://yikatong.isawesome.cn/oauth2",
|
||||||
|
"RequireHttpsMetadata": true,
|
||||||
|
"Issuer": "identity.isawesome.cn",
|
||||||
|
"Audience": "",
|
||||||
|
"Pat": {
|
||||||
|
"Enable": false,
|
||||||
|
"Scheme": "token",
|
||||||
|
"ClientId": "reference",
|
||||||
|
"ClientSecret": "123456"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
65
Src/Dlhis.InfoCheck/appsettings.json
Normal file
65
Src/Dlhis.InfoCheck/appsettings.json
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
{
|
||||||
|
"Logging": {
|
||||||
|
"LogLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Microsoft.AspNetCore": "Warning"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"AllowedHosts": "*",
|
||||||
|
"SwaggerOptions": {
|
||||||
|
"Enable": true,
|
||||||
|
"Authority": "http://identity.oauth.svc.cluster.local",
|
||||||
|
"ClientId": "4fb184324eac4180",
|
||||||
|
"ClientSecret": "8ac8f235152f1524",
|
||||||
|
"Scopes": {
|
||||||
|
"openid": "openid",
|
||||||
|
"profile": "profile",
|
||||||
|
"yikatong": "yikatong"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"IdentityServerOptions": {
|
||||||
|
"Authority": "http://identity.oauth.svc.cluster.local",
|
||||||
|
"RequireHttpsMetadata": false,
|
||||||
|
"Issuer": "identity.isawesome.cn",
|
||||||
|
"Audience": "",
|
||||||
|
"Pat": {
|
||||||
|
"Enable": false,
|
||||||
|
"Scheme": "token",
|
||||||
|
"ClientId": "reference",
|
||||||
|
"ClientSecret": "123456"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"Serilog": {
|
||||||
|
"MinimumLevel": {
|
||||||
|
"Default": "Information",
|
||||||
|
"Override": {
|
||||||
|
"System": "Warning",
|
||||||
|
"Microsoft": "Warning",
|
||||||
|
"Microsoft.Hosting.Lifetime": "Information"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"WriteTo": [
|
||||||
|
{
|
||||||
|
"Name": "Async",
|
||||||
|
"Args": {
|
||||||
|
"configure": [
|
||||||
|
{
|
||||||
|
"Name": "Console",
|
||||||
|
"Args": {
|
||||||
|
"outputTemplate": "[{Timestamp:HH:mm:ss} {Level:u3}] [{SourceContext}] {Message:lj}{NewLine}{Exception}"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"Name": "MySQL",
|
||||||
|
"Args": {
|
||||||
|
"connectionString": "server=192.168.199.124;port=3306;userid=root;password=dlhis123;database=log;charset=utf8mb4;",
|
||||||
|
"tableName": "Logs",
|
||||||
|
"autoCreateSqlTable": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user