Skip to content

Commit 1438224

Browse files
committed
feat: fix wopee-dino coordinatex post procesing
1 parent 99a9070 commit 1438224

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

app/src/core/api-client.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,43 @@ export class ApiClient {
347347
const w = Number(serverResponse.width || imageW || 0);
348348
const h = Number(serverResponse.height || imageH || 0);
349349

350+
// Minimal-pass adapter: if the server already returns pixel-space detections,
351+
// forward them with minimal transformation (round only, keep order).
352+
if (Array.isArray(serverResponse?.detections) && serverResponse.detections.length > 0) {
353+
const toBox = (d) => {
354+
const src = (d && d.bbox) ? d.bbox : d || {};
355+
const x = Number(src.x);
356+
const y = Number(src.y);
357+
const width = Number(src.width);
358+
const height = Number(src.height);
359+
const conf = (d && d.score != null) ? Number(d.score)
360+
: (d && d.confidence != null) ? Number(d.confidence)
361+
: 0;
362+
return {
363+
x: Math.max(0, Number.isFinite(x) ? x : 0),
364+
y: Math.max(0, Number.isFinite(y) ? y : 0),
365+
width: Math.max(0, Number.isFinite(width) ? width : 0),
366+
height: Math.max(0, Number.isFinite(height) ? height : 0),
367+
confidence: Math.max(0, Math.min(1, conf || 0))
368+
};
369+
};
370+
const mapped = serverResponse.detections
371+
.map(toBox)
372+
.filter(b => Number.isFinite(b.x) && Number.isFinite(b.y));
373+
// If nothing valid after mapping, fall through to other shapes.
374+
if (mapped.length > 0) {
375+
const primary = { type: 'bbox', ...mapped[0] };
376+
const others = mapped.slice(1).map(b => ({ type: 'bbox', ...b }));
377+
return JSON.stringify({
378+
coordinate_system: 'pixel',
379+
origin: 'top-left',
380+
image_size: { width: w, height: h },
381+
primary,
382+
others
383+
});
384+
}
385+
}
386+
350387
const boxes = [];
351388
const points = [];
352389

0 commit comments

Comments
 (0)