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