ocr_stabilizer 0.2.1 copy "ocr_stabilizer: ^0.2.1" to clipboard
ocr_stabilizer: ^0.2.1 copied to clipboard

Real-time OCR overlay stabilization engine — drift correction, spatial indexing, block tracking. Built for Flutter.

example/example.dart

// ignore_for_file: avoid_print

import 'dart:ui';

import 'package:ocr_stabilizer/ocr_stabilizer.dart';

/// Minimal example: stabilize two batches of OCR observations using
/// [DefaultTrackedBlock] as the block implementation.
void main() {
  final engine = StabilizationEngine<DefaultTrackedBlock<void>, void>(
    merger: (existing, fresh, merge) => existing.applyMerge(merge),
  );

  // First capture: two text blocks observed.
  final batch1 = [
    _block(text: 'Hello world', left: 10, top: 100, width: 200, height: 30),
    _block(text: 'Goodbye', left: 10, top: 150, width: 150, height: 30),
  ];
  final result1 = engine.stabilize(batch1);
  print('Capture 1: ${result1.stableBlocks.length} stable blocks');

  // Caller contract: rebuild the spatial index after each stabilize call
  // (see StabilizationEngine.stabilize docstring). `rebuild` replaces the
  // index atomically; using `add` in a real capture loop without removing
  // prior versions would accumulate stale blocks.
  engine.spatialIndex.rebuild(result1.stableBlocks);

  // Second capture: same text at slightly different positions (OCR jitter).
  final batch2 = [
    _block(text: 'Hello world', left: 12, top: 102, width: 200, height: 30),
    _block(text: 'Goodbye', left: 11, top: 149, width: 150, height: 30),
  ];
  final result2 = engine.stabilize(batch2);
  print('Capture 2: ${result2.stableBlocks.length} stable blocks');

  for (final block in result2.stableBlocks) {
    print(
      '  "${block.originalText}" at '
      '(${block.absoluteRect.left.toStringAsFixed(1)}, '
      '${block.absoluteRect.top.toStringAsFixed(1)}) '
      'observations=${block.observationCount}',
    );
  }
}

DefaultTrackedBlock<void> _block({
  required String text,
  required double left,
  required double top,
  required double width,
  required double height,
}) {
  return DefaultTrackedBlock<void>(
    absoluteRect: AbsoluteRect(Rect.fromLTWH(left, top, width, height)),
    payload: null,
    originalText: text,
  );
}
0
likes
160
points
794
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Real-time OCR overlay stabilization engine — drift correction, spatial indexing, block tracking. Built for Flutter.

Repository (GitHub)
View/report issues

Topics

#ocr #overlay #tracking #slam #flutter

License

MIT (license)

Dependencies

flutter

More

Packages that depend on ocr_stabilizer