tesseract_ocr 0.3.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 88

Tesseract OCR for Flutter #

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

Getting Started #

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 tess_data.config.json file under assets folder.

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

0.1.0 #

  • Extract Text from images, Especially helpful when you are extracting single character images.

0.1.1 #

  • fixed path references

0.1.2 #

  • added description

0.1.2+1 #

  • fixed typo

0.1.2+2 #

  • fixed description

0.1.2+3 #

  • added LICENSE

0.1.3 #

  • updated swift version to 4.2

0.2.0 #

  • fixed dependecies

0.2.1 #

  • fixed swift version

0.2.2 #

  • set target swift version to 4.2

0.3.0 #

  • added language support you can pass the language as an optional parameter. TesseractOcr.extractText(imagePath, language: "financial"); if not set it will default to "eng". language must match the name of .traineddata file

example/lib/main.dart

import 'dart:io';
import 'dart:typed_data';

import 'package:flutter/services.dart';
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';

import 'package:flutter/material.dart';
import 'dart:async';

import 'package:tesseract_ocr/tesseract_ocr.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _extractText = 'Unknown';

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String extractText;
    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      final Directory directory = await getTemporaryDirectory();
      final String imagePath = join(
        directory.path,
        "tmp_1.jpg",
      );
      final ByteData data = await rootBundle.load('packages/tesseract_ocr/images/test.png');
      final Uint8List bytes = data.buffer.asUint8List(
        data.offsetInBytes,
        data.lengthInBytes,
      );
      await File(imagePath).writeAsBytes(bytes);

      extractText = await TesseractOcr.extractText(imagePath, language: "financial");
    } on PlatformException {
      extractText = 'Failed to extract text';
    }

    // If the widget was removed from the tree while the asynchronous platform
    // message was in flight, we want to discard the reply rather than calling
    // setState to update our non-existent appearance.
    if (!mounted) return;

    setState(() {
      _extractText = extractText;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
          appBar: AppBar(
            title: const Text('Tesseract OCR'),
          ),
          body: Column(
            children: <Widget>[
              Center(
                child: Text('Detected Text: $_extractText\n'),
              ),
              Image.asset('images/test.png', package: 'tesseract_ocr', height: 30.0),
            ],
          )),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  tesseract_ocr: ^0.3.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:tesseract_ocr/tesseract_ocr.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
77
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
88
Learn more about scoring.

We analyzed this package on Apr 4, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health issues and suggestions

Document public APIs. (-1 points)

6 out of 6 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/tesseract_ocr.dart.

Run flutter format to format lib/tesseract_ocr.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
path ^1.6.4 1.6.4
path_provider ^1.3.0 1.6.5
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
path_provider_macos 0.0.4
path_provider_platform_interface 1.0.1
platform 2.2.1
plugin_platform_interface 1.0.2
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test