document_scan 0.1.1
document_scan: ^0.1.1 copied to clipboard
Composable, native-light document scanner for Flutter: document corner detection plus perspective correction, for both live camera frames and still images.
0.1.1 #
DocumentProcessor.pagesToPdf(List<ScannedDocument>)— combine several scanned pages into one multi-page PDF (one A4 page per scan, in order). The multi-page counterpart tooutput: ScanOutputFormat.pdf; pass the pages you collected in aScanSession. Each page's bytes are embedded as-is (no re-encode); returns null for an empty list.
0.1.0 #
Initial release.
DocumentScanner— one-call scanning:scan(input)detects and crops; passcorners:to skip detection and crop user-adjusted corners instead.DocumentDetector— document corner detection for still images (detect) and live camera frames (detectStream), backed by Apple Vision on iOS and OpenCV on Android, with per-frame downscaling for realtime performance.detectStreamemits a sealedDetectionEvent(DetectionSuccess/DetectionEmpty/DetectionSkipped/DetectionError) so a consumer can tell an empty scene from a backpressure drop from a native error, rather than a blindnull. Corners carry aconfidence(engine value on iOS, geometric heuristic on Android).CornerStabilizer— optional EMA smoothing for the live corner stream, so an overlay drawn fromdetectStream(stabilize: ...)stays steady instead of jittering; snaps rather than slides when the document jumps.DocumentProcessor— pure-Dart perspective correction (crop) withgrayscale,enhance,blackWhite,sharpen, and adaptivemagicColorfilters. Output as PNG, JPEG, or a single-page PDF viaScanOutputFormat. Undecodable input (and a degenerate/1px warp) returnsnullrather than throwing.AutoCaptureAnalyzer— pure-Dart stream analyzer that signals when a document has been held steady and confident long enough to auto-capture. Pipe the detector straight in withbindEvents(detectStream(...))(orbindCorners/addEventfor finer control) — the event distinctions are preserved.DocumentProcessor.cropcaps the warp output's long side atmaxDimension(default 2000px, aspect-preserving; passnullto warp at full resolution) so a near-full-frame high-megapixel photo doesn't produce a needlessly huge scan.- Off-UI-thread crop:
crop/applyFiltertake abackgroundflag (defaultfalse) that runs the pure-Dart warp+filter on a background isolate; theDocumentScanner.scanfaçade defaults it totrue, so the simple path never janks the UI without the caller reaching forIsolate.run. ScanSession— an immutable multi-page container (add / reorder / remove).- Plugin-free value types with value equality:
ScanInput(with format-specificbgraFrame/yuvFrameframe factories),DocumentCorners(geometry-ordered corners + confidence),ScannedDocument,ScanFilter,ScanOutputFormat(png/jpeg/pdfconstants, plusjpegAt(quality)). - Example app with four flows: gallery scan, realtime overlay (detectStream +
CornerStabilizer + AutoCaptureAnalyzer over a live camera), manual corner
edit (drag-adjust → crop with
corners:), and reprocess (detect once, swap filters live). PlainStatefulWidget, no state-management dependency.