Spaces:
Running
Running
Upload 37 files
Browse files
src/components/MultiSourceCaptioningView.tsx
CHANGED
@@ -27,9 +27,14 @@ function normalizeBoxes(raw: any): { label: string, bbox_2d: number[] }[] {
|
|
27 |
} else if (typeof raw === "object" && raw !== null) {
|
28 |
boxes = [raw];
|
29 |
}
|
|
|
|
|
30 |
return boxes
|
31 |
-
.
|
32 |
-
|
|
|
|
|
|
|
33 |
let bbox = obj.bbox_2d;
|
34 |
// Accept [x1, y1, x2, y2]
|
35 |
if (
|
@@ -37,7 +42,6 @@ function normalizeBoxes(raw: any): { label: string, bbox_2d: number[] }[] {
|
|
37 |
bbox.length === 4 &&
|
38 |
bbox.every((v: any) => typeof v === "number")
|
39 |
) {
|
40 |
-
// Already in [x1, y1, x2, y2] format
|
41 |
return { ...obj, bbox_2d: bbox };
|
42 |
}
|
43 |
// Accept [[x1, y1], [x2, y2]]
|
@@ -54,7 +58,16 @@ function normalizeBoxes(raw: any): { label: string, bbox_2d: number[] }[] {
|
|
54 |
bbox = [bbox[0][0], bbox[0][1], bbox[1][0], bbox[1][1]];
|
55 |
return { ...obj, bbox_2d: bbox };
|
56 |
}
|
57 |
-
//
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
return null;
|
59 |
})
|
60 |
.filter((obj: any) => obj && Array.isArray(obj.bbox_2d) && obj.bbox_2d.length === 4 && obj.bbox_2d.every((v: any) => typeof v === "number"));
|
|
|
27 |
} else if (typeof raw === "object" && raw !== null) {
|
28 |
boxes = [raw];
|
29 |
}
|
30 |
+
// Debug: print all candidate boxes
|
31 |
+
console.log("normalizeBoxes: candidate objects:", boxes);
|
32 |
return boxes
|
33 |
+
.map((obj: any, idx: number) => {
|
34 |
+
if (!obj || !obj.bbox_2d) {
|
35 |
+
console.log(`normalizeBoxes: skipping object at idx ${idx} (no bbox_2d):`, obj);
|
36 |
+
return null;
|
37 |
+
}
|
38 |
let bbox = obj.bbox_2d;
|
39 |
// Accept [x1, y1, x2, y2]
|
40 |
if (
|
|
|
42 |
bbox.length === 4 &&
|
43 |
bbox.every((v: any) => typeof v === "number")
|
44 |
) {
|
|
|
45 |
return { ...obj, bbox_2d: bbox };
|
46 |
}
|
47 |
// Accept [[x1, y1], [x2, y2]]
|
|
|
58 |
bbox = [bbox[0][0], bbox[0][1], bbox[1][0], bbox[1][1]];
|
59 |
return { ...obj, bbox_2d: bbox };
|
60 |
}
|
61 |
+
// Accept [x, y, w, h] (if that's possible in your model)
|
62 |
+
if (
|
63 |
+
Array.isArray(bbox) &&
|
64 |
+
bbox.length === 4 &&
|
65 |
+
bbox.every((v: any) => typeof v === "number")
|
66 |
+
) {
|
67 |
+
return { ...obj, bbox_2d: bbox };
|
68 |
+
}
|
69 |
+
// Log if bbox_2d is present but not recognized
|
70 |
+
console.log(`normalizeBoxes: skipping object at idx ${idx} (unrecognized bbox_2d format):`, bbox);
|
71 |
return null;
|
72 |
})
|
73 |
.filter((obj: any) => obj && Array.isArray(obj.bbox_2d) && obj.bbox_2d.length === 4 && obj.bbox_2d.every((v: any) => typeof v === "number"));
|