improve parsing 3
This commit is contained in:
@@ -16,15 +16,17 @@ class ReceiptOcr {
|
||||
required double imageHeight,
|
||||
}) {
|
||||
final elements = <OcrElement>[];
|
||||
final lines = <OcrLine>[];
|
||||
var maxRight = 0.0;
|
||||
var maxBottom = 0.0;
|
||||
|
||||
for (final block in recognized.blocks) {
|
||||
for (final line in block.lines) {
|
||||
final lineElements = <OcrElement>[];
|
||||
if (line.elements.isNotEmpty) {
|
||||
for (final element in line.elements) {
|
||||
final box = element.boundingBox;
|
||||
elements.add(
|
||||
lineElements.add(
|
||||
OcrElement(
|
||||
text: element.text,
|
||||
left: box.left,
|
||||
@@ -38,7 +40,7 @@ class ReceiptOcr {
|
||||
}
|
||||
} else {
|
||||
final box = line.boundingBox;
|
||||
elements.add(
|
||||
lineElements.add(
|
||||
OcrElement(
|
||||
text: line.text,
|
||||
left: box.left,
|
||||
@@ -50,6 +52,18 @@ class ReceiptOcr {
|
||||
if (box.right > maxRight) maxRight = box.right;
|
||||
if (box.bottom > maxBottom) maxBottom = box.bottom;
|
||||
}
|
||||
elements.addAll(lineElements);
|
||||
final box = line.boundingBox;
|
||||
lines.add(
|
||||
OcrLine(
|
||||
text: line.text,
|
||||
elements: lineElements,
|
||||
left: box.left,
|
||||
top: box.top,
|
||||
right: box.right,
|
||||
bottom: box.bottom,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +72,7 @@ class ReceiptOcr {
|
||||
|
||||
return OcrDocument(
|
||||
elements: elements,
|
||||
lines: lines,
|
||||
imageWidth: width,
|
||||
imageHeight: height,
|
||||
flattenedText: recognized.text.trim(),
|
||||
|
||||
Reference in New Issue
Block a user