tesseract_ocr 0.1.2 copy "tesseract_ocr: ^0.1.2" to clipboard
tesseract_ocr: ^0.1.2 copied to clipboard

outdated

Tesseract OCR for Flutter. Tesseract 4 adds a new neural net (LSTM) based OCR engine which is focused on line recognition.It also needs traineddata files which support the legacy engine, for example t [...]

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_16.jpg');
    final Uint8List bytes = data.buffer.asUint8List(
      data.offsetInBytes,
      data.lengthInBytes,
    );
    await File(imagePath).writeAsBytes(bytes);

      extractText = await TesseractOcr.extractText(imagePath);
    } 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_16.jpg',package: 'tesseract_ocr', height: 30.0),
            ],
          )),
    );
  }
}
79
likes
0
pub points
89%
popularity

Publisher

verified publisherzikzak.wtf

Tesseract OCR for Flutter. Tesseract 4 adds a new neural net (LSTM) based OCR engine which is focused on line recognition.It also needs traineddata files which support the legacy engine, for example those from the tessdata repository.Tesseract has unicode (UTF-8) support, and can recognize more than 100 languages out of the box.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, path, path_provider

More

Packages that depend on tesseract_ocr