62 lines
1.4 KiB
Dart
62 lines
1.4 KiB
Dart
/// One OCR text fragment with pixel bounding box on the receipt image.
|
|
library;
|
|
|
|
class OcrElement {
|
|
const OcrElement({
|
|
required this.text,
|
|
required this.left,
|
|
required this.top,
|
|
required this.right,
|
|
required this.bottom,
|
|
});
|
|
|
|
final String text;
|
|
final double left;
|
|
final double top;
|
|
final double right;
|
|
final double bottom;
|
|
|
|
double get centerX => (left + right) / 2;
|
|
double get centerY => (top + bottom) / 2;
|
|
double get height => (bottom - top).abs();
|
|
double get width => (right - left).abs();
|
|
}
|
|
|
|
/// One ML Kit text line with its word-level elements.
|
|
class OcrLine {
|
|
const OcrLine({
|
|
required this.text,
|
|
required this.elements,
|
|
required this.left,
|
|
required this.top,
|
|
required this.right,
|
|
required this.bottom,
|
|
});
|
|
|
|
final String text;
|
|
final List<OcrElement> elements;
|
|
final double left;
|
|
final double top;
|
|
final double right;
|
|
final double bottom;
|
|
|
|
double get centerY => (top + bottom) / 2;
|
|
}
|
|
|
|
/// All positioned elements from one ML Kit recognition pass.
|
|
class OcrDocument {
|
|
const OcrDocument({
|
|
required this.elements,
|
|
required this.lines,
|
|
required this.imageWidth,
|
|
required this.imageHeight,
|
|
required this.flattenedText,
|
|
});
|
|
|
|
final List<OcrElement> elements;
|
|
final List<OcrLine> lines;
|
|
final double imageWidth;
|
|
final double imageHeight;
|
|
final String flattenedText;
|
|
}
|