Spaces:
Running
Running
Upload 51 files
Browse files
src/components/MultiSourceCaptioningView.tsx
CHANGED
@@ -141,35 +141,6 @@ function postprocessYoloOutput(output: ort.Tensor) {
|
|
141 |
return results;
|
142 |
}
|
143 |
|
144 |
-
// 2. Add a function to crop a detection from a video frame
|
145 |
-
function cropBoxFromFrame(video: HTMLVideoElement, bbox: number[]) {
|
146 |
-
const [x1, y1, x2, y2] = bbox;
|
147 |
-
const width = x2 - x1;
|
148 |
-
const height = y2 - y1;
|
149 |
-
const canvas = document.createElement('canvas');
|
150 |
-
canvas.width = width;
|
151 |
-
canvas.height = height;
|
152 |
-
const ctx = canvas.getContext('2d');
|
153 |
-
if (!ctx) throw new Error('Could not get 2D context for cropping');
|
154 |
-
ctx.drawImage(video, x1, y1, width, height, 0, 0, width, height);
|
155 |
-
return new Promise<Blob>(resolve => canvas.toBlob(blob => resolve(blob!), 'image/jpeg'));
|
156 |
-
}
|
157 |
-
|
158 |
-
// Helper: compute IOU between two boxes [x1,y1,x2,y2]
|
159 |
-
function iou(boxA: number[], boxB: number[]) {
|
160 |
-
const [ax1, ay1, ax2, ay2] = boxA;
|
161 |
-
const [bx1, by1, bx2, by2] = boxB;
|
162 |
-
const interX1 = Math.max(ax1, bx1);
|
163 |
-
const interY1 = Math.max(ay1, by1);
|
164 |
-
const interX2 = Math.min(ax2, bx2);
|
165 |
-
const interY2 = Math.min(ay2, by2);
|
166 |
-
const interArea = Math.max(0, interX2 - interX1) * Math.max(0, interY2 - interY1);
|
167 |
-
const areaA = (ax2 - ax1) * (ay2 - ay1);
|
168 |
-
const areaB = (bx2 - bx1) * (by2 - by1);
|
169 |
-
const unionArea = areaA + areaB - interArea;
|
170 |
-
return unionArea > 0 ? interArea / unionArea : 0;
|
171 |
-
}
|
172 |
-
|
173 |
// Helper type guard for annotation
|
174 |
function hasAnnotation(obj: any): obj is { annotation: string } {
|
175 |
return typeof obj === 'object' && obj !== null && 'annotation' in obj && typeof obj.annotation === 'string';
|
@@ -200,8 +171,6 @@ export default function MultiSourceCaptioningView() {
|
|
200 |
const boxHistoryRef = useRef<any[]>([]);
|
201 |
// Add a ref to store the latest YOLOv8 results (with optional FastVLM annotation)
|
202 |
const lastYoloBoxesRef = React.useRef<any[]>([]);
|
203 |
-
// Add a ref to store annotation history for persistence
|
204 |
-
const annotationHistoryRef = React.useRef<any[]>([]);
|
205 |
const { isLoaded, isLoading, error: modelError, runInference } = useVLMContext();
|
206 |
|
207 |
// Remove videoProcessingRef and exampleProcessingRef
|
|
|
141 |
return results;
|
142 |
}
|
143 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
144 |
// Helper type guard for annotation
|
145 |
function hasAnnotation(obj: any): obj is { annotation: string } {
|
146 |
return typeof obj === 'object' && obj !== null && 'annotation' in obj && typeof obj.annotation === 'string';
|
|
|
171 |
const boxHistoryRef = useRef<any[]>([]);
|
172 |
// Add a ref to store the latest YOLOv8 results (with optional FastVLM annotation)
|
173 |
const lastYoloBoxesRef = React.useRef<any[]>([]);
|
|
|
|
|
174 |
const { isLoaded, isLoading, error: modelError, runInference } = useVLMContext();
|
175 |
|
176 |
// Remove videoProcessingRef and exampleProcessingRef
|