From 2a26966df7ad13ea5abd71879273bd6b31bc8e40 Mon Sep 17 00:00:00 2001 From: Cmake Date: Thu, 3 Dec 2026 22:27:38 +0800 Subject: [PATCH] =?UTF-8?q?fix(playground):=20=E6=A0=87=E6=B3=A8=E5=B1=82?= =?UTF-8?q?=E5=90=8C=E6=97=B6=E8=AF=86=E5=88=AB=20detections=20=E4=B8=8E?= =?UTF-8?q?=20objects=EF=BC=8C=E6=A0=87=E7=AD=BE=E5=B8=A6=E4=B8=8A?= =?UTF-8?q?=E7=BD=AE=E4=BF=A1=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/pages/Playground.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/web/src/pages/Playground.tsx b/web/src/pages/Playground.tsx index 600bef3..74a672c 100644 --- a/web/src/pages/Playground.tsx +++ b/web/src/pages/Playground.tsx @@ -45,6 +45,7 @@ function readFile(file: File): Promise { interface Detection { class?: string box?: number[] + confidence?: number } interface DetectionWrap { result?: { detections?: Detection[] } @@ -93,8 +94,10 @@ export default function PlaygroundPage({ token, role, onLogout }: Props) { cv.height = img.naturalHeight ctx.drawImage(img, 0, 0) + // 图标/文字检测返回 detections,目标类型检测返回 objects,两种都要能画 + const wrap = result as DetectionWrap & { result?: { detections?: Detection[]; objects?: Detection[] } } const dets: Detection[] = - (result as DetectionWrap)?.result?.detections || (result as DetectionWrap)?.detections || [] + wrap?.result?.detections || wrap?.result?.objects || wrap?.detections || [] const scale = Math.max(1, img.naturalWidth / 500) ctx.lineWidth = 1.6 * scale ctx.font = `${11 * scale}px ui-monospace, monospace` @@ -105,7 +108,9 @@ export default function PlaygroundPage({ token, role, onLogout }: Props) { if (b.length < 4) return ctx.strokeStyle = '#e5e5e5' ctx.strokeRect(b[0], b[1], b[2] - b[0], b[3] - b[1]) - const txt = `${i + 1}${d.class ? ' ' + d.class : ''}` + const txt = `${i + 1}${d.class ? ' ' + d.class : ''}${ + typeof d.confidence === 'number' ? ' ' + d.confidence.toFixed(2) : '' + }` const w = ctx.measureText(txt).width + 6 * scale const lh = 14 * scale // 贴到图片上边缘的框,标签改画在框内侧,避免被裁掉