From 29e90bbc7b660c95337e2063f73af4343f88d352 Mon Sep 17 00:00:00 2001 From: ldh <17393183636@163.com> Date: Tue, 17 Nov 2026 16:28:24 +0800 Subject: [PATCH] 1111 --- Hardware-Vue/src/api/sample.ts | 104 ++ .../src/components/AdminFunctionPanel.vue | 257 +++ Hardware-Vue/src/components/CameraPreview.vue | 37 +- Hardware-Vue/src/router/index.ts | 6 + Hardware-Vue/src/views/HomeView.vue | 19 + Hardware-Vue/src/views/RulerSettingView.vue | 728 +++++++++ Hardware-Vue/src/views/SampleSetupView.vue | 232 ++- Hardware-Vue/src/views/ScanPlanView.vue | 325 +++- Hardware-Vue/src/views/SystemConfigView.vue | 32 +- .../HardwareControl.Core.csproj | 3 + .../HardwareService/ISampleAnalysisService.cs | 19 + .../HardwareService/IUsbCameraService.cs | 3 + .../SampleAnalysisService.cs | 141 ++ .../HardwareServiceImpl/UsbCameraService.cs | 87 +- .../SampleAnalysis/BackgroundDiffSegmenter.cs | 283 ++++ .../SampleAnalysis/OnnxSegmentationOptions.cs | 53 + .../SampleAnalysis/SampleAnalysisModels.cs | 26 + .../SampleAnalysis/TargetOutlineAnalyzer.cs | 1375 +++++++++++++++++ .../UsbCamera/CameraFrameSnapshot.cs | 13 + .../UsbCamera/UsbCameraOptions.cs | 4 + .../Controllers/SampleAnalysisController.cs | 110 ++ HardwareWeb/HardwareWeb.csproj | 13 + HardwareWeb/Models/SampleAnalysisPayload.cs | 48 + HardwareWeb/Program.cs | 8 + HardwareWeb/appsettings.json | 11 + 25 files changed, 3891 insertions(+), 46 deletions(-) create mode 100644 Hardware-Vue/src/api/sample.ts create mode 100644 Hardware-Vue/src/components/AdminFunctionPanel.vue create mode 100644 Hardware-Vue/src/views/RulerSettingView.vue create mode 100644 HardwareControl.Core/HardwareService/ISampleAnalysisService.cs create mode 100644 HardwareControl.Core/HardwareServiceImpl/SampleAnalysisService.cs create mode 100644 HardwareControl.Core/SampleAnalysis/BackgroundDiffSegmenter.cs create mode 100644 HardwareControl.Core/SampleAnalysis/OnnxSegmentationOptions.cs create mode 100644 HardwareControl.Core/SampleAnalysis/SampleAnalysisModels.cs create mode 100644 HardwareControl.Core/SampleAnalysis/TargetOutlineAnalyzer.cs create mode 100644 HardwareControl.Core/UsbCamera/CameraFrameSnapshot.cs create mode 100644 HardwareWeb/Controllers/SampleAnalysisController.cs create mode 100644 HardwareWeb/Models/SampleAnalysisPayload.cs diff --git a/Hardware-Vue/src/api/sample.ts b/Hardware-Vue/src/api/sample.ts new file mode 100644 index 0000000..4c9cc49 --- /dev/null +++ b/Hardware-Vue/src/api/sample.ts @@ -0,0 +1,104 @@ +/** + * 靶样轮廓识别与采样点规划接口封装。 + * 后端实现见 HardwareWeb/Controllers/SampleAnalysisController.cs: + * POST /api/sample/baseline -> { width, height, capturedAt } + * POST /api/sample/target -> { width, height, capturedAt } + * POST /api/sample/analyze -> { imageBase64, mimeType, width, height, samplingPointCount, samplingPoints } + */ + +export interface SampleFrameResult { + width: number + height: number + capturedAt: string +} + +export interface SamplePoint { + x: number + y: number +} + +export interface SampleAnalysisResult { + imageBase64: string + mimeType: string + width: number + height: number + samplingPointCount: number + samplingPoints: SamplePoint[] +} + +const API_BASE = (import.meta.env.VITE_API_BASE ?? '').replace(/\/$/, '') +const DEFAULT_TIMEOUT = 15000 +const ANALYZE_TIMEOUT = 30000 + +export class SampleApiError extends Error { + readonly status: number + + constructor(message: string, status = 0) { + super(message) + this.name = 'SampleApiError' + this.status = status + } +} + +async function request( + path: string, + init?: RequestInit, + timeout = DEFAULT_TIMEOUT, +): Promise { + const controller = new AbortController() + const timer = window.setTimeout(() => controller.abort(), timeout) + + try { + const response = await fetch(`${API_BASE}${path}`, { + ...init, + cache: 'no-store', + signal: controller.signal, + headers: { + Accept: 'application/json', + ...(init?.headers ?? {}), + }, + }) + + if (!response.ok) { + let detail = `HTTP ${response.status}` + try { + const body = (await response.json()) as { message?: string; error?: string } + detail = body.message ?? body.error ?? detail + } catch { + // 响应不是 JSON 时保留状态码信息 + } + throw new SampleApiError(detail, response.status) + } + + return (await response.json()) as T + } catch (error) { + if (error instanceof SampleApiError) throw error + if (error instanceof DOMException && error.name === 'AbortError') { + throw new SampleApiError('图像分析服务响应超时') + } + throw new SampleApiError( + error instanceof Error ? error.message : '无法连接图像分析服务', + ) + } finally { + window.clearTimeout(timer) + } +} + +/** 相机画面稳定后采集基准画面。 */ +export function captureSampleBaseline(): Promise { + return request('/api/sample/baseline', { method: 'POST' }) +} + +/** 放置靶样并点击开始检测时采集第二张画面。 */ +export function captureSampleTarget(): Promise { + return request('/api/sample/target', { method: 'POST' }) +} + +/** 提取靶样轮廓、绘制采样点并返回处理后的图像。 */ +export function analyzeSample(): Promise { + return request( + '/api/sample/analyze', + { method: 'POST' }, + ANALYZE_TIMEOUT, + ) +} diff --git a/Hardware-Vue/src/components/AdminFunctionPanel.vue b/Hardware-Vue/src/components/AdminFunctionPanel.vue new file mode 100644 index 0000000..64b22ad --- /dev/null +++ b/Hardware-Vue/src/components/AdminFunctionPanel.vue @@ -0,0 +1,257 @@ + + + + + diff --git a/Hardware-Vue/src/components/CameraPreview.vue b/Hardware-Vue/src/components/CameraPreview.vue index 398ec71..54c8ada 100644 --- a/Hardware-Vue/src/components/CameraPreview.vue +++ b/Hardware-Vue/src/components/CameraPreview.vue @@ -1,14 +1,21 @@ + + + + diff --git a/Hardware-Vue/src/views/SampleSetupView.vue b/Hardware-Vue/src/views/SampleSetupView.vue index 57c35eb..b8a8bf8 100644 --- a/Hardware-Vue/src/views/SampleSetupView.vue +++ b/Hardware-Vue/src/views/SampleSetupView.vue @@ -1,30 +1,87 @@ @@ -39,7 +96,7 @@ function previewFocus() {
- +
- + @@ -128,16 +212,16 @@ function previewFocus() { .guide-steps { display: flex; - flex: 1; + flex: none; flex-direction: column; } .guide-step { display: flex; - flex: 1; + flex: none; align-items: center; gap: 22px; - min-height: 0; + min-height: 88px; padding: 0 34px; border-bottom: 1px solid rgba(255, 255, 255, 0.18); } @@ -177,10 +261,105 @@ function previewFocus() { padding: 2px; } +.placement-requirements { + display: flex; + flex: 1; + flex-direction: column; + min-height: 0; + margin: 0 24px 22px; + padding: 18px 22px; + overflow: hidden; + border: 1px solid rgba(224, 154, 6, 0.45); + border-radius: 14px; + background: var(--orange-soft); + color: #5b4213; +} + +.placement-requirements h3 { + display: flex; + align-items: center; + gap: 10px; + color: #8a5b00; + font-size: 22px; + font-weight: 700; + letter-spacing: 1px; +} + +.placement-requirements__mark { + display: grid; + flex: none; + place-items: center; + width: 28px; + height: 28px; + border-radius: 50%; + color: #fff; + background: var(--orange-dark); + font-size: 19px; + font-weight: 700; +} + +.placement-requirements ul { + display: grid; + gap: 8px; + margin-top: 12px; +} + +.placement-requirements li { + display: flex; + gap: 9px; + color: #5b4213; + font-size: 18px; + line-height: 1.4; +} + +.placement-requirements__index { + display: grid; + flex: none; + place-items: center; + width: 21px; + height: 21px; + margin-top: 2px; + border-radius: 50%; + background: rgba(224, 154, 6, 0.18); + color: #8a5b00; + font-size: 13px; + font-weight: 700; +} + +.placement-requirements__warning { + margin-top: 10px; + padding-top: 10px; + border-top: 1px dashed rgba(138, 91, 0, 0.32); + color: var(--red); + font-size: 18px; + font-weight: 600; + line-height: 1.4; +} + +.placement-confirm { + display: flex; + align-items: center; + gap: 10px; + margin-top: auto; + padding-top: 10px; + color: #5b4213; + font-size: 17px; + cursor: pointer; + user-select: none; +} + +.placement-confirm input { + flex: none; + width: 20px; + height: 20px; + accent-color: var(--teal-dark); + cursor: pointer; +} + .guide-actions { display: grid; flex: none; - grid-template-columns: 1.16fr 0.84fr; + grid-template-columns: 1fr; gap: 20px; height: 78px; } @@ -200,6 +379,12 @@ function previewFocus() { transform: translateY(-1px); } +.action-button:disabled { + cursor: default; + opacity: 0.7; + transform: none; +} + .action-button--start { color: #fff; background: linear-gradient(180deg, #ffc52c 0%, #f3ae0d 100%); @@ -214,15 +399,4 @@ function previewFocus() { 0 16px 30px rgba(224, 154, 6, 0.36), inset 0 1px 0 rgba(255, 255, 255, 0.55); } - -.action-button--ghost { - border: 2px solid #d3dbe6; - color: #253243; - background: #fff; -} - -.action-button--ghost:hover { - border-color: #aebdcd; - background: #f8fafc; -} diff --git a/Hardware-Vue/src/views/ScanPlanView.vue b/Hardware-Vue/src/views/ScanPlanView.vue index 4300636..0896103 100644 --- a/Hardware-Vue/src/views/ScanPlanView.vue +++ b/Hardware-Vue/src/views/ScanPlanView.vue @@ -1,24 +1,115 @@ @@ -101,6 +232,147 @@ function abortProcess() { justify-self: center; } +.result-card { + display: flex; + flex-direction: column; + width: 1120px; + max-width: 100%; + height: 100%; + overflow: hidden; + border: 1px solid #1e55a4; + border-radius: 18px; + background: #0b1220; + box-shadow: 0 18px 44px rgba(31, 77, 147, 0.28); + justify-self: center; +} + +.result-card__header { + display: flex; + flex: none; + align-items: center; + justify-content: space-between; + height: 66px; + padding: 0 26px; + background: linear-gradient(180deg, #3d80e2 0%, #2f6fd0 100%); +} + +.result-card__header h2 { + color: #fff; + font-size: 28px; + font-weight: 600; + letter-spacing: 3px; + text-shadow: 0 1px 3px rgba(16, 49, 101, 0.22); +} + +.result-card__count { + padding: 5px 14px; + border: 1px solid rgba(255, 255, 255, 0.3); + border-radius: 30px; + background: rgba(255, 255, 255, 0.12); + color: #fff; + font-size: 17px; + letter-spacing: 1px; +} + +.result-card__viewport { + display: grid; + flex: 1; + min-height: 0; + place-items: center; + padding: 10px; +} + +.result-card__image { + width: 100%; + height: 100%; + object-fit: contain; +} + +.error-card { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + width: 1120px; + max-width: 100%; + height: 100%; + padding: 40px; + border: 1px solid #d9e0e8; + border-radius: 18px; + background: #fff; + box-shadow: var(--shadow-card); + justify-self: center; + text-align: center; +} + +.error-card__icon { + display: grid; + place-items: center; + width: 96px; + height: 96px; + margin-bottom: 24px; + border-radius: 50%; + color: var(--red); + background: #fdeeee; +} + +.error-card__icon svg { + width: 54px; + height: 54px; +} + +.error-card h2 { + color: #1f2937; + font-size: 32px; + font-weight: 600; + letter-spacing: 2px; +} + +.error-card p { + margin-top: 16px; + max-width: 760px; + color: var(--muted); + font-size: 20px; + line-height: 1.6; +} + +.error-card__actions { + display: flex; + gap: 20px; + margin-top: 32px; +} + +.error-button { + width: 200px; + height: 58px; + border-radius: 12px; + font-size: 21px; + font-weight: 600; + letter-spacing: 3px; + transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease; +} + +.error-button--ghost { + border: 2px solid var(--line-strong); + color: var(--ink-soft); + background: #fff; +} + +.error-button--ghost:hover { + background: var(--surface-soft); +} + +.error-button--primary { + color: #fff; + background: linear-gradient(180deg, #4b89e4 0%, #2f6fd0 100%); + box-shadow: 0 10px 22px rgba(47, 111, 208, 0.28); +} + +.error-button--primary:hover { + transform: translateY(-1px); + box-shadow: 0 14px 28px rgba(47, 111, 208, 0.36); +} + .params-card { display: flex; flex-direction: column; @@ -173,6 +445,33 @@ function abortProcess() { top: 900px; right: 44px; left: 44px; + display: flex; + align-items: center; + gap: 20px; height: 54px; } + +.scan-progress__strip { + flex: 1; + min-width: 0; +} + +.scan-next { + flex: none; + width: 280px; + height: 54px; + border-radius: 10px; + color: #fff; + font-size: 23px; + font-weight: 600; + letter-spacing: 3px; + background: linear-gradient(180deg, #4b89e4 0%, #2f6fd0 100%); + box-shadow: 0 10px 22px rgba(47, 111, 208, 0.28); + transition: transform 0.2s ease, box-shadow 0.2s ease; +} + +.scan-next:hover { + transform: translateY(-1px); + box-shadow: 0 14px 28px rgba(47, 111, 208, 0.36); +} diff --git a/Hardware-Vue/src/views/SystemConfigView.vue b/Hardware-Vue/src/views/SystemConfigView.vue index c940d7b..779252b 100644 --- a/Hardware-Vue/src/views/SystemConfigView.vue +++ b/Hardware-Vue/src/views/SystemConfigView.vue @@ -109,6 +109,22 @@ function closeForm() { formOpen.value = false } +let backdropPressed = false + +function onBackdropPointerDown(event: PointerEvent) { + backdropPressed = event.target === event.currentTarget +} + +function onBackdropPointerUp(event: PointerEvent) { + if (event.target !== event.currentTarget) backdropPressed = false +} + +function closeOnBackdrop(event: MouseEvent, action: () => void) { + const shouldClose = backdropPressed && event.target === event.currentTarget + backdropPressed = false + if (shouldClose) action() +} + async function save() { if (saving.value) return @@ -254,7 +270,13 @@ onMounted(() => { -
+