Document local setup and OCR workflow
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
export function rectFromPoints(start, end) {
|
||||
return {
|
||||
x: Math.round(Math.min(start.x, end.x)),
|
||||
y: Math.round(Math.min(start.y, end.y)),
|
||||
width: Math.round(Math.abs(end.x - start.x)),
|
||||
height: Math.round(Math.abs(end.y - start.y)),
|
||||
};
|
||||
}
|
||||
|
||||
export function resolveFieldRect(anchorPosition, field) {
|
||||
return {
|
||||
x: Math.round(anchorPosition.x + field.offsetX),
|
||||
y: Math.round(anchorPosition.y + field.offsetY),
|
||||
width: Math.round(field.width),
|
||||
height: Math.round(field.height),
|
||||
};
|
||||
}
|
||||
|
||||
export function normalizeOcrText(text) {
|
||||
return text.replace(/\s+/g, " ").trim();
|
||||
}
|
||||
|
||||
export function parseFieldValue(type, text) {
|
||||
const normalized = normalizeOcrText(text);
|
||||
|
||||
if (type !== "price" && type !== "quantity") {
|
||||
return normalized;
|
||||
}
|
||||
|
||||
const digits = normalized.replace(/\D/g, "");
|
||||
return digits ? Number(digits) : null;
|
||||
}
|
||||
|
||||
export function isCalibrationReady(calibration) {
|
||||
return Boolean(
|
||||
calibration?.anchor?.image &&
|
||||
calibration.anchor.width >= 4 &&
|
||||
calibration.anchor.height >= 4 &&
|
||||
calibration.fields?.length,
|
||||
);
|
||||
}
|
||||
|
||||
export function isRectInside(rect, width, height) {
|
||||
return (
|
||||
rect.x >= 0 &&
|
||||
rect.y >= 0 &&
|
||||
rect.width > 0 &&
|
||||
rect.height > 0 &&
|
||||
rect.x + rect.width <= width &&
|
||||
rect.y + rect.height <= height
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user