@rickcedwhat/playwright-smart-vision 0.3.0-next.92600aa → 0.3.0-next.9cee38e
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/author/apply.d.ts +24 -2
- package/dist/author/apply.d.ts.map +1 -1
- package/dist/author/apply.js +129 -21
- package/dist/author/apply.js.map +1 -1
- package/dist/author/author.test.js +88 -2
- package/dist/author/author.test.js.map +1 -1
- package/dist/author/catalog.d.ts +5 -2
- package/dist/author/catalog.d.ts.map +1 -1
- package/dist/author/catalog.js +29 -14
- package/dist/author/catalog.js.map +1 -1
- package/dist/author/detect.d.ts +7 -2
- package/dist/author/detect.d.ts.map +1 -1
- package/dist/author/detect.js +187 -27
- package/dist/author/detect.js.map +1 -1
- package/dist/author/geometry.d.ts +42 -2
- package/dist/author/geometry.d.ts.map +1 -1
- package/dist/author/geometry.js +237 -4
- package/dist/author/geometry.js.map +1 -1
- package/dist/author/geometry.test.js +207 -2
- package/dist/author/geometry.test.js.map +1 -1
- package/dist/author/index.d.ts +5 -3
- package/dist/author/index.d.ts.map +1 -1
- package/dist/author/index.js +3 -2
- package/dist/author/index.js.map +1 -1
- package/dist/author/labels.d.ts +33 -0
- package/dist/author/labels.d.ts.map +1 -0
- package/dist/author/labels.js +111 -0
- package/dist/author/labels.js.map +1 -0
- package/dist/author/labels.test.d.ts +2 -0
- package/dist/author/labels.test.d.ts.map +1 -0
- package/dist/author/labels.test.js +64 -0
- package/dist/author/labels.test.js.map +1 -0
- package/dist/author/show.d.ts +8 -0
- package/dist/author/show.d.ts.map +1 -0
- package/dist/author/show.js +20 -0
- package/dist/author/show.js.map +1 -0
- package/dist/field-extractor.d.ts.map +1 -1
- package/dist/field-extractor.js +5 -15
- package/dist/field-extractor.js.map +1 -1
- package/dist/utils/ocr.d.ts +12 -0
- package/dist/utils/ocr.d.ts.map +1 -1
- package/dist/utils/ocr.js +52 -4
- package/dist/utils/ocr.js.map +1 -1
- package/package.json +1 -1
package/dist/author/detect.js
CHANGED
|
@@ -2,12 +2,61 @@ import fs from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { PNG } from 'pngjs';
|
|
4
4
|
import { VisionUtil, ensureCvReady, getCv } from '../utils/vision.js';
|
|
5
|
-
import { dedupeBoxes, numberBoxes } from './geometry.js';
|
|
5
|
+
import { dedupeBoxes, dropNestedBoxes, numberBoxes, splitBoxGutters, splitMergedFields, unionRects, } from './geometry.js';
|
|
6
|
+
import { labelsFromOcr } from './labels.js';
|
|
7
|
+
import { getOCRUtil } from '../utils/ocr.js';
|
|
6
8
|
import { screenDir } from './storage.js';
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
9
|
+
const MIN = 10;
|
|
10
|
+
const EMPTY_MEAN = 205;
|
|
11
|
+
const FILLED_EXTENT = 0.88;
|
|
12
|
+
const LABEL_SCALE = 2;
|
|
13
|
+
/** Room for a caption sitting just outside the outermost control. */
|
|
14
|
+
const LABEL_PAD = 72;
|
|
15
|
+
function columnMeansGray(gray, rect) {
|
|
16
|
+
const y0 = Math.max(0, rect.y + 2);
|
|
17
|
+
const y1 = Math.min(gray.rows, rect.y + rect.height - 2);
|
|
18
|
+
const rowCount = Math.max(1, y1 - y0);
|
|
19
|
+
const means = [];
|
|
20
|
+
for (let dx = 0; dx < rect.width; dx++) {
|
|
21
|
+
const x = rect.x + dx;
|
|
22
|
+
if (x < 0 || x >= gray.cols) {
|
|
23
|
+
means.push(0);
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
let sum = 0;
|
|
27
|
+
for (let y = y0; y < y1; y++) {
|
|
28
|
+
sum += gray.data[y * gray.cols + x];
|
|
29
|
+
}
|
|
30
|
+
means.push(sum / rowCount);
|
|
31
|
+
}
|
|
32
|
+
return means;
|
|
33
|
+
}
|
|
34
|
+
function rowMeansGray(gray, rect) {
|
|
35
|
+
const x0 = Math.max(0, rect.x);
|
|
36
|
+
const x1 = Math.min(gray.cols, rect.x + rect.width);
|
|
37
|
+
const colCount = Math.max(1, x1 - x0);
|
|
38
|
+
const means = [];
|
|
39
|
+
for (let dy = 0; dy < rect.height; dy++) {
|
|
40
|
+
const y = rect.y + dy;
|
|
41
|
+
if (y < 0 || y >= gray.rows) {
|
|
42
|
+
means.push(0);
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
let sum = 0;
|
|
46
|
+
for (let x = x0; x < x1; x++) {
|
|
47
|
+
sum += gray.data[y * gray.cols + x];
|
|
48
|
+
}
|
|
49
|
+
means.push(sum / colCount);
|
|
50
|
+
}
|
|
51
|
+
return means;
|
|
52
|
+
}
|
|
53
|
+
function keepRect(rect, mean, vertices, extent, imgW, imgH) {
|
|
54
|
+
if (rect.width < MIN || rect.height < MIN)
|
|
55
|
+
return false;
|
|
56
|
+
if (rect.width > imgW * 0.85 || rect.height > imgH * 0.85)
|
|
57
|
+
return false;
|
|
58
|
+
return mean >= EMPTY_MEAN || (vertices === 4 && extent >= FILLED_EXTENT);
|
|
59
|
+
}
|
|
11
60
|
export function detectBoxes(pngBuffer) {
|
|
12
61
|
const cv = getCv();
|
|
13
62
|
const vision = new VisionUtil();
|
|
@@ -25,18 +74,25 @@ export function detectBoxes(pngBuffer) {
|
|
|
25
74
|
for (let i = 0; i < contours.size(); i++) {
|
|
26
75
|
const contour = contours.get(i);
|
|
27
76
|
const rect = cv.boundingRect(contour);
|
|
77
|
+
const peri = cv.arcLength(contour, true);
|
|
78
|
+
const approx = new cv.Mat();
|
|
79
|
+
cv.approxPolyDP(contour, approx, 0.04 * peri, true);
|
|
80
|
+
const area = cv.contourArea(contour);
|
|
81
|
+
const extent = area / (rect.width * rect.height || 1);
|
|
82
|
+
let mean = 0;
|
|
83
|
+
if (rect.width >= 2 && rect.height >= 2 && rect.x + rect.width <= gray.cols && rect.y + rect.height <= gray.rows) {
|
|
84
|
+
const roi = gray.roi(rect);
|
|
85
|
+
mean = cv.mean(roi)[0];
|
|
86
|
+
roi.delete();
|
|
87
|
+
}
|
|
88
|
+
if (keepRect(rect, mean, approx.rows, extent, gray.cols, gray.rows)) {
|
|
89
|
+
raw.push({ x: rect.x, y: rect.y, width: rect.width, height: rect.height });
|
|
90
|
+
}
|
|
91
|
+
approx.delete();
|
|
28
92
|
contour.delete();
|
|
29
|
-
if (rect.width < MIN_W || rect.width > MAX_W)
|
|
30
|
-
continue;
|
|
31
|
-
if (rect.height < MIN_H || rect.height > MAX_H)
|
|
32
|
-
continue;
|
|
33
|
-
const roi = gray.roi(rect);
|
|
34
|
-
const mean = cv.mean(roi)[0];
|
|
35
|
-
roi.delete();
|
|
36
|
-
if (mean < 205)
|
|
37
|
-
continue;
|
|
38
|
-
raw.push({ x: rect.x, y: rect.y, width: rect.width, height: rect.height });
|
|
39
93
|
}
|
|
94
|
+
const split = raw.flatMap((box) => splitBoxGutters(box, columnMeansGray(gray, box), rowMeansGray(gray, box)) || [box]);
|
|
95
|
+
const cells = split.filter((box) => box.height < 80);
|
|
40
96
|
color.delete();
|
|
41
97
|
gray.delete();
|
|
42
98
|
edges.delete();
|
|
@@ -44,26 +100,92 @@ export function detectBoxes(pngBuffer) {
|
|
|
44
100
|
kernel.delete();
|
|
45
101
|
contours.delete();
|
|
46
102
|
hierarchy.delete();
|
|
47
|
-
return numberBoxes(dedupeBoxes(
|
|
103
|
+
return numberBoxes(dedupeBoxes(dropNestedBoxes(splitMergedFields(cells))));
|
|
48
104
|
}
|
|
49
|
-
export function annotateBoxes(pngBuffer, boxes) {
|
|
105
|
+
export function annotateBoxes(pngBuffer, boxes, labels = []) {
|
|
50
106
|
const cv = getCv();
|
|
51
107
|
const png = PNG.sync.read(pngBuffer);
|
|
52
108
|
const mat = new cv.Mat(png.height, png.width, cv.CV_8UC4);
|
|
53
109
|
mat.data.set(png.data);
|
|
54
|
-
const
|
|
55
|
-
const
|
|
110
|
+
const boxColor = new cv.Scalar(220, 40, 40, 255);
|
|
111
|
+
const boxText = new cv.Scalar(180, 0, 0, 255);
|
|
112
|
+
const labelColor = new cv.Scalar(30, 140, 200, 255);
|
|
113
|
+
const labelText = new cv.Scalar(20, 90, 150, 255);
|
|
56
114
|
for (const box of boxes) {
|
|
57
|
-
cv.rectangle(mat, new cv.Point(box.x, box.y), new cv.Point(box.x + box.width, box.y + box.height),
|
|
58
|
-
cv.putText(mat, String(box.id), new cv.Point(box.x + 1, Math.max(10, box.y - 2)), cv.FONT_HERSHEY_SIMPLEX, 0.35,
|
|
115
|
+
cv.rectangle(mat, new cv.Point(box.x, box.y), new cv.Point(box.x + box.width, box.y + box.height), boxColor, 1);
|
|
116
|
+
cv.putText(mat, String(box.id), new cv.Point(box.x + 1, Math.max(10, box.y - 2)), cv.FONT_HERSHEY_SIMPLEX, 0.35, boxText, 1);
|
|
117
|
+
}
|
|
118
|
+
for (const label of labels) {
|
|
119
|
+
cv.rectangle(mat, new cv.Point(label.x, label.y), new cv.Point(label.x + label.width, label.y + label.height), labelColor, 1);
|
|
120
|
+
cv.putText(mat, `L${label.id}`, new cv.Point(label.x + 1, Math.max(10, label.y - 2)), cv.FONT_HERSHEY_SIMPLEX, 0.32, labelText, 1);
|
|
59
121
|
}
|
|
60
122
|
const out = new PNG({ width: png.width, height: png.height });
|
|
61
123
|
out.data.set(mat.data);
|
|
62
124
|
mat.delete();
|
|
63
125
|
return PNG.sync.write(out);
|
|
64
126
|
}
|
|
127
|
+
function cropPngBuffer(pngBuffer, x, y, width, height) {
|
|
128
|
+
const png = PNG.sync.read(pngBuffer);
|
|
129
|
+
const sx = Math.max(0, Math.round(x));
|
|
130
|
+
const sy = Math.max(0, Math.round(y));
|
|
131
|
+
const sw = Math.max(1, Math.min(png.width - sx, Math.round(width)));
|
|
132
|
+
const sh = Math.max(1, Math.min(png.height - sy, Math.round(height)));
|
|
133
|
+
const out = new PNG({ width: sw, height: sh });
|
|
134
|
+
for (let row = 0; row < sh; row++) {
|
|
135
|
+
const src = ((sy + row) * png.width + sx) * 4;
|
|
136
|
+
out.data.set(png.data.subarray(src, src + sw * 4), row * sw * 4);
|
|
137
|
+
}
|
|
138
|
+
return PNG.sync.write(out);
|
|
139
|
+
}
|
|
140
|
+
function labelRoi(boxes, imgW, imgH) {
|
|
141
|
+
if (!boxes.length)
|
|
142
|
+
return { x: 0, y: 0, width: imgW, height: imgH };
|
|
143
|
+
const union = unionRects(boxes);
|
|
144
|
+
const x = Math.max(0, union.x - LABEL_PAD);
|
|
145
|
+
const y = Math.max(0, union.y - LABEL_PAD);
|
|
146
|
+
const right = Math.min(imgW, union.x + union.width + LABEL_PAD);
|
|
147
|
+
const bottom = Math.min(imgH, union.y + union.height + LABEL_PAD);
|
|
148
|
+
return { x, y, width: Math.max(1, right - x), height: Math.max(1, bottom - y) };
|
|
149
|
+
}
|
|
150
|
+
function scaleGrayPng(pngBuffer, scale) {
|
|
151
|
+
const cv = getCv();
|
|
152
|
+
const vision = new VisionUtil();
|
|
153
|
+
const color = vision.loadImage(pngBuffer);
|
|
154
|
+
const gray = vision.toGrayscale(color);
|
|
155
|
+
color.delete();
|
|
156
|
+
const scaled = new cv.Mat();
|
|
157
|
+
cv.resize(gray, scaled, new cv.Size(Math.max(1, gray.cols * scale), Math.max(1, gray.rows * scale)), 0, 0, cv.INTER_CUBIC);
|
|
158
|
+
gray.delete();
|
|
159
|
+
const buf = vision.matToBuffer(scaled);
|
|
160
|
+
scaled.delete();
|
|
161
|
+
return buf;
|
|
162
|
+
}
|
|
163
|
+
async function detectLabels(pngBuffer, boxes) {
|
|
164
|
+
const png = PNG.sync.read(pngBuffer);
|
|
165
|
+
const roi = labelRoi(boxes, png.width, png.height);
|
|
166
|
+
const cropped = cropPngBuffer(pngBuffer, roi.x, roi.y, roi.width, roi.height);
|
|
167
|
+
const scaled = scaleGrayPng(cropped, LABEL_SCALE);
|
|
168
|
+
const ocr = await getOCRUtil();
|
|
169
|
+
const words = await ocr.extractPageWords(scaled);
|
|
170
|
+
const mapped = words.map((word) => ({
|
|
171
|
+
...word,
|
|
172
|
+
x: word.x / LABEL_SCALE + roi.x,
|
|
173
|
+
y: word.y / LABEL_SCALE + roi.y,
|
|
174
|
+
width: word.width / LABEL_SCALE,
|
|
175
|
+
height: word.height / LABEL_SCALE,
|
|
176
|
+
}));
|
|
177
|
+
return labelsFromOcr(mapped, boxes);
|
|
178
|
+
}
|
|
179
|
+
function writeDetectFiles(dir, blank, meta, boxes, labels) {
|
|
180
|
+
const boxesPath = path.join(dir, 'boxes.json');
|
|
181
|
+
const annotatedPath = path.join(dir, 'boxes-annotated.png');
|
|
182
|
+
const payload = { width: meta.width, height: meta.height, boxes, labels };
|
|
183
|
+
fs.writeFileSync(boxesPath, `${JSON.stringify(payload, null, 2)}\n`);
|
|
184
|
+
fs.writeFileSync(annotatedPath, annotateBoxes(blank, boxes, labels));
|
|
185
|
+
return { boxesPath, annotatedPath };
|
|
186
|
+
}
|
|
65
187
|
/**
|
|
66
|
-
* Run OpenCV box detection on `{storage.root}/{name}/blank.png`.
|
|
188
|
+
* Run OpenCV box detection + OCR labels on `{storage.root}/{name}/blank.png`.
|
|
67
189
|
* Writes `boxes.json` and `boxes-annotated.png` next to the blank.
|
|
68
190
|
*/
|
|
69
191
|
export async function detectScreen(name) {
|
|
@@ -76,11 +198,49 @@ export async function detectScreen(name) {
|
|
|
76
198
|
const blank = fs.readFileSync(blankPath);
|
|
77
199
|
const meta = PNG.sync.read(blank);
|
|
78
200
|
const boxes = detectBoxes(blank);
|
|
201
|
+
const labels = await detectLabels(blank, boxes);
|
|
202
|
+
const { boxesPath, annotatedPath } = writeDetectFiles(dir, blank, meta, boxes, labels);
|
|
203
|
+
return { dir, boxesPath, annotatedPath, width: meta.width, height: meta.height, boxes, labels };
|
|
204
|
+
}
|
|
205
|
+
/** Persist boxes (including hand-drawn) and rewrite boxes-annotated.png. Keeps existing labels. */
|
|
206
|
+
export async function writeBoxes(name, boxes) {
|
|
207
|
+
await ensureCvReady();
|
|
208
|
+
const dir = screenDir(name);
|
|
209
|
+
const blankPath = path.join(dir, 'blank.png');
|
|
210
|
+
if (!fs.existsSync(blankPath)) {
|
|
211
|
+
throw new Error(`writeBoxes('${name}'): no blank.png at ${blankPath}`);
|
|
212
|
+
}
|
|
213
|
+
const blank = fs.readFileSync(blankPath);
|
|
214
|
+
const meta = PNG.sync.read(blank);
|
|
215
|
+
const clean = boxes
|
|
216
|
+
.map((box) => ({
|
|
217
|
+
id: Number(box.id),
|
|
218
|
+
x: Math.round(box.x),
|
|
219
|
+
y: Math.round(box.y),
|
|
220
|
+
width: Math.max(1, Math.round(box.width)),
|
|
221
|
+
height: Math.max(1, Math.round(box.height)),
|
|
222
|
+
}))
|
|
223
|
+
.sort((a, b) => a.id - b.id);
|
|
79
224
|
const boxesPath = path.join(dir, 'boxes.json');
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
225
|
+
let labels = [];
|
|
226
|
+
if (fs.existsSync(boxesPath)) {
|
|
227
|
+
try {
|
|
228
|
+
const prev = JSON.parse(fs.readFileSync(boxesPath, 'utf8'));
|
|
229
|
+
labels = prev.labels || [];
|
|
230
|
+
}
|
|
231
|
+
catch {
|
|
232
|
+
labels = [];
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
const written = writeDetectFiles(dir, blank, meta, clean, labels);
|
|
236
|
+
return {
|
|
237
|
+
dir,
|
|
238
|
+
boxesPath: written.boxesPath,
|
|
239
|
+
annotatedPath: written.annotatedPath,
|
|
240
|
+
width: meta.width,
|
|
241
|
+
height: meta.height,
|
|
242
|
+
boxes: clean,
|
|
243
|
+
labels,
|
|
244
|
+
};
|
|
85
245
|
}
|
|
86
246
|
//# sourceMappingURL=detect.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"detect.js","sourceRoot":"","sources":["../../src/author/detect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EA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C,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;KAC5C,CAAC,CAAC;SACF,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;IAC/B,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;IAC/C,IAAI,MAAM,GAAoB,EAAE,CAAC;IACjC,IAAI,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;QAC7B,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,SAAS,EAAE,MAAM,CAAC,CAAc,CAAC;YACzE,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,EAAE,CAAC;QAC7B,CAAC;QAAC,MAAM,CAAC;YACP,MAAM,GAAG,EAAE,CAAC;QACd,CAAC;IACH,CAAC;IACD,MAAM,OAAO,GAAG,gBAAgB,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;IAClE,OAAO;QACL,GAAG;QACH,SAAS,EAAE,OAAO,CAAC,SAAS;QAC5B,aAAa,EAAE,OAAO,CAAC,aAAa;QACpC,KAAK,EAAE,IAAI,CAAC,KAAK;QACjB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,KAAK,EAAE,KAAK;QACZ,MAAM;KACP,CAAC;AACJ,CAAC"}
|
|
@@ -7,9 +7,49 @@ export declare function unionRects(rects: Rect[]): Rect;
|
|
|
7
7
|
export declare function insetRect(rect: Rect, pad?: number): Rect;
|
|
8
8
|
/** Move a screen-space rect into the crop's coordinate system. */
|
|
9
9
|
export declare function relativeToCrop(rect: Rect, crop: Rect): Rect;
|
|
10
|
-
/**
|
|
10
|
+
/** Slice a rect by horizontal fractions in [0, 1]. */
|
|
11
|
+
export declare function sliceRectHorizontal(rect: Rect, start: number, end: number): Rect;
|
|
12
|
+
export declare function evenHorizontalSlices(rect: Rect, count: number): Rect[];
|
|
13
|
+
/** Bright column runs inside a merged field (cells vs `/` gutters). */
|
|
14
|
+
export declare function findAlignedCells(columnMeans: number[], count: number, minWidth?: number, bright?: number): Array<{
|
|
15
|
+
start: number;
|
|
16
|
+
end: number;
|
|
17
|
+
}> | null;
|
|
18
|
+
/** Bright cells in a row separated by dark gutters (dates, id + name). */
|
|
19
|
+
export declare function findCellRow(columnMeans: number[], minCount?: number, minWidth?: number, bright?: number): Array<{
|
|
20
|
+
start: number;
|
|
21
|
+
end: number;
|
|
22
|
+
}> | null;
|
|
23
|
+
/** Short mid-gray bands between bright rows (repeating row gutters). */
|
|
24
|
+
export declare function findHairlineDividers(rowMeans: number[], midLo?: number, midHi?: number, bright?: number): number[];
|
|
25
|
+
/** Slice a tall rect into rows when hairlines repeat. */
|
|
26
|
+
export declare function splitRowGutters(parent: Rect, rowMeans: number[]): Rect[] | null;
|
|
27
|
+
/** Split a rect on visible gutters: columns if short, rows if tall. */
|
|
28
|
+
export declare function splitBoxGutters(box: Rect, columnMeans: number[], rowMeans: number[]): Rect[] | null;
|
|
29
|
+
export declare function cellRunsToRects(parent: Rect, runs: Array<{
|
|
30
|
+
start: number;
|
|
31
|
+
end: number;
|
|
32
|
+
}>, inset?: number): Rect[];
|
|
33
|
+
/** Value box relative to the match crop. Dropdowns drop the spinner on the right. */
|
|
11
34
|
export declare function ocrRectFromBoxes(crop: Rect, fieldBoxes: Rect[], type?: string, pad?: number): Rect;
|
|
12
|
-
export declare function
|
|
35
|
+
export declare function includeLabelForType(type?: string, override?: boolean): boolean;
|
|
36
|
+
/** First in-form x walking left from the field — stop before window chrome. */
|
|
37
|
+
export declare function formLeftEdge(png: {
|
|
38
|
+
width: number;
|
|
39
|
+
height: number;
|
|
40
|
+
data: Buffer | Uint8Array;
|
|
41
|
+
}, rect: Rect, dark?: number): number | null;
|
|
42
|
+
/** Grow the crop left from the value box(es) to include the label. */
|
|
43
|
+
export declare function expandLeftForLabel(boxes: DetectedBox[], fieldBoxes: DetectedBox[], pad?: number, maxLabel?: number, png?: {
|
|
44
|
+
width: number;
|
|
45
|
+
height: number;
|
|
46
|
+
data: Buffer | Uint8Array;
|
|
47
|
+
}): Rect;
|
|
48
|
+
export declare function containedRatio(inner: Rect, outer: Rect): number;
|
|
49
|
+
/** Drop a container that already has inner cells. Keep the inners. */
|
|
50
|
+
export declare function splitMergedFields(boxes: Rect[], minKids?: number): Rect[];
|
|
51
|
+
/** Drop boxes that sit mostly inside a larger box (text scraps inside a button). */
|
|
52
|
+
export declare function dropNestedBoxes(boxes: Rect[], ratio?: number): Rect[];
|
|
13
53
|
export declare function dedupeBoxes(raw: Rect[]): Rect[];
|
|
14
54
|
export declare function numberBoxes(boxes: Rect[]): DetectedBox[];
|
|
15
55
|
//# sourceMappingURL=geometry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../../src/author/geometry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE/C,MAAM,WAAW,WAAY,SAAQ,IAAI;IACvC,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAM1C;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,IAAI,CAM9C;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,SAAI,GAAG,IAAI,CAOnD;AAED,kEAAkE;AAClE,wBAAgB,cAAc,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,GAAG,IAAI,CAO3D;AAED,qFAAqF;AACrF,wBAAgB,gBAAgB,CAC9B,IAAI,EAAE,IAAI,EACV,UAAU,EAAE,IAAI,EAAE,EAClB,IAAI,SAAU,EACd,GAAG,SAAI,G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,kBAAkB,CAChC,KAAK,EAAE,WAAW,EAAE,EACpB,UAAU,EAAE,WAAW,EAAE,EACzB,GAAG,SAAI,EACP,QAAQ,SAAM,EACd,GAAG,CAAC,EAAE;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,GAAG,UAAU,CAAA;CAAE,GACjE,IAAI,CAqBN;AAYD,wBAAgB,cAAc,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,GAAG,MAAM,CAG/D;AAED,sEAAsE;AACtE,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,OAAO,SAAI,GAAG,IAAI,EAAE,CAiCpE;AAED,oFAAoF;AACpF,wBAAgB,eAAe,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,KAAK,SAAM,GAAG,IAAI,EAAE,CAQlE;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,IAAI,EAAE,CAY/C;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,IAAI,EAAE,GAAG,WAAW,EAAE,CAExD"}
|
package/dist/author/geometry.js
CHANGED
|
@@ -29,7 +29,143 @@ export function relativeToCrop(rect, crop) {
|
|
|
29
29
|
height: rect.height,
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
-
/**
|
|
32
|
+
/** Slice a rect by horizontal fractions in [0, 1]. */
|
|
33
|
+
export function sliceRectHorizontal(rect, start, end) {
|
|
34
|
+
const left = rect.x + rect.width * start;
|
|
35
|
+
const right = rect.x + rect.width * end;
|
|
36
|
+
const x = Math.round(left);
|
|
37
|
+
return {
|
|
38
|
+
x,
|
|
39
|
+
y: rect.y,
|
|
40
|
+
width: Math.max(1, Math.round(right) - x),
|
|
41
|
+
height: rect.height,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export function evenHorizontalSlices(rect, count) {
|
|
45
|
+
const n = Math.max(1, count);
|
|
46
|
+
return Array.from({ length: n }, (_, i) => sliceRectHorizontal(rect, i / n, (i + 1) / n));
|
|
47
|
+
}
|
|
48
|
+
/** Bright column runs inside a merged field (cells vs `/` gutters). */
|
|
49
|
+
export function findAlignedCells(columnMeans, count, minWidth = 10, bright = 220) {
|
|
50
|
+
if (count < 2 || columnMeans.length < count * minWidth)
|
|
51
|
+
return null;
|
|
52
|
+
const runs = [];
|
|
53
|
+
let start = null;
|
|
54
|
+
for (let i = 0; i <= columnMeans.length; i++) {
|
|
55
|
+
const on = i < columnMeans.length && columnMeans[i] >= bright;
|
|
56
|
+
if (on && start == null)
|
|
57
|
+
start = i;
|
|
58
|
+
if (!on && start != null) {
|
|
59
|
+
if (i - start >= minWidth)
|
|
60
|
+
runs.push({ start, end: i });
|
|
61
|
+
start = null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
if (runs.length < count)
|
|
65
|
+
return null;
|
|
66
|
+
const picked = [...runs]
|
|
67
|
+
.sort((a, b) => b.end - b.start - (a.end - a.start))
|
|
68
|
+
.slice(0, count)
|
|
69
|
+
.sort((a, b) => a.start - b.start);
|
|
70
|
+
const widths = picked.map((run) => run.end - run.start);
|
|
71
|
+
const maxW = Math.max(...widths);
|
|
72
|
+
const minW = Math.min(...widths);
|
|
73
|
+
if (minW < 1 || maxW > minW * 3)
|
|
74
|
+
return null;
|
|
75
|
+
return picked;
|
|
76
|
+
}
|
|
77
|
+
/** Bright cells in a row separated by dark gutters (dates, id + name). */
|
|
78
|
+
export function findCellRow(columnMeans, minCount = 2, minWidth = 10, bright = 220) {
|
|
79
|
+
const runs = [];
|
|
80
|
+
let start = null;
|
|
81
|
+
for (let i = 0; i <= columnMeans.length; i++) {
|
|
82
|
+
const on = i < columnMeans.length && columnMeans[i] >= bright;
|
|
83
|
+
if (on && start == null)
|
|
84
|
+
start = i;
|
|
85
|
+
if (!on && start != null) {
|
|
86
|
+
if (i - start >= minWidth)
|
|
87
|
+
runs.push({ start, end: i });
|
|
88
|
+
start = null;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (runs.length < minCount || runs.length > 4)
|
|
92
|
+
return null;
|
|
93
|
+
return runs;
|
|
94
|
+
}
|
|
95
|
+
/** Short mid-gray bands between bright rows (repeating row gutters). */
|
|
96
|
+
export function findHairlineDividers(rowMeans, midLo = 190, midHi = 225, bright = 248) {
|
|
97
|
+
const lines = [];
|
|
98
|
+
let i = 0;
|
|
99
|
+
while (i < rowMeans.length) {
|
|
100
|
+
const value = rowMeans[i];
|
|
101
|
+
if (value >= midLo && value <= midHi) {
|
|
102
|
+
let j = i;
|
|
103
|
+
while (j < rowMeans.length && rowMeans[j] >= midLo && rowMeans[j] <= midHi)
|
|
104
|
+
j++;
|
|
105
|
+
const len = j - i;
|
|
106
|
+
const prevBright = i === 0 || rowMeans[i - 1] >= bright;
|
|
107
|
+
const nextBright = j >= rowMeans.length || rowMeans[j] >= bright;
|
|
108
|
+
if (len >= 2 && len <= 5 && prevBright && nextBright) {
|
|
109
|
+
lines.push(i + Math.floor(len / 2));
|
|
110
|
+
}
|
|
111
|
+
i = j;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
i++;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return lines;
|
|
118
|
+
}
|
|
119
|
+
/** Slice a tall rect into rows when hairlines repeat. */
|
|
120
|
+
export function splitRowGutters(parent, rowMeans) {
|
|
121
|
+
const lines = findHairlineDividers(rowMeans);
|
|
122
|
+
if (lines.length < 3)
|
|
123
|
+
return null;
|
|
124
|
+
const gaps = lines.slice(1).map((y, i) => y - lines[i]);
|
|
125
|
+
const median = [...gaps].sort((a, b) => a - b)[Math.floor(gaps.length / 2)];
|
|
126
|
+
if (median < 24 || median > 48)
|
|
127
|
+
return null;
|
|
128
|
+
if (gaps.some((gap) => gap < median * 0.75 || gap > median * 1.25))
|
|
129
|
+
return null;
|
|
130
|
+
const bounds = [0, ...lines, parent.height];
|
|
131
|
+
const rows = [];
|
|
132
|
+
for (let i = 0; i < bounds.length - 1; i++) {
|
|
133
|
+
const y0 = bounds[i];
|
|
134
|
+
const height = bounds[i + 1] - y0;
|
|
135
|
+
if (height < 16)
|
|
136
|
+
continue;
|
|
137
|
+
rows.push({ x: parent.x, y: parent.y + y0, width: parent.width, height });
|
|
138
|
+
}
|
|
139
|
+
return rows.length >= 4 ? rows : null;
|
|
140
|
+
}
|
|
141
|
+
/** Split a rect on visible gutters: columns if short, rows if tall. */
|
|
142
|
+
export function splitBoxGutters(box, columnMeans, rowMeans) {
|
|
143
|
+
if (box.height <= 28 && box.width >= 48) {
|
|
144
|
+
const runs = findCellRow(columnMeans);
|
|
145
|
+
const span = runs ? runs.reduce((sum, run) => sum + (run.end - run.start), 0) : 0;
|
|
146
|
+
if (runs && runs.length >= 2 && span >= box.width * 0.5) {
|
|
147
|
+
return runs.map((run) => {
|
|
148
|
+
const x = box.x + Math.max(0, run.start - 1);
|
|
149
|
+
const right = box.x + Math.min(box.width, run.end + 1);
|
|
150
|
+
return { x, y: box.y, width: Math.max(1, right - x), height: box.height };
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (box.height >= 80)
|
|
155
|
+
return splitRowGutters(box, rowMeans);
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
export function cellRunsToRects(parent, runs, inset = 2) {
|
|
159
|
+
const y = parent.y + inset;
|
|
160
|
+
const height = Math.max(1, parent.height - inset * 2);
|
|
161
|
+
return runs.map((run) => ({
|
|
162
|
+
x: parent.x + run.start,
|
|
163
|
+
y,
|
|
164
|
+
width: Math.max(1, run.end - run.start),
|
|
165
|
+
height,
|
|
166
|
+
}));
|
|
167
|
+
}
|
|
168
|
+
/** Value box relative to the match crop. Dropdowns drop the spinner on the right. */
|
|
33
169
|
export function ocrRectFromBoxes(crop, fieldBoxes, type = 'field', pad = 2) {
|
|
34
170
|
const union = unionRects(fieldBoxes);
|
|
35
171
|
const rightTrim = type === 'dropdown' ? 16 : 0;
|
|
@@ -40,14 +176,54 @@ export function ocrRectFromBoxes(crop, fieldBoxes, type = 'field', pad = 2) {
|
|
|
40
176
|
height: Math.max(1, union.height - pad * 2),
|
|
41
177
|
};
|
|
42
178
|
}
|
|
43
|
-
|
|
179
|
+
/** Types that used to grow left by default. Apply now unions labelIds; includeLabel: true is the leftover. */
|
|
180
|
+
const LABEL_CROP_TYPES = new Set(['field', 'dropdown']);
|
|
181
|
+
export function includeLabelForType(type, override) {
|
|
182
|
+
if (override != null)
|
|
183
|
+
return override;
|
|
184
|
+
return LABEL_CROP_TYPES.has(type || 'field');
|
|
185
|
+
}
|
|
186
|
+
function columnMean(png, x, y0, y1) {
|
|
187
|
+
const x0 = Math.round(x);
|
|
188
|
+
if (x0 < 0 || x0 >= png.width)
|
|
189
|
+
return 0;
|
|
190
|
+
const top = Math.max(0, Math.round(y0));
|
|
191
|
+
const bottom = Math.min(png.height, Math.round(y1));
|
|
192
|
+
const rows = Math.max(1, bottom - top);
|
|
193
|
+
let sum = 0;
|
|
194
|
+
for (let y = top; y < bottom; y++) {
|
|
195
|
+
const i = (y * png.width + x0) * 4;
|
|
196
|
+
sum += (png.data[i] + png.data[i + 1] + png.data[i + 2]) / 3;
|
|
197
|
+
}
|
|
198
|
+
return sum / rows;
|
|
199
|
+
}
|
|
200
|
+
/** First in-form x walking left from the field — stop before window chrome. */
|
|
201
|
+
export function formLeftEdge(png, rect, dark = 40) {
|
|
202
|
+
const y0 = rect.y + 2;
|
|
203
|
+
const y1 = rect.y + rect.height - 2;
|
|
204
|
+
const start = Math.min(png.width - 1, Math.max(0, Math.round(rect.x) - 1));
|
|
205
|
+
for (let x = start; x >= 0; x--) {
|
|
206
|
+
if (columnMean(png, x, y0, y1) < dark)
|
|
207
|
+
return x + 1;
|
|
208
|
+
}
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
/** Grow the crop left from the value box(es) to include the label. */
|
|
212
|
+
export function expandLeftForLabel(boxes, fieldBoxes, pad = 8, maxLabel = 140, png) {
|
|
44
213
|
const ids = new Set(fieldBoxes.map((box) => box.id));
|
|
45
214
|
const union = unionRects(fieldBoxes);
|
|
46
|
-
|
|
215
|
+
let leftLimit = union.x - maxLabel;
|
|
216
|
+
const neighbor = boxes
|
|
47
217
|
.filter((box) => !ids.has(box.id))
|
|
48
218
|
.filter((box) => box.x + box.width <= union.x + 2)
|
|
49
219
|
.filter((box) => box.y < union.y + union.height && box.y + box.height > union.y)
|
|
50
|
-
.reduce((max, box) => Math.max(max, box.x + box.width),
|
|
220
|
+
.reduce((max, box) => Math.max(max, box.x + box.width), leftLimit);
|
|
221
|
+
leftLimit = Math.max(leftLimit, neighbor);
|
|
222
|
+
if (png) {
|
|
223
|
+
const edge = formLeftEdge(png, union);
|
|
224
|
+
if (edge != null)
|
|
225
|
+
leftLimit = Math.max(leftLimit, edge);
|
|
226
|
+
}
|
|
51
227
|
const x = Math.max(0, Math.min(union.x - pad, Math.max(leftLimit + 4, union.x - maxLabel)));
|
|
52
228
|
return {
|
|
53
229
|
x,
|
|
@@ -64,6 +240,63 @@ function overlapArea(a, b) {
|
|
|
64
240
|
function score(box) {
|
|
65
241
|
return -Math.abs(box.height - 18) * 10 + box.width * 0.01;
|
|
66
242
|
}
|
|
243
|
+
export function containedRatio(inner, outer) {
|
|
244
|
+
const area = inner.width * inner.height;
|
|
245
|
+
return area ? overlapArea(inner, outer) / area : 0;
|
|
246
|
+
}
|
|
247
|
+
/** Drop a container that already has inner cells. Keep the inners. */
|
|
248
|
+
export function splitMergedFields(boxes, minKids = 2) {
|
|
249
|
+
const parents = boxes.filter((parent) => {
|
|
250
|
+
const kids = boxes.filter((box) => box !== parent && containedRatio(box, parent) >= 0.7);
|
|
251
|
+
if (kids.length < minKids || kids.length > 24)
|
|
252
|
+
return false;
|
|
253
|
+
const fieldKids = kids.filter((box) => box.height >= 12 && box.height <= 28 && box.width >= 14);
|
|
254
|
+
if (parent.height <= 50 && parent.width >= parent.height * 8 && fieldKids.length >= 2)
|
|
255
|
+
return true;
|
|
256
|
+
const parentArea = parent.width * parent.height;
|
|
257
|
+
const kidArea = kids.reduce((sum, box) => sum + box.width * box.height, 0);
|
|
258
|
+
const maxKid = Math.max(...kids.map((box) => box.width * box.height));
|
|
259
|
+
if (maxKid > parentArea * 0.85)
|
|
260
|
+
return false;
|
|
261
|
+
if (kidArea < parentArea * 0.35)
|
|
262
|
+
return false;
|
|
263
|
+
const union = unionRects(kids);
|
|
264
|
+
return union.width >= parent.width * 0.5 || union.height >= parent.height * 0.5;
|
|
265
|
+
});
|
|
266
|
+
if (!parents.length)
|
|
267
|
+
return boxes;
|
|
268
|
+
const out = [];
|
|
269
|
+
for (const box of boxes) {
|
|
270
|
+
if (parents.includes(box))
|
|
271
|
+
continue;
|
|
272
|
+
const parent = parents.find((p) => containedRatio(box, p) >= 0.7);
|
|
273
|
+
if (parent) {
|
|
274
|
+
const padX = Math.min(2, Math.max(0, box.x - parent.x));
|
|
275
|
+
const padY = Math.min(2, Math.max(0, box.y - parent.y));
|
|
276
|
+
out.push({
|
|
277
|
+
x: box.x - padX,
|
|
278
|
+
y: box.y - padY,
|
|
279
|
+
width: box.width + padX * 2,
|
|
280
|
+
height: box.height + padY * 2,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
out.push(box);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return out;
|
|
288
|
+
}
|
|
289
|
+
/** Drop boxes that sit mostly inside a larger box (text scraps inside a button). */
|
|
290
|
+
export function dropNestedBoxes(boxes, ratio = 0.7) {
|
|
291
|
+
const sorted = [...boxes].sort((a, b) => b.width * b.height - a.width * a.height);
|
|
292
|
+
const kept = [];
|
|
293
|
+
for (const box of sorted) {
|
|
294
|
+
if (kept.some((outer) => containedRatio(box, outer) >= ratio))
|
|
295
|
+
continue;
|
|
296
|
+
kept.push(box);
|
|
297
|
+
}
|
|
298
|
+
return kept.sort((a, b) => a.y - b.y || a.x - b.x);
|
|
299
|
+
}
|
|
67
300
|
export function dedupeBoxes(raw) {
|
|
68
301
|
const sorted = [...raw].sort((a, b) => score(b) - score(a));
|
|
69
302
|
const kept = [];
|