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 // 贴到图片上边缘的框,标签改画在框内侧,避免被裁掉