-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
98 lines (80 loc) · 2.55 KB
/
Program.cs
File metadata and controls
98 lines (80 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using FaceSimilarityService.Services;
using SeetaFace6Sharp;
using System.Runtime.Intrinsics.X86;
var builder = WebApplication.CreateSlimBuilder(args);
builder.Services.AddControllers();
// 判断是否为Nvidia显卡 支持CUDA 使用系统环境变量
if (Environment.GetEnvironmentVariable("FACE_CUDA") == "1")
{
//打印内部日志
GlobalConfig.DefaultDeviceType = DeviceType.GPU;
}
else
{
// 使用System.Runtime进行判断cpu是否支持axv2指令集
if (Avx2.IsSupported)
{
GlobalConfig.DefaultDeviceType = DeviceType.CPU;
}
else
{
/// 打印
Console.WriteLine("CPU不支持AVX2指令集,使用SSE2指令集");
GlobalConfig.X86Instruction = X86Instruction.SSE2;
}
}
builder.Services.AddSingleton<FaceDetector>();
builder.Services.AddSingleton(new FaceLandmarker(new FaceLandmarkConfig(MarkType.Light))); // 人脸关键点检测器
builder.Services.AddSingleton<FaceRecognizer>();
builder.Services.AddSingleton(new FeatureStorageService("./storage.json"));
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
// builder.WebHost.ConfigureKestrel(options =>
// {
// options.ListenAnyIP(5000); // HTTP 端口
// options.ListenAnyIP(5001, listenOptions =>
// {
// listenOptions.UseHttps(); // HTTPS 端口
// });
// });
var app = builder.Build();
// 添加跨域中间件
app.UseCors(builder =>
{
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
// Configure the HTTP request pipeline.
// if (app.Environment.IsDevelopment())
// {
app.UseSwagger();
// 重定向到swagger
app.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/swagger/v1/swagger.json", "FaceSimilarityService");
options.RoutePrefix = string.Empty;
});
// }
// app.UseHttpsRedirection();
app.UseRouting(); // 添加路由中间件
app.UseAuthorization();
app.MapControllers(); // 映射控制器路由
// var summaries = new[]
// {
// "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
// };
// app.MapGet("/weatherforecast", () =>
// {
// var forecast = Enumerable.Range(1, 5).Select(index =>
// new WeatherForecast
// (
// DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
// Random.Shared.Next(-20, 55),
// summaries[Random.Shared.Next(summaries.Length)]
// ))
// .ToArray();
// return forecast;
// })
// .WithName("GetWeatherForecast")
app.Run("http://0.0.0.0:5000"); // Set the application to listen on port 5000