ANDREAS_LATANOWSKY_CPD_1910877/lib/image_uploader.dart

49 lines
1.4 KiB
Dart
Raw Normal View History

2023-11-21 19:48:58 +01:00
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 {
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;
}
2024-01-02 13:53:21 +01:00
Future<String> performAdvancedOCR(
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.extractHocr(tempImageFile.path,
language: lang,
args: {
"psm": "4",
"preserve_interword_spaces": "1",
});
return text;
}
2023-11-21 19:48:58 +01:00
}