10/23/1
This commit is contained in:
80
lib/controller/functions/ocr_controller.dart
Normal file
80
lib/controller/functions/ocr_controller.dart
Normal file
@@ -0,0 +1,80 @@
|
||||
import 'package:flutter_tesseract_ocr/flutter_tesseract_ocr.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
|
||||
class OCRController extends GetxController {
|
||||
final text = RxString('');
|
||||
|
||||
void setText(value) {
|
||||
text.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
class TextExtractionController extends GetxController {
|
||||
String extractedText = '';
|
||||
|
||||
Future<void> pickAndExtractText() async {
|
||||
final pickedImage =
|
||||
await ImagePicker().pickImage(source: ImageSource.camera);
|
||||
if (pickedImage != null) {
|
||||
final imagePath = pickedImage.path;
|
||||
final languages = [
|
||||
'eng',
|
||||
'ara'
|
||||
]; // Specify the languages you want to use for text extraction
|
||||
|
||||
try {
|
||||
final text = await FlutterTesseractOcr.extractText(imagePath,
|
||||
language:
|
||||
languages.join('+'), // Combine multiple languages with '+'
|
||||
args: {
|
||||
"psm": "4",
|
||||
"preserve_interword_spaces": "1",
|
||||
} // Additional options if needed
|
||||
);
|
||||
extractedText = text;
|
||||
} catch (e) {
|
||||
print('Error during text extraction: $e');
|
||||
extractedText = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// import 'package:get/get.dart';
|
||||
// import 'package:flutter/material.dart';
|
||||
// import 'package:image_picker/image_picker.dart';
|
||||
// import 'package:google_ml_kit/google_ml_kit.dart';
|
||||
//
|
||||
// class TextRecognizerController extends GetxController {
|
||||
// // The ImagePicker instance
|
||||
// final ImagePicker _imagePicker = ImagePicker();
|
||||
//
|
||||
// // The GoogleMlKit TextRecognizer instance
|
||||
// final TextRecognizer _textRecognizer = TextRecognizer();
|
||||
//
|
||||
// // The scanned text
|
||||
// String? scannedText;
|
||||
//
|
||||
// // Picks an image from the camera or gallery and extracts the text
|
||||
// Future<void> scanText() async {
|
||||
// // Pick an image from the camera or gallery
|
||||
// final XFile? image =
|
||||
// await _imagePicker.pickImage(source: ImageSource.gallery);
|
||||
//
|
||||
// // If no image was picked, return
|
||||
// if (image == null) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// // Recognize the text in the image
|
||||
// final RecognizedText recognizedText =
|
||||
// await _textRecognizer.processImage(image as InputImage);
|
||||
//
|
||||
// // Extract the scanned text
|
||||
// scannedText = recognizedText.text;
|
||||
//
|
||||
// // Update the UI
|
||||
// update();
|
||||
// }
|
||||
// }
|
||||
Reference in New Issue
Block a user