This commit is contained in:
Hamza-Ayed
2023-11-09 18:26:11 +03:00
parent 8238323dd3
commit ebde8bb44d
29 changed files with 1667 additions and 819 deletions

View File

@@ -2,7 +2,6 @@ import 'dart:convert';
import 'dart:io';
import 'package:camera/camera.dart';
import 'package:flutter_tesseract_ocr/flutter_tesseract_ocr.dart';
import 'package:get/get.dart';
import 'package:google_mlkit_text_recognition/google_mlkit_text_recognition.dart';
import 'package:ride/constant/box_name.dart';
@@ -193,49 +192,49 @@ class CameraClassController extends GetxController {
return text.split('\n');
}
Future<void> takePictureAndTesseractScan() async {
try {
// Construct the path for the image file
final directory = await path_provider.getTemporaryDirectory();
final imagePath =
path.join(directory.path, '${box.read(BoxName.driverID)}.png');
// Future<void> takePictureAndTesseractScan() async {
// try {
// // Construct the path for the image file
// final directory = await path_provider.getTemporaryDirectory();
// final imagePath =
// path.join(directory.path, '${box.read(BoxName.driverID)}.png');
// Capture the image and save it to the specified path
final XFile capturedImage = await cameraController.takePicture();
// // Capture the image and save it to the specified path
// final XFile capturedImage = await cameraController.takePicture();
// Move the captured image to the desired path
await capturedImage.saveTo(imagePath);
// // Move the captured image to the desired path
// await capturedImage.saveTo(imagePath);
// Recognize the text in the image
final languages = [
'eng',
'ara'
]; // Specify the languages you want to use for text extraction
// // Recognize the text in the image
// final languages = [
// 'eng',
// 'ara'
// ]; // Specify the languages you want to use for text extraction
final text = await FlutterTesseractOcr.extractText(imagePath,
language: languages.join('+'), // Combine multiple languages with '+'
args: {
"psm": "4",
"preserve_interword_spaces": "1",
// "rectangle": const Rect.fromLTWH(100, 100, 200, 200),
} // Additional options if needed
);
isloading = false;
final jsonText = getTextAsJSON(text);
final textBlocks = getTextBlocks(text);
update();
scannedText =
textBlocks.toString(); // Convert the extracted text to JSON.
// final text = await FlutterTesseractOcr.extractText(imagePath,
// language: languages.join('+'), // Combine multiple languages with '+'
// args: {
// "psm": "4",
// "preserve_interword_spaces": "1",
// // "rectangle": const Rect.fromLTWH(100, 100, 200, 200),
// } // Additional options if needed
// );
// isloading = false;
// final jsonText = getTextAsJSON(text);
// final textBlocks = getTextBlocks(text);
// update();
// scannedText =
// textBlocks.toString(); // Convert the extracted text to JSON.
// Print the JSON to the console.
print(jsonText);
update();
// print(text);
} catch (e) {
print('Error during text extraction: $e');
scannedText = '';
}
}
// // Print the JSON to the console.
// print(jsonText);
// update();
// // print(text);
// } catch (e) {
// print('Error during text extraction: $e');
// scannedText = '';
// }
// }
@override
void onClose() {

File diff suppressed because it is too large Load Diff