34 lines
953 B
Dart
34 lines
953 B
Dart
|
import 'package:flutter/services.dart';
|
||
|
import 'dart:io';
|
||
|
import 'package:flutter_tesseract_ocr/flutter_tesseract_ocr.dart';
|
||
|
import 'package:path_provider/path_provider.dart';
|
||
|
|
||
|
class ImageUploader {
|
||
|
//final http.Client client;
|
||
|
|
||
|
ImageUploader();
|
||
|
|
||
|
Future<Uint8List> buildImageFile(String img) async {
|
||
|
String imageName = img;
|
||
|
ByteData bytes = await rootBundle.load('assets/$imageName');
|
||
|
return bytes.buffer.asUint8List();
|
||
|
}
|
||
|
|
||
|
Future<String> performOcr(
|
||
|
Uint8List imageBytes, String imageName, String lang) async {
|
||
|
Directory tempDir = await getTemporaryDirectory();
|
||
|
String tempPath = tempDir.path;
|
||
|
File tempImageFile = File('$tempPath/$imageName');
|
||
|
await tempImageFile.writeAsBytes(imageBytes);
|
||
|
|
||
|
String text = await FlutterTesseractOcr.extractText(tempImageFile.path,
|
||
|
language: lang,
|
||
|
args: {
|
||
|
"psm": "4",
|
||
|
"preserve_interword_spaces": "1",
|
||
|
});
|
||
|
|
||
|
return text;
|
||
|
}
|
||
|
}
|