Spaces:
Running
Running
Upload 37 files
Browse files
src/components/MultiSourceCaptioningView.tsx
CHANGED
@@ -19,7 +19,6 @@ function parseFlatBoxArray(arr: any[]): { label: string, bbox_2d: number[] }[] {
|
|
19 |
function normalizeBoxes(raw: any): { label: string, bbox_2d: number[] }[] {
|
20 |
if (!raw) return [];
|
21 |
let boxes = [];
|
22 |
-
// If the object has an 'image' property that is an array, use that
|
23 |
if (typeof raw === "object" && raw !== null && Array.isArray(raw.image)) {
|
24 |
boxes = raw.image;
|
25 |
} else if (Array.isArray(raw)) {
|
@@ -27,38 +26,22 @@ function normalizeBoxes(raw: any): { label: string, bbox_2d: 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
|
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 |
-
//
|
40 |
-
if (
|
41 |
-
Array.isArray(bbox) &&
|
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]]
|
48 |
if (
|
49 |
Array.isArray(bbox) &&
|
50 |
bbox.length === 2 &&
|
51 |
Array.isArray(bbox[0]) &&
|
52 |
Array.isArray(bbox[1]) &&
|
53 |
bbox[0].length === 2 &&
|
54 |
-
bbox[1].length === 2
|
55 |
-
bbox[0].every((v: any) => typeof v === "number") &&
|
56 |
-
bbox[1].every((v: any) => typeof v === "number")
|
57 |
) {
|
58 |
bbox = [bbox[0][0], bbox[0][1], bbox[1][0], bbox[1][1]];
|
59 |
-
return { ...obj, bbox_2d: bbox };
|
60 |
}
|
61 |
-
//
|
62 |
if (
|
63 |
Array.isArray(bbox) &&
|
64 |
bbox.length === 4 &&
|
@@ -66,11 +49,10 @@ function normalizeBoxes(raw: any): { label: string, bbox_2d: number[] }[] {
|
|
66 |
) {
|
67 |
return { ...obj, bbox_2d: bbox };
|
68 |
}
|
69 |
-
//
|
70 |
-
console.log(`normalizeBoxes: skipping object at idx ${idx} (unrecognized bbox_2d format):`, bbox);
|
71 |
return null;
|
72 |
})
|
73 |
-
.filter((obj: any) => obj
|
74 |
}
|
75 |
|
76 |
function isImageFile(file: File) {
|
|
|
19 |
function normalizeBoxes(raw: any): { label: string, bbox_2d: number[] }[] {
|
20 |
if (!raw) return [];
|
21 |
let boxes = [];
|
|
|
22 |
if (typeof raw === "object" && raw !== null && Array.isArray(raw.image)) {
|
23 |
boxes = raw.image;
|
24 |
} else if (Array.isArray(raw)) {
|
|
|
26 |
} else if (typeof raw === "object" && raw !== null) {
|
27 |
boxes = [raw];
|
28 |
}
|
|
|
|
|
29 |
return boxes
|
30 |
+
.map((obj: any) => {
|
31 |
+
if (!obj || !obj.bbox_2d) return null;
|
|
|
|
|
|
|
32 |
let bbox = obj.bbox_2d;
|
33 |
+
// If bbox_2d is [[x1, y1], [x2, y2]], convert to [x1, y1, x2, y2]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
if (
|
35 |
Array.isArray(bbox) &&
|
36 |
bbox.length === 2 &&
|
37 |
Array.isArray(bbox[0]) &&
|
38 |
Array.isArray(bbox[1]) &&
|
39 |
bbox[0].length === 2 &&
|
40 |
+
bbox[1].length === 2
|
|
|
|
|
41 |
) {
|
42 |
bbox = [bbox[0][0], bbox[0][1], bbox[1][0], bbox[1][1]];
|
|
|
43 |
}
|
44 |
+
// If bbox_2d is [x1, y1, x2, y2], use as-is
|
45 |
if (
|
46 |
Array.isArray(bbox) &&
|
47 |
bbox.length === 4 &&
|
|
|
49 |
) {
|
50 |
return { ...obj, bbox_2d: bbox };
|
51 |
}
|
52 |
+
// Otherwise, skip
|
|
|
53 |
return null;
|
54 |
})
|
55 |
+
.filter((obj: any) => obj);
|
56 |
}
|
57 |
|
58 |
function isImageFile(file: File) {
|