The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
OCR: a frame that says 0–1000 is trusted, one box past 1000 no longer turns them all to pixels
Claudea937fed2c3fa
diff --git a/src/lib/ocr.ts b/src/lib/ocr.tsindex acc59861..7c211e9c 100644--- a/src/lib/ocr.ts+++ b/src/lib/ocr.ts@@ -111,6 +111,9 @@ function itemsOf(v: unknown): unknown[] | undefined {const r4 = (n: number) => Math.round(n * 10000) / 10000;const clamp01 = (n: number) => Math.min(1, Math.max(0, n));+/** How far past 1000 an answer that doesn't say its units must reach before it reads as pixels. */+const PIXELS_PAST = 1100;+/*** The size the corners are measured in: 1000 for the relative boxes the instruction asks for, 1 for* boxes that are already fractions, the frame's pixels when it says the corners are pixels.@@ -120,8 +123,11 @@ function unitsFor(all: [number, number, number, number][], frame?: OcrFrame): [nif (sized && frame.coords === "pixels") return [frame.width!, frame.height!];const max = Math.max(0, ...all.flat());if (max <= 1.0001) return [1, 1];- // Past 1000 the model answered in the pixels of the picture it saw (older Qwen-VL habits).- return max > 1000.5 && sized ? [frame.width!, frame.height!] : [1000, 1000];+ // The workflow says 0–1000 (ocr-lines-qwen35's frame always does): a box reaching past 1000 is an+ // overshoot, kept to the image below, not a sign the other boxes are pixels.+ if (frame?.coords === "relative-1000") return [1000, 1000];+ // Units unsaid: well past 1000, the model answered in the pixels of the picture it saw (older Qwen-VL habits).+ return max > PIXELS_PAST && sized ? [frame.width!, frame.height!] : [1000, 1000];}/** A model's OCR answer as lines with 0–1 boxes, in the order it read them. */diff --git a/tests/ocr.test.ts b/tests/ocr.test.tsindex c20cca72..a3fbfad7 100644--- a/tests/ocr.test.ts+++ b/tests/ocr.test.ts@@ -38,6 +38,18 @@ describe("OCR answers → lines with 0–1 boxes", () => {// Under 1000 the boxes stay relative (what the instruction asks for), size or not.expect(parseOcrLines('[{"bbox": [100, 100, 600, 200], "text": "Rel"}]', frame).lines[0].bbox).toEqual([0.1, 0.1, 0.5, 0.1]);expect(parseOcrLines('[{"bbox": [128, 96, 640, 192], "text": "Px"}]', { ...frame, coords: "pixels" }).lines[0].bbox).toEqual([0.1, 0.1, 0.4, 0.1]);+ // A little past 1000 with the units unsaid is an overshoot, not pixels.+ expect(parseOcrLines('[{"bbox": [100, 100, 600, 200], "text": "A"}, {"bbox": [900, 900, 1005, 980], "text": "B"}]', frame).lines[0].bbox).toEqual([0.1, 0.1, 0.5, 0.1]);+ });++ it("trusts the frame's declared 0–1000: one box overshooting doesn't move the others", () => {+ // What ocr-lines-qwen35's frame output always says (the size the model saw, coords relative-1000).+ const frame = { width: 1280, height: 960, coords: "relative-1000" };+ const { lines } = parseOcrLines('[{"bbox": [100, 100, 600, 200], "text": "A"}, {"bbox": [900, 900, 1080, 1040], "text": "B"}]', frame);+ expect(lines).toEqual([+ { text: "A", bbox: [0.1, 0.1, 0.5, 0.1] },+ { text: "B", bbox: [0.9, 0.9, 0.1, 0.1] },+ ]);});it("puts swapped corners in order, keeps boxes on the image, and drops what isn't a line", () => {