10/23/2
This commit is contained in:
12
ios/Podfile
12
ios/Podfile
@@ -1,5 +1,6 @@
|
||||
# Uncomment this line to define a global platform for your project
|
||||
platform :ios, '13.0'
|
||||
$iOSVersion = '13.0' # or newer version
|
||||
|
||||
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
|
||||
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
|
||||
@@ -38,7 +39,18 @@ target 'Runner' do
|
||||
end
|
||||
|
||||
post_install do |installer|
|
||||
# add these lines:
|
||||
installer.pods_project.build_configurations.each do |config|
|
||||
config.build_settings["EXCLUDED_ARCHS[sdk=*]"] = "armv7"
|
||||
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = $iOSVersion
|
||||
end
|
||||
installer.pods_project.targets.each do |target|
|
||||
flutter_additional_ios_build_settings(target)
|
||||
# add these lines:
|
||||
target.build_configurations.each do |config|
|
||||
if Gem::Version.new($iOSVersion) > Gem::Version.new(config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'])
|
||||
config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = $iOSVersion
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
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:image_picker/image_picker.dart';
|
||||
|
||||
class OCRController extends GetxController {
|
||||
@@ -12,11 +16,28 @@ class OCRController extends GetxController {
|
||||
|
||||
class TextExtractionController extends GetxController {
|
||||
String extractedText = '';
|
||||
bool isloading = false;
|
||||
File? _scannedImage;
|
||||
// Convert the extracted text to JSON
|
||||
String getTextAsJSON(String text) {
|
||||
final json = {
|
||||
'text': text,
|
||||
};
|
||||
|
||||
return jsonEncode(json);
|
||||
}
|
||||
|
||||
// Convert the extracted text to blocks by line
|
||||
List<String> getTextBlocks(String text) {
|
||||
return text.split('\n');
|
||||
}
|
||||
|
||||
Future<void> pickAndExtractText() async {
|
||||
final pickedImage =
|
||||
await ImagePicker().pickImage(source: ImageSource.camera);
|
||||
if (pickedImage != null) {
|
||||
isloading = true;
|
||||
update();
|
||||
final imagePath = pickedImage.path;
|
||||
final languages = [
|
||||
'eng',
|
||||
@@ -32,7 +53,17 @@ class TextExtractionController extends GetxController {
|
||||
"preserve_interword_spaces": "1",
|
||||
} // Additional options if needed
|
||||
);
|
||||
extractedText = text;
|
||||
isloading = false;
|
||||
final jsonText = getTextAsJSON(text);
|
||||
final textBlocks = getTextBlocks(text);
|
||||
update();
|
||||
extractedText =
|
||||
textBlocks.toString(); // Convert the extracted text to JSON.
|
||||
|
||||
// Print the JSON to the console.
|
||||
print(textBlocks);
|
||||
update();
|
||||
// print(text);
|
||||
} catch (e) {
|
||||
print('Error during text extraction: $e');
|
||||
extractedText = '';
|
||||
@@ -41,40 +72,82 @@ class TextExtractionController extends GetxController {
|
||||
}
|
||||
}
|
||||
|
||||
// class TesseractController extends GetxController {
|
||||
// String text = '';
|
||||
// bool scanning = false;
|
||||
|
||||
// Future<void> extractTextFromImage() async {
|
||||
// scanning = true;
|
||||
// update();
|
||||
|
||||
// // Get the image from the image picker
|
||||
// final ImagePicker picker = ImagePicker();
|
||||
// final XFile? image = await picker.pickImage(source: ImageSource.gallery);
|
||||
|
||||
// // If an image was selected, extract the text from it
|
||||
// if (image != null) {
|
||||
// var watch = Stopwatch()..start();
|
||||
// text = await TesseractLatest.extractText(image.path);
|
||||
// scanning = false;
|
||||
// update();
|
||||
// print('Scanning took ${watch.elapsedMilliseconds} ms');
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// 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();
|
||||
// }
|
||||
// }
|
||||
class TextRecognizerController extends GetxController {
|
||||
@override
|
||||
void onInit() {
|
||||
scanText();
|
||||
super.onInit();
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// Convert the XFile object to an InputImage object
|
||||
final InputImage inputImage = InputImage.fromFile(File(image.path));
|
||||
|
||||
// Recognize the text in the image
|
||||
final RecognizedText recognizedText =
|
||||
await _textRecognizer.processImage(inputImage);
|
||||
scannedText = recognizedText.text;
|
||||
// Extract the scanned text line by line
|
||||
final List<Map<String, dynamic>> lines = [];
|
||||
for (var i = 0; i < recognizedText.blocks.length; i++) {
|
||||
lines.add({
|
||||
'line_number': i,
|
||||
'text': recognizedText.blocks[i].text,
|
||||
});
|
||||
}
|
||||
|
||||
// Convert the list of lines to a JSON string
|
||||
final String jsonOutput = jsonEncode(lines);
|
||||
update();
|
||||
// Print the JSON output
|
||||
print(jsonOutput);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import 'package:ride/views/widgets/elevated_btn.dart';
|
||||
import 'package:flutter_font_icons/flutter_font_icons.dart';
|
||||
|
||||
import '../../../controller/functions/location_controller.dart';
|
||||
import '../../../controller/functions/ocr_controller.dart';
|
||||
import '../../../controller/home/captin/widget/connect.dart';
|
||||
|
||||
class HomeCaptain extends StatelessWidget {
|
||||
@@ -191,6 +192,14 @@ class HomeCaptain extends StatelessWidget {
|
||||
"Text FlutterTesseractsOcr",
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Get.to(() => TextRecognizerWidget());
|
||||
},
|
||||
child: const Text(
|
||||
"Text FlutterMLGoogle",
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_scalable_ocr/flutter_scalable_ocr.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:ride/views/widgets/mycircular.dart';
|
||||
|
||||
import '../../../controller/functions/ocr_controller.dart';
|
||||
|
||||
@@ -19,22 +19,23 @@ class TextScanner extends StatelessWidget {
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
ScalableOCR(
|
||||
paintboxCustom: Paint()
|
||||
..style = PaintingStyle.stroke
|
||||
..strokeWidth = 4.0
|
||||
..color = const Color.fromARGB(153, 102, 160, 241),
|
||||
boxLeftOff: 5,
|
||||
boxBottomOff: 2.5,
|
||||
boxRightOff: 5,
|
||||
boxTopOff: 2.5,
|
||||
boxHeight: MediaQuery.of(context).size.height / 3,
|
||||
getRawData: (value) {
|
||||
// Inspect the raw data here.
|
||||
},
|
||||
getScannedText: (value) {
|
||||
controller.setText(value);
|
||||
}),
|
||||
// ScalableOCR(
|
||||
// paintboxCustom: Paint()
|
||||
// ..style = PaintingStyle.stroke
|
||||
// ..strokeWidth = 4.0
|
||||
// ..color = const Color.fromARGB(153, 102, 160, 241),
|
||||
// boxLeftOff: 5,
|
||||
// boxBottomOff: 2.5,
|
||||
// boxRightOff: 5,
|
||||
// boxTopOff: 2.5,
|
||||
// boxHeight: MediaQuery.of(context).size.height / 3,
|
||||
// getRawData: (value) {
|
||||
// // Inspect the raw data here.
|
||||
// },
|
||||
// getScannedText: (value) {
|
||||
// controller.setText(value);
|
||||
// }),
|
||||
|
||||
Result(),
|
||||
Obx(() {
|
||||
return SnackBar(
|
||||
@@ -80,7 +81,9 @@ class TextExtractionView extends StatelessWidget {
|
||||
child: const Text('Pick Image and Extract Text'),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
Text(controller.extractedText),
|
||||
controller.isloading
|
||||
? const MyCircularProgressIndicator()
|
||||
: Text(controller.extractedText),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -88,6 +91,62 @@ class TextExtractionView extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class TextRecognizerWidget extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
Get.put(TextRecognizerController());
|
||||
return GetBuilder<TextRecognizerController>(
|
||||
builder: (controller) => Scaffold(
|
||||
appBar: AppBar(),
|
||||
body: Center(
|
||||
child: Text(controller.scannedText ?? ''),
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// class TesseractWidget extends StatelessWidget {
|
||||
// final TesseractController controller = Get.put(TesseractController());
|
||||
|
||||
// @override
|
||||
// Widget build(BuildContext context) {
|
||||
// return Scaffold(
|
||||
// appBar: AppBar(
|
||||
// title: Text('Tesseract Implementation'),
|
||||
// ),
|
||||
// body: GetBuilder<TesseractController>(
|
||||
// builder: (controller) => Container(
|
||||
// padding: const EdgeInsets.all(16),
|
||||
// child: ListView(
|
||||
// children: <Widget>[
|
||||
// Column(
|
||||
// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
// children: [
|
||||
// ElevatedButton(
|
||||
// child: Text('Select image'),
|
||||
// onPressed: controller.extractTextFromImage,
|
||||
// ),
|
||||
// controller.scanning
|
||||
// ? const MyCircularProgressIndicator()
|
||||
// : const Icon(Icons.done),
|
||||
// SizedBox(height: 16),
|
||||
// Center(child: SelectableText(controller.text)),
|
||||
// ],
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// ),
|
||||
// ),
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// import 'package:flutter/material.dart';
|
||||
// import 'package:get/get.dart';
|
||||
// import 'package:image_picker/image_picker.dart';
|
||||
|
||||
100
pubspec.lock
100
pubspec.lock
@@ -49,46 +49,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.1.1"
|
||||
camera:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: camera
|
||||
sha256: "1f9010f0689774380fbcd7d6b7820a5157e8e97685fa66d619e1d1f58b3fdf93"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.10.5+5"
|
||||
camera_android:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: camera_android
|
||||
sha256: c978373b41a463c9edda3fea0a06966299f55db63232cd0f0d4efc21a59a0006
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.10.8+12"
|
||||
camera_avfoundation:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: camera_avfoundation
|
||||
sha256: "9495e633cda700717bbe299b0979e6c4a08cee45f298945973dc9cf3e4c1cba5"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.9.13+6"
|
||||
camera_platform_interface:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: camera_platform_interface
|
||||
sha256: "8734d1c682f034bdb12d0d6ff379b0535a9b8e44266b530025bf8266d6a62f28"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.5.2"
|
||||
camera_web:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: camera_web
|
||||
sha256: d4c2c571c7af04f8b10702ca16bb9ed2a26e64534171e8f75c9349b2c004d8f1
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.3.2+3"
|
||||
characters:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -185,14 +145,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.7.8"
|
||||
decimal:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: decimal
|
||||
sha256: "24a261d5d5c87e86c7651c417a5dbdf8bcd7080dd592533910e8d0505a279f21"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.3.3"
|
||||
device_info_plus:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -318,14 +270,6 @@ packages:
|
||||
description: flutter
|
||||
source: sdk
|
||||
version: "0.0.0"
|
||||
flutter_charts:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_charts
|
||||
sha256: eb9d2bf98bfc779c1da9cf1fe80afd598094aed33e536cf04845d8f266f48c11
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.5.2"
|
||||
flutter_font_icons:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -398,14 +342,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.0.1"
|
||||
flutter_scalable_ocr:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: flutter_scalable_ocr
|
||||
sha256: "9e5c239c993c3c6c0b530b42165547b275d7db18d646cfc840b750aea1a7c988"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
flutter_secure_storage:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -612,18 +548,18 @@ packages:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: google_mlkit_commons
|
||||
sha256: "68429fa2e17686819dbaf2344790e3daa59924ef8625dd24f97f9deaaed42767"
|
||||
sha256: "42173a8ba89f386486cc5b8249e84da4a4b861daa70498373627d985eb418689"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.3.0"
|
||||
version: "0.5.0"
|
||||
google_mlkit_text_recognition:
|
||||
dependency: transitive
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: google_mlkit_text_recognition
|
||||
sha256: "0d5ac35fc666c311e0cd34f64c28f0842eb192ee2f23d49845a14d147aede146"
|
||||
sha256: "588021c99536fdfb173eeecc4ee1b60ea4e0bd4be9787f52363c85346ae20364"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.6.0"
|
||||
version: "0.10.0"
|
||||
google_polyline_algorithm:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -840,14 +776,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "4.2.0"
|
||||
logger:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: logger
|
||||
sha256: "6bbb9d6f7056729537a4309bda2e74e18e5d9f14302489cc1e93f33b3fe32cac"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.2+1"
|
||||
lottie:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@@ -984,14 +912,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.2.1"
|
||||
rational:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: rational
|
||||
sha256: ba58e9e18df9abde280e8b10051e4bce85091e41e8e7e411b6cde2e738d357cf
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.2.2"
|
||||
sanitize_html:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -1093,14 +1013,6 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.9.2"
|
||||
tuple:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: tuple
|
||||
sha256: a97ce2013f240b2f3807bcbaf218765b6f301c3eff91092bcfa23a039e7dd151
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.2"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
@@ -1271,4 +1183,4 @@ packages:
|
||||
version: "3.1.2"
|
||||
sdks:
|
||||
dart: ">=3.1.0 <4.0.0"
|
||||
flutter: ">=3.13.0"
|
||||
flutter: ">=3.10.0"
|
||||
|
||||
@@ -38,11 +38,16 @@ dependencies:
|
||||
crypto: ^3.0.3
|
||||
flutter_rating_bar: ^4.0.1
|
||||
flutter_font_icons: ^2.2.5
|
||||
flutter_charts: ^0.5.2
|
||||
# flutter_charts: ^0.5.2
|
||||
device_info_plus: ^9.1.0
|
||||
flutter_scalable_ocr: ^2.0.0
|
||||
# flutter_scalable_ocr: ^2.0.0
|
||||
image_picker: ^1.0.4
|
||||
flutter_tesseract_ocr: ^0.4.24
|
||||
# document_scanner_flutter: ^0.2.7
|
||||
# ocr_scan_text: ^1.3.1
|
||||
# tesseract_latest: ^0.0.2
|
||||
google_mlkit_text_recognition: ^0.10.0
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user