10/25/3
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter_tesseract_ocr/flutter_tesseract_ocr.dart';
|
||||
import 'package:get/get.dart';
|
||||
@@ -18,11 +19,20 @@ class TextExtractionController extends GetxController {
|
||||
String extractedText = '';
|
||||
bool isloading = false;
|
||||
File? _scannedImage;
|
||||
// Convert the extracted text to JSON
|
||||
// Convert the extracted text to JSON
|
||||
String getTextAsJSON(String text) {
|
||||
final lines = text.split('\n');
|
||||
final jsonList = lines.map((line) {
|
||||
return {
|
||||
'line_text': line,
|
||||
'num_words': line.trim().split(' ').length,
|
||||
};
|
||||
}).toList();
|
||||
|
||||
final json = {
|
||||
'text': text,
|
||||
'num_lines': text.split('\n').length,
|
||||
'lines': jsonList,
|
||||
'num_lines': lines.length,
|
||||
};
|
||||
|
||||
return jsonEncode(json);
|
||||
@@ -35,11 +45,11 @@ class TextExtractionController extends GetxController {
|
||||
|
||||
Future<void> pickAndExtractText() async {
|
||||
final pickedImage = await ImagePicker().pickImage(
|
||||
source: ImageSource.camera,
|
||||
preferredCameraDevice: CameraDevice.rear,
|
||||
maxHeight: Get.height * .7,
|
||||
maxWidth: Get.width * .9,
|
||||
imageQuality: 99,
|
||||
source: ImageSource.gallery,
|
||||
// preferredCameraDevice: CameraDevice.rear,
|
||||
// maxHeight: Get.height * .7,
|
||||
// maxWidth: Get.width * .9,
|
||||
// imageQuality: 99,
|
||||
);
|
||||
if (pickedImage != null) {
|
||||
isloading = true;
|
||||
@@ -56,8 +66,8 @@ class TextExtractionController extends GetxController {
|
||||
languages.join('+'), // Combine multiple languages with '+'
|
||||
args: {
|
||||
"psm": "4",
|
||||
"preserve_interword_spaces":
|
||||
"1", // "rectangle": Rect.fromLTWH(100, 100, 200, 200),
|
||||
"preserve_interword_spaces": "1",
|
||||
// "rectangle": const Rect.fromLTWH(100, 100, 200, 200),
|
||||
} // Additional options if needed
|
||||
);
|
||||
isloading = false;
|
||||
|
||||
Reference in New Issue
Block a user