提交代码
This commit is contained in:
@@ -7,7 +7,7 @@ namespace HardwareWeb.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 靶样轮廓识别与采样点规划接口。
|
||||
/// 流程:采集基准画面 -> 采集靶样画面 -> 分析并返回处理后的图像。
|
||||
/// 流程:抓取相机当前画面 -> 分析并返回处理后的图像。
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/sample")]
|
||||
@@ -24,36 +24,21 @@ namespace HardwareWeb.Controllers
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <summary>连续抓取多帧并取中值作为基准背景画面。</summary>
|
||||
[HttpPost("baseline")]
|
||||
[ProducesResponseType(typeof(SampleBaselinePayload), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> CaptureBaseline(CancellationToken ct)
|
||||
/// <summary>
|
||||
/// 获取轮廓识别的等待超时时间,
|
||||
/// 取自系统参数 camera_Identification_outtime(秒)。
|
||||
/// </summary>
|
||||
[HttpGet("analyze-timeout")]
|
||||
[ProducesResponseType(typeof(AnalyzeTimeoutPayload), StatusCodes.Status200OK)]
|
||||
public IActionResult AnalyzeTimeout()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Ok(SampleBaselinePayload.From(
|
||||
await _service.CaptureBaselineAsync(ct)));
|
||||
}
|
||||
catch (HardwareException ex)
|
||||
{
|
||||
return HardwareError(ex);
|
||||
}
|
||||
}
|
||||
var timeoutSeconds = _service.GetIdentificationTimeoutSeconds();
|
||||
_logger.LogInformation(
|
||||
"前端轮廓识别等待超时:{TimeoutSeconds} 秒" +
|
||||
"(系统参数 camera_Identification_outtime)",
|
||||
timeoutSeconds);
|
||||
|
||||
/// <summary>关闭红外测距光源后抓取当前最新画面作为靶样画面。</summary>
|
||||
[HttpPost("target")]
|
||||
[ProducesResponseType(typeof(SampleTargetPayload), StatusCodes.Status200OK)]
|
||||
public async Task<IActionResult> CaptureTarget(CancellationToken ct)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Ok(SampleTargetPayload.From(
|
||||
await _service.CaptureTargetAsync(ct)));
|
||||
}
|
||||
catch (HardwareException ex)
|
||||
{
|
||||
return HardwareError(ex);
|
||||
}
|
||||
return Ok(new AnalyzeTimeoutPayload(timeoutSeconds));
|
||||
}
|
||||
|
||||
/// <summary>提取靶样轮廓、绘制采样点并返回处理后的 JPEG 图像。</summary>
|
||||
|
||||
@@ -27,4 +27,24 @@
|
||||
<Content Remove="..\HardwareControl.Core\Models\4.highvalue_expert_logits.onnx" />
|
||||
</ItemGroup>
|
||||
|
||||
<!--
|
||||
前端构建产物:pnpm build 生成的 dist 在发布时自动复制到 wwwroot。
|
||||
避免发布目录继续使用旧的前端包(旧包把识别等待时间写死为 30 秒)。
|
||||
未执行 pnpm build 时 dist 不存在,该配置不会产生任何文件。
|
||||
-->
|
||||
<ItemGroup>
|
||||
<Content Include="..\Hardware-Vue\dist\**\*"
|
||||
Link="wwwroot\%(RecursiveDir)%(Filename)%(Extension)"
|
||||
CopyToPublishDirectory="PreserveNewest" />
|
||||
</ItemGroup>
|
||||
|
||||
<!--
|
||||
ASP.NET Core 的静态 Web 资源清单会把项目 wwwroot 作为内容根目录,
|
||||
目录不存在时 Development 环境启动会在 WebApplication.CreateBuilder
|
||||
抛 DirectoryNotFoundException。这里在构建前确保目录存在。
|
||||
-->
|
||||
<Target Name="EnsureWwwRootDirectory" BeforeTargets="PrepareForBuild">
|
||||
<MakeDir Directories="$(MSBuildProjectDirectory)\wwwroot" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -2,29 +2,12 @@ using HardwareControl.Core.SampleAnalysis;
|
||||
|
||||
namespace HardwareWeb.Models
|
||||
{
|
||||
/// <summary>基准画面采集结果。</summary>
|
||||
public sealed record SampleBaselinePayload(
|
||||
int Width,
|
||||
int Height,
|
||||
DateTimeOffset CapturedAt)
|
||||
{
|
||||
public static SampleBaselinePayload From(SampleBaselineInfo info) =>
|
||||
new(info.Width, info.Height, info.CapturedAt);
|
||||
}
|
||||
|
||||
/// <summary>靶样画面采集结果。</summary>
|
||||
public sealed record SampleTargetPayload(
|
||||
int Width,
|
||||
int Height,
|
||||
DateTimeOffset CapturedAt)
|
||||
{
|
||||
public static SampleTargetPayload From(SampleTargetInfo info) =>
|
||||
new(info.Width, info.Height, info.CapturedAt);
|
||||
}
|
||||
|
||||
/// <summary>采样点坐标(图像像素)。</summary>
|
||||
public sealed record SamplePointPayload(int X, int Y);
|
||||
|
||||
/// <summary>轮廓识别等待超时(单位:秒)。</summary>
|
||||
public sealed record AnalyzeTimeoutPayload(int TimeoutSeconds);
|
||||
|
||||
/// <summary>靶样轮廓与采样点分析结果。</summary>
|
||||
public sealed record SampleAnalysisPayload(
|
||||
string ImageBase64,
|
||||
|
||||
+14
-2
@@ -56,8 +56,8 @@ builder.Services.AddSingleton<AdminAccessService>();
|
||||
// 8. 靶样轮廓识别与采样点规划(ONNX 模型分割)
|
||||
builder.Services.Configure<OnnxSegmentationOptions>(
|
||||
builder.Configuration.GetSection(OnnxSegmentationOptions.SectionName));
|
||||
builder.Services.AddSingleton<BackgroundDiffSegmenter>();
|
||||
builder.Services.AddSingleton<TargetOutlineAnalyzer>();
|
||||
builder.Services.AddHostedService<SampleAnalysisWarmupService>();
|
||||
builder.Services.AddSingleton<ISampleAnalysisService, SampleAnalysisService>();
|
||||
|
||||
// 9. 位移台:串口优先取系统参数 translation_com,未配置时回退到 appsettings 的 AxisStage:ComPort
|
||||
@@ -105,7 +105,19 @@ app.UseAuthorization();
|
||||
|
||||
//这两行是用来托管前端的
|
||||
app.UseDefaultFiles();
|
||||
app.UseStaticFiles();
|
||||
app.UseStaticFiles(new StaticFileOptions
|
||||
{
|
||||
OnPrepareResponse = context =>
|
||||
{
|
||||
// 入口页禁止缓存,避免前端重新构建后浏览器仍加载旧的 JS 资源。
|
||||
if (string.Equals(
|
||||
context.File.Name, "index.html", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
context.Context.Response.Headers.CacheControl =
|
||||
"no-cache, no-store, must-revalidate";
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
app.MapControllers();
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
using HardwareControl.Core.SampleAnalysis;
|
||||
|
||||
namespace HardwareWeb.Services
|
||||
{
|
||||
/// <summary>
|
||||
/// 应用启动后在后台预热靶样轮廓分析模型。
|
||||
/// 大模型首次加载往往需要数十秒,放到后台执行可以避免用户点击检测时才等待。
|
||||
/// </summary>
|
||||
public sealed class SampleAnalysisWarmupService : IHostedService
|
||||
{
|
||||
private readonly TargetOutlineAnalyzer _analyzer;
|
||||
private readonly ILogger<SampleAnalysisWarmupService> _logger;
|
||||
|
||||
public SampleAnalysisWarmupService(
|
||||
TargetOutlineAnalyzer analyzer,
|
||||
ILogger<SampleAnalysisWarmupService> logger)
|
||||
{
|
||||
_analyzer = analyzer;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
_ = Task.Run(
|
||||
() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
_analyzer.PreloadPrimaryModel();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogWarning(
|
||||
ex, "靶样分析模型预热失败,将在检测时重新加载");
|
||||
}
|
||||
},
|
||||
CancellationToken.None);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public Task StopAsync(CancellationToken cancellationToken) =>
|
||||
Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,7 @@
|
||||
},
|
||||
"SystemSetting": {
|
||||
"DatabasePath": null,
|
||||
"AdminPassword": "flzx3QC!1"
|
||||
"AdminPassword": "123456"
|
||||
},
|
||||
"Scanning": {
|
||||
"DatabasePath": null,
|
||||
@@ -60,6 +60,8 @@
|
||||
"ModelDirectory": "Models",
|
||||
"InputWidth": 640,
|
||||
"InputHeight": 640,
|
||||
"ExecutionProvider": "Auto",
|
||||
"DmlDeviceId": 0,
|
||||
"ConfidenceThreshold": 0.25,
|
||||
"FallbackConfidenceThreshold": 0.6,
|
||||
"MaskThreshold": 0.5,
|
||||
|
||||
Reference in New Issue
Block a user