搜尋套件、儲存庫與 APP 分類

flutter_tesseract_ocr 封面
套件詳情v0.4.31

flutter_tesseract_ocr

Tesseract 4 加入了一個基於神經網路(LSTM)的新OCR引擎,專注於行識別。它支援Unicode(UTF-8),可辨識超過100種語言。

AndroidiOSWeb
近 30 天下載
7910
喜歡數
216
Pub 分數
130

安裝套件

flutter pub add flutter_tesseract_ocr

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

Flutter Tesseract OCR 是一個 Flutter 插件,整合了 Tesseract 4 的先進神經網絡(LSTM)基底 OCR 引擎,可準確從影像中識別超過 100 種語言的文字。它支援 Unicode(UTF-8),非常適合多語系應用程式。此插件可在 Android、iOS 與 Web 平台運作,為開發者提供可靠的文件掃描與文字擷取解決方案。

適用情境

  • 移動應用中的文件掃描
  • 從圖像中提取文字
  • 多語言文本識別
  • 自動表單數據捕獲
  • 基於圖像的搜尋功能

主要特色

  • 基於LSTM的OCR引擎
  • 支援100多種語言
  • Unicode (UTF-8) 文本輸出
  • 跨平台相容性
  • 高精度的行級識別

適合對象

  • 需要OCR的移動應用
  • 文件管理工具
  • 語言無關的文本提取
  • Web 和移動混合專案
  • 具有圖像到文字工作流程的應用程式

使用建議

  • 需要圖像預處理以獲得最佳效果
  • 性能在低階設備上可能會有所不同
  • 非預設語言所需的額外設定
  • 有限的離線支援,不含內建模型
  • 模型大小影響應用程式封裝大小

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Tesseract OCR for Flutter

Fork note (onestudi0/tesseract_ocr): This fork exists solely to fix android/build.gradle, which still declares the defunct jcenter() repository — current Gradle rejects the jcenter() DSL method outright, so upstream fails to build at all as of this writing. This fork replaces it with mavenCentral(). No other changes. If upstream (khjde1207/tesseract_ocr) ever merges an equivalent fix, switch back to the pub.dev release and drop the dependency_overrides pointing here.

Tesseract OCR 4.0 for flutter This plugin is based on Tesseract OCR 4 This plugin uses Tesseract4Android and SwiftyTesseract.

pub.dev link


https://pub.dev/packages/google_ml_kit

Tesseract is slower than ml_kit.

Consider whether you should use Tesseract


example

install


dev_dependencies:
  ...
  flutter_tesseract_ocr:

web

./web/index.html

use https://www.npmjs.com/package/tesseract.js/v/v4.0.2

<body>
  <script src='https://unpkg.com/tesseract.js@v4.0.2/dist/tesseract.min.js'></script>
  <script>
    async function _extractText(imagePath , mapData){
      var worker = await Tesseract.createWorker();
      await worker.load();
      await worker.loadLanguage(mapData.language)
      await worker.initialize(mapData.language)
      await worker.setParameters(mapData.args)
      var rtn = await worker.recognize(imagePath, {}, worker.id);
      await worker.terminate();
      if(mapData.args["tessjs_create_hocr"]){
        return rtn.data.hocr;
      }
      return rtn.data.text;
    }
  </script>
  ...
  ..
  .
</body>

Getting Started (Android / Ios)

You must add trained data and trained data config file to your assets directory. You can find additional language trained data files here Trained language files

add tessdata folder under assets folder, add tessdata_config.json file under assets folder:

{
  "files": [
    "eng.traineddata",
    "<other_language>.traineddata"
  ]
}

Plugin assumes you have tessdata folder in your assets directory and defined in your pubspec.yaml

Check the contents of example/assets folder and example/pubspec.yaml


IOS issues

Initialization of SwiftyTesseract has failed

Just drag tessdata folder from asset to place under Runner folder in xcode add as a reference then it will work.

Reference


Usage

Using is very simple:

//args support android / Web , i don't have a mac
String text = await FlutterTesseractOcr.extractText('/path/to/image', language: 'kor+eng',
        args: {
          "psm": "4",
          "preserve_interword_spaces": "1",
        });

You can leave language empty, it will default to `'eng'.

//---- dynamic add Tessdata (Android)---- ▼
// https://github.com/tesseract-ocr/tessdata/raw/main/dan_frak.traineddata

HttpClient httpClient = new HttpClient();

HttpClientRequest request = await httpClient.getUrl(Uri.parse(
        'https://github.com/tesseract-ocr/tessdata/raw/main/${langName}.traineddata'));

HttpClientResponse response = await request.close();
Uint8List bytes =await consolidateHttpClientResponseBytes(response);
String dir = await FlutterTesseractOcr.getTessdataPath();

print('$dir/${langName}.traineddata');
File file = new File('$dir/${langName}.traineddata');
await file.writeAsBytes(bytes);
//---- dynamic add Tessdata ---- ▲

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案