Spaces:
Sleeping
Sleeping
Commit ·
e467b57
1
Parent(s): 107ce58
fix: apply NMS filtering to raw detection mode to fix overlapping bounding boxes and count mismatch
Browse files
toothmap_frontend/src/App.jsx
CHANGED
|
@@ -300,13 +300,13 @@ export default function App() {
|
|
| 300 |
});
|
| 301 |
}
|
| 302 |
|
| 303 |
-
if (
|
| 304 |
-
|
| 305 |
const [x1, y1, x2, y2] = box;
|
| 306 |
const rx = x1*sx, ry = y1*sy, rw = (x2-x1)*sx, rh = (y2-y1)*sy;
|
| 307 |
ctx.strokeStyle = '#3b82f6'; ctx.lineWidth = 2;
|
| 308 |
ctx.strokeRect(rx, ry, rw, rh);
|
| 309 |
-
const s = `${(
|
| 310 |
ctx.fillStyle = '#3b82f6'; ctx.fillRect(rx, ry - 20, 40, 20);
|
| 311 |
ctx.fillStyle = 'white'; ctx.font = '12px Arial';
|
| 312 |
ctx.fillText(s, rx + 4, ry - 5);
|
|
@@ -315,9 +315,10 @@ export default function App() {
|
|
| 315 |
}, [pipelineResults, rawBoxes, isPipeline]);
|
| 316 |
|
| 317 |
const uniquePipelineResults = pipelineResults ? applyNMS(pipelineResults, 0.40) : null;
|
|
|
|
| 318 |
const detectedFDIs = uniquePipelineResults ? uniquePipelineResults.filter(r => r.fdi > 0).map(r => r.fdi) : [];
|
| 319 |
-
const totalDetected = uniquePipelineResults ? uniquePipelineResults.length : (
|
| 320 |
-
const hasResults = uniquePipelineResults ||
|
| 321 |
|
| 322 |
return (
|
| 323 |
<div className="min-h-screen flex flex-col bg-zinc-950 font-sans text-slate-200">
|
|
@@ -470,13 +471,13 @@ export default function App() {
|
|
| 470 |
)}
|
| 471 |
|
| 472 |
{/* Detection results list (for non-pipeline modes) */}
|
| 473 |
-
{
|
| 474 |
<div className="bg-zinc-900/60 border border-zinc-800/60 rounded-xl p-4">
|
| 475 |
<p className="text-xs font-bold text-zinc-400 uppercase tracking-widest mb-3">Detection Results</p>
|
| 476 |
<div className="flex flex-wrap gap-2">
|
| 477 |
-
{
|
| 478 |
<span key={i} className="px-2 py-1 rounded-lg bg-blue-500/10 border border-blue-500/30 text-blue-300 text-xs font-medium">
|
| 479 |
-
Tooth #{i+1} — {(
|
| 480 |
</span>
|
| 481 |
))}
|
| 482 |
</div>
|
|
|
|
| 300 |
});
|
| 301 |
}
|
| 302 |
|
| 303 |
+
if (uniqueDetectionResults) {
|
| 304 |
+
uniqueDetectionResults.forEach(({ box, score }, i) => {
|
| 305 |
const [x1, y1, x2, y2] = box;
|
| 306 |
const rx = x1*sx, ry = y1*sy, rw = (x2-x1)*sx, rh = (y2-y1)*sy;
|
| 307 |
ctx.strokeStyle = '#3b82f6'; ctx.lineWidth = 2;
|
| 308 |
ctx.strokeRect(rx, ry, rw, rh);
|
| 309 |
+
const s = `${(score*100).toFixed(0)}%`;
|
| 310 |
ctx.fillStyle = '#3b82f6'; ctx.fillRect(rx, ry - 20, 40, 20);
|
| 311 |
ctx.fillStyle = 'white'; ctx.font = '12px Arial';
|
| 312 |
ctx.fillText(s, rx + 4, ry - 5);
|
|
|
|
| 315 |
}, [pipelineResults, rawBoxes, isPipeline]);
|
| 316 |
|
| 317 |
const uniquePipelineResults = pipelineResults ? applyNMS(pipelineResults, 0.40) : null;
|
| 318 |
+
const uniqueDetectionResults = rawBoxes ? applyNMS(rawBoxes.boxes.map((box, i) => ({ box, score: rawBoxes.scores[i] })), 0.40) : null;
|
| 319 |
const detectedFDIs = uniquePipelineResults ? uniquePipelineResults.filter(r => r.fdi > 0).map(r => r.fdi) : [];
|
| 320 |
+
const totalDetected = uniquePipelineResults ? uniquePipelineResults.length : (uniqueDetectionResults ? uniqueDetectionResults.length : 0);
|
| 321 |
+
const hasResults = uniquePipelineResults || uniqueDetectionResults;
|
| 322 |
|
| 323 |
return (
|
| 324 |
<div className="min-h-screen flex flex-col bg-zinc-950 font-sans text-slate-200">
|
|
|
|
| 471 |
)}
|
| 472 |
|
| 473 |
{/* Detection results list (for non-pipeline modes) */}
|
| 474 |
+
{uniqueDetectionResults && (
|
| 475 |
<div className="bg-zinc-900/60 border border-zinc-800/60 rounded-xl p-4">
|
| 476 |
<p className="text-xs font-bold text-zinc-400 uppercase tracking-widest mb-3">Detection Results</p>
|
| 477 |
<div className="flex flex-wrap gap-2">
|
| 478 |
+
{uniqueDetectionResults.map((r, i) => (
|
| 479 |
<span key={i} className="px-2 py-1 rounded-lg bg-blue-500/10 border border-blue-500/30 text-blue-300 text-xs font-medium">
|
| 480 |
+
Tooth #{i+1} — {(r.score*100).toFixed(0)}%
|
| 481 |
</span>
|
| 482 |
))}
|
| 483 |
</div>
|