flutter_tesseract_ocr 0.4.10 flutter_tesseract_ocr: ^0.4.10 copied to clipboard
Tesseract 4 adds a new neural net (LSTM) based OCR engine which is focused on line recognition. It has unicode (UTF-8) support, and can recognize more than 100 languages.
import 'dart:async';
import 'package:camera/camera.dart';
import 'package:example/Demos/TextDetectorFromCamera.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'dart:io';
import 'Demos/TextDetector.dart';
late List<CameraDescription> cameras;
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
if (!kIsWeb) {
cameras = await availableCameras();
}
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Tesseract Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Home(),
);
}
}
class Home extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Tesseract Demo'),
centerTitle: true,
elevation: 0,
),
body: SafeArea(
child: Center(
child: SingleChildScrollView(
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 16),
child: Column(
children: [
CustomCard(
'Text Detector',
TextDetector(
title: "Extract text From File",
),
featureCompleted: true,
),
kIsWeb
? Container()
: CustomCard(
'Tesseract OCR Live (IOS)',
TextDetectorView(),
featureCompleted: true,
),
],
),
),
),
),
),
);
}
}
class CustomCard extends StatelessWidget {
final String _label;
final Widget _viewPage;
final bool featureCompleted;
const CustomCard(this._label, this._viewPage,
{this.featureCompleted = false});
@override
Widget build(BuildContext context) {
return Card(
elevation: 5,
margin: EdgeInsets.only(bottom: 10),
child: ListTile(
tileColor: Theme.of(context).primaryColor,
title: Text(
_label,
style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
),
onTap: () {
if (!kIsWeb && Platform.isIOS && !featureCompleted) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
content: const Text(
'This feature has not been implemented for iOS yet')));
} else
Navigator.push(
context, MaterialPageRoute(builder: (context) => _viewPage));
},
),
);
}
}
void logError(String code, String? message) {
if (message != null) {
print('Error: $code\nError Message: $message');
} else {
print('Error: $code');
}
}
/// Returns a suitable camera icon for [direction].
IconData getCameraLensIcon(CameraLensDirection direction) {
switch (direction) {
case CameraLensDirection.back:
return Icons.camera_rear;
case CameraLensDirection.front:
return Icons.camera_front;
case CameraLensDirection.external:
return Icons.camera;
default:
throw ArgumentError('Unknown lens direction');
}
}