Document local setup and OCR workflow
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import {
|
||||
isCalibrationReady,
|
||||
isRectInside,
|
||||
parseFieldValue,
|
||||
rectFromPoints,
|
||||
resolveFieldRect,
|
||||
} from "../src/parser.js";
|
||||
|
||||
test("normalizes a reverse drag into a positive rectangle", () => {
|
||||
assert.deepEqual(rectFromPoints({ x: 140, y: 90 }, { x: 20, y: 30 }), {
|
||||
x: 20,
|
||||
y: 30,
|
||||
width: 120,
|
||||
height: 60,
|
||||
});
|
||||
});
|
||||
|
||||
test("moves calibrated fields together with the detected anchor", () => {
|
||||
assert.deepEqual(
|
||||
resolveFieldRect(
|
||||
{ x: 400, y: 250 },
|
||||
{ offsetX: 32, offsetY: 80, width: 180, height: 24 },
|
||||
),
|
||||
{ x: 432, y: 330, width: 180, height: 24 },
|
||||
);
|
||||
});
|
||||
|
||||
test("parses formatted prices and rejects empty numeric OCR", () => {
|
||||
assert.equal(parseFieldValue("price", "1 250,000 adena"), 1250000);
|
||||
assert.equal(parseFieldValue("quantity", "not found"), null);
|
||||
assert.equal(parseFieldValue("item", " Soulshot: S-grade\n"), "Soulshot: S-grade");
|
||||
});
|
||||
|
||||
test("requires an anchor image and at least one field", () => {
|
||||
assert.equal(isCalibrationReady({ anchor: null, fields: [] }), false);
|
||||
assert.equal(
|
||||
isCalibrationReady({
|
||||
anchor: { image: "data:image/png;base64,x", width: 20, height: 10 },
|
||||
fields: [{ id: "price" }],
|
||||
}),
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
test("detects OCR rectangles outside the captured frame", () => {
|
||||
assert.equal(isRectInside({ x: 10, y: 10, width: 20, height: 20 }, 100, 100), true);
|
||||
assert.equal(isRectInside({ x: 90, y: 10, width: 20, height: 20 }, 100, 100), false);
|
||||
});
|
||||
Reference in New Issue
Block a user