搜索插件、代码仓与 APP 分类

ocr_scan_text 封面
插件详情v1.3.1

ocr_scan_text

OCR 扫描文本是 "Google ML Kit 文本识别" 库的包装器。

AndroidiOS
近 30 天下载
48
喜欢数
38
Pub 分数
125

安装插件

flutter pub add ocr_scan_text

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

OCR Scan Text 是一个 Flutter 包,封装了 Google ML Kit 文本识别库,使开发者能够从通过相机拍摄或从设备相册中选择的图像中提取文本。它提供准确且快速的文本检测功能,支持多种语言和手写体识别。该包简化了将高级 OCR 功能集成到移动应用中的过程,无需深入了解底层机器学习框架。专为 Android 和 iOS 构建,确保跨平台文本扫描功能的一致性。

适合场景

  • 从文档中提取文本
  • 扫描名片
  • 阅读手写笔记
  • 从截图中捕获文本
  • 自动化数据录入

主要特点

  • 实时文本识别
  • 对多种语言的支持
  • 手写检测
  • 相机集成
  • 离线操作

适合对象

  • 文档扫描应用
  • 记事工具
  • 数据录入自动化
  • 无障碍功能
  • 移动库存系统

使用建议

  • 需要相机权限
  • 性能因设备而异
  • 使用清晰的图像效果最佳
  • 仅限文本识别
  • 可能需要对低质量输入进行图像预处理

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Flutter OCR Scan Text

OCR Flutter v1.3.1

Flutter OCR Scan Text is a wrapper around the "Google ML kit Text Recognition" library. It helps to facilitate accurate text search and display of results from the camera. It also allows to manage text searches from an image or a pdf.

Features

Allows you to easily scan text from the camera, extract accurate results and display them to the user.

The results are returned by list of Block.

  • A Block contains: the global text of the block, a list of Lines and the position.
  • A Line contains: the global text of the line, a list of Elements and the position.
  • An Element contains: a word and the position.

Note: The library uses the Camera package, be sure to ask for permission.

Usage

Add package in pubspec.yaml :
dependencies:
ocr_scan_text: 1.3.1
To use the library, import :
import 'package:ocr_scan_text/ocr_scan_text.dart';
To display the text detection widget with camera:
 LiveScanWidget(ocrTextResult: (ocrTextResult) {}, scanModules: [ScanAllModule()],)

A LiveScanWidget needs a module list to start detection. Validated results will be returned to the "matchedResult" method.

Create a scan module :

In this example (see the /example folder), we consider all Elements to be results.

Create a scan module :

class ScanAllModule extends ScanModule

The constructor of a module:

  • label: A label (optional) that will be displayed to the user during rendering
  • color: A color (optional) that will be used for rendering
  • validateCountCorrelation: The number of times the same result must be found in the same place for it to be valid. (As the camera moves certain numbers / letters may be misinterpreted over several frames).
ScanAllModule() : super(label: 'All',color: Colors.redAccent.withOpacity(0.3), validateCountCorrelation: 1);

The purpose of a module is to search among the Blocks for a list of results (ScanResult) and to return it using the "matchedResult" method.

@override
Future<List<ScanResult>> matchedResult(List<TextBlock> textBlock, String text) async {
 List<ScanResult> list = [];
 for (var block in textBlock) {
  for (var line in block.lines) {
   for (var element in line.elements) {
    list.add(ScanResult(cleanedText: element.text, scannedElementList: [element]));
   }
  }
 }
 return list;
}
Start a module :
module.start();
Stop a module :
module.stop();

Scan file with Widget (Supported extension : png, jpg and pdf )

StaticScanWidget(ocrTextResult: (ocrTextResult) {}, scanModules: [ScanAllModule()], file: File("path/image.png"));

Scan file without Widget (Supported extension : png, jpg and pdf )

This method open gallery for pick a pics and start text analyze. ( /!\ verify permissions before )

OcrScanService([module]).startScanWithPhoto();

This method open file folder for pick a file and start text analyze. ( /!\ verify permissions before )

OcrScanService([module]).startScanWithOpenFile();

This method start text analyze

OcrScanService([module]).startScanProcess(File('path/image.png'));

Helper

You can use TextBlockHelper methods to help find results.

  • TextBlockHelper.extractTextElementsWithRegex : Find the list of elements that match with the regex

  • TextBlockHelper.nextTextElement : Find the next TextElement a right or left of TextElement

  • TextBlockHelper.combineRecreateTextLine : When texts are on the same line but distant, MLKit can create two different TextBlock. The "combineRecreateTextLine" method will create a TextLine, from a starting TextElement, taking into account the Elements of each TextBlock

  • TextBlockHelper.combineLeftTextElement : Return a List of TextElement with all TextElement to the left of startElement including startElement.

  • TextBlockHelper.combineRightTextElement : Return a List of TextElement with all TextElement to the right of startElement including startElement.

  • TextBlockHelper.combineBetweenTextElement : Return a List of TextElement between startElement and endElement

所属分类

依赖

依赖清单 9 项

源码仓库

使用此插件的项目

暂无相关数据。