|
| 1 | +# Flutter Document Capture |
| 2 | + |
| 3 | +A Flutter FFI plugin for real-time document capture preprocessing. Uses OpenCV for image processing on mobile devices (Edge AI) to optimize input quality for downstream OCR and layout detection. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Document Detection** - OpenCV-based corner detection using Canny + findContours |
| 8 | +- **Quality Assessment** - Blur, brightness, and stability scoring |
| 9 | +- **Perspective Correction** - Transform skewed documents to rectangular |
| 10 | +- **Image Enhancement** - Multiple enhancement modes for OCR optimization |
| 11 | +- **Auto-capture Trigger** - Automatic capture when quality thresholds are met |
| 12 | + |
| 13 | +## Screenshot |
| 14 | + |
| 15 | + |
| 16 | + |
| 17 | +## Demo |
| 18 | + |
| 19 | +### A/B Test |
| 20 | +Real-time comparison between instant capture and processed results. |
| 21 | + |
| 22 | +<!-- TODO: Add demo video --> |
| 23 | + |
| 24 | +### Batch Test |
| 25 | +Compare recognition accuracy with preprocessing ON vs OFF. |
| 26 | + |
| 27 | +<!-- TODO: Add demo video --> |
| 28 | + |
| 29 | +## Results |
| 30 | + |
| 31 | +Preprocessing significantly improves OCR recognition accuracy and stability. |
| 32 | + |
| 33 | +| Mode | Avg Score | Success Rate | |
| 34 | +|------|-----------|--------------| |
| 35 | +| OFF | --% | --% | |
| 36 | +| ON | --% | --% | |
| 37 | + |
| 38 | +## Why Use This Package? |
| 39 | + |
| 40 | +| Benefit | Description | |
| 41 | +|---------|-------------| |
| 42 | +| **Higher Accuracy** | Preprocessing improves OCR recognition rate | |
| 43 | +| **Better Stability** | Multi-frame buffering selects the best result | |
| 44 | +| **Faster Valid Results** | Reduces time to obtain valid recognition | |
| 45 | + |
| 46 | +> **Note:** Single-frame processing time is not faster (due to preprocessing + multi-frame buffer), but overall time to get valid results is reduced. |
| 47 | +
|
| 48 | +## Installation |
| 49 | + |
| 50 | +Add to your `pubspec.yaml`: |
| 51 | + |
| 52 | +```yaml |
| 53 | +dependencies: |
| 54 | + flutter_document_capture: |
| 55 | + git: |
| 56 | + url: https://github.com/robert008/flutter_document_capture.git |
| 57 | +``` |
| 58 | +
|
| 59 | +## Usage |
| 60 | +
|
| 61 | +### Basic Setup |
| 62 | +
|
| 63 | +```dart |
| 64 | +import 'package:flutter_document_capture/flutter_document_capture.dart'; |
| 65 | + |
| 66 | +// Initialize engine |
| 67 | +final engine = DocumentCaptureEngine(); |
| 68 | + |
| 69 | +// Analyze frame quality |
| 70 | +final analysis = engine.analyzeFrame( |
| 71 | + imageBytes, |
| 72 | + width, |
| 73 | + height, |
| 74 | + format: 2, // RGB |
| 75 | +); |
| 76 | + |
| 77 | +// Check if ready for capture |
| 78 | +if (analysis.captureReady) { |
| 79 | + // Capture and enhance |
| 80 | + final result = engine.enhanceImageWithGuideFrame( |
| 81 | + imageBytes, |
| 82 | + width, |
| 83 | + height, |
| 84 | + guideLeft, |
| 85 | + guideTop, |
| 86 | + guideRight, |
| 87 | + guideBottom, |
| 88 | + enhanceMode: EnhanceMode.contrastStretch, |
| 89 | + ); |
| 90 | +} |
| 91 | + |
| 92 | +// Cleanup |
| 93 | +engine.dispose(); |
| 94 | +``` |
| 95 | + |
| 96 | +### Enhancement Modes |
| 97 | + |
| 98 | +```dart |
| 99 | +enum EnhanceMode { |
| 100 | + none, // No enhancement |
| 101 | + whitenBg, // Background whitening |
| 102 | + contrastStretch, // Contrast stretching (recommended) |
| 103 | + adaptiveBinarize, // Adaptive binarization |
| 104 | + sauvola, // Sauvola binarization |
| 105 | +} |
| 106 | +``` |
| 107 | + |
| 108 | +### Frame Analysis Result |
| 109 | + |
| 110 | +```dart |
| 111 | +class FrameAnalysisResult { |
| 112 | + bool documentFound; // Document corners detected |
| 113 | + bool tableFound; // Table region detected |
| 114 | + bool textRegionFound; // Text regions detected |
| 115 | + double blurScore; // 0.0 - 1.0 (higher = sharper) |
| 116 | + double brightnessScore; // 0.0 - 1.0 |
| 117 | + double stabilityScore; // 0.0 - 1.0 |
| 118 | + double cornerConfidence; // 0.0 - 1.0 |
| 119 | + bool captureReady; // All thresholds met |
| 120 | + List<double> corners; // 8 values: [x0,y0,x1,y1,x2,y2,x3,y3] |
| 121 | +} |
| 122 | +``` |
| 123 | + |
| 124 | +## Requirements |
| 125 | + |
| 126 | +- Flutter 3.0+ |
| 127 | +- iOS 12.0+ / Android API 21+ |
| 128 | +- OpenCV (bundled) |
| 129 | + |
| 130 | +## Related Projects |
| 131 | + |
| 132 | +- [flutter_ocr_kit](https://github.com/robert008/flutter_ocr_kit) - OCR + Layout Detection |
| 133 | + |
| 134 | +## License |
| 135 | + |
| 136 | +MIT License - see [LICENSE](LICENSE) for details. |
0 commit comments