Update: 2026-05-12 01:07:38
This commit is contained in:
@@ -36,24 +36,24 @@ class ImageProcessingService {
|
||||
}
|
||||
|
||||
File compressedFile = File(compressedXFile.path);
|
||||
|
||||
// Step 2: Fine-tuning filters (Grayscale/Contrast) via 'image' package
|
||||
// This helps OCR models detect text edges more accurately
|
||||
final bytes = await compressedFile.readAsBytes();
|
||||
final filteredBytes = await compute(_applyFilters, bytes);
|
||||
|
||||
// Step 2: Grayscale and Contrast using `image` package (in Isolate to avoid UI freeze)
|
||||
final processedBytes =
|
||||
await compute(_applyFilters, await compressedFile.readAsBytes());
|
||||
|
||||
if (processedBytes == null) {
|
||||
AppLogger.error('Failed to apply filters', null);
|
||||
return compressedFile; // Fallback to just compressed
|
||||
if (filteredBytes != null) {
|
||||
final filteredPath = path.join(
|
||||
dir.path, 'filtered_${DateTime.now().millisecondsSinceEpoch}.jpg');
|
||||
final filteredFile = File(filteredPath);
|
||||
await filteredFile.writeAsBytes(filteredBytes);
|
||||
|
||||
AppLogger.print('Finished processing image with filters: ${filteredFile.path}');
|
||||
return filteredFile;
|
||||
}
|
||||
|
||||
// Step 3: Save final processed image
|
||||
final finalPath = path.join(
|
||||
dir.path, 'processed_${DateTime.now().millisecondsSinceEpoch}.jpg');
|
||||
final finalFile = File(finalPath);
|
||||
await finalFile.writeAsBytes(processedBytes);
|
||||
|
||||
AppLogger.print('Finished processing image: ${finalFile.path}');
|
||||
return finalFile;
|
||||
AppLogger.print('Finished processing image (no filters): ${compressedFile.path}');
|
||||
return compressedFile;
|
||||
} catch (e, stack) {
|
||||
AppLogger.error('Error processing image', e, stack);
|
||||
return originalImage; // Fallback
|
||||
@@ -66,13 +66,8 @@ class ImageProcessingService {
|
||||
img.Image? decodedImage = img.decodeImage(Uint8List.fromList(bytes));
|
||||
if (decodedImage == null) return null;
|
||||
|
||||
// Convert to Grayscale
|
||||
img.grayscale(decodedImage);
|
||||
|
||||
// Increase contrast (adjust as needed, e.g., 1.5)
|
||||
img.contrast(decodedImage, contrast: 150);
|
||||
|
||||
// Encode back to JPG
|
||||
// Do not apply grayscale or contrast filters as they destroy the image quality
|
||||
// for OpenAI Vision models. Only encode back to JPG.
|
||||
return img.encodeJpg(decodedImage, quality: 90);
|
||||
} catch (e) {
|
||||
return null;
|
||||
|
||||
@@ -24,7 +24,7 @@ class UploadProgressService extends GetxService {
|
||||
|
||||
void startProcessing() {
|
||||
status.value = 'processing';
|
||||
progress.value = 0.5; // generic progress for processing until FCM hits
|
||||
progress.value = 0.5;
|
||||
}
|
||||
|
||||
void updateProcessingProgress(int processed, int total) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'dart:io';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:get/get.dart';
|
||||
import 'package:get/get.dart' hide FormData, MultipartFile;
|
||||
import 'package:firebase_messaging/firebase_messaging.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
@@ -156,6 +157,7 @@ class ScannerController extends GetxController {
|
||||
// Start global progress
|
||||
_progressService.startUpload(selectedCompanyName.value, capturedImages.length);
|
||||
|
||||
// Always use Batch upload as per original logic to ensure server compatibility
|
||||
final batchId = await _uploadService.uploadBatch(
|
||||
companyId: selectedCompanyId.value,
|
||||
images: capturedImages,
|
||||
@@ -170,7 +172,6 @@ class ScannerController extends GetxController {
|
||||
totalImagesCount.value = capturedImages.length;
|
||||
processedImagesCount.value = 0;
|
||||
|
||||
// Clear scanner state and go back to dashboard
|
||||
capturedImages.clear();
|
||||
uploadProgress.value = 0.0;
|
||||
isProcessing.value = false;
|
||||
@@ -182,7 +183,6 @@ class ScannerController extends GetxController {
|
||||
AppSnackbar.showSuccess(
|
||||
'تم البدء', 'تم رفع الصور بنجاح، جاري استخراج البيانات في الخلفية');
|
||||
|
||||
// Start polling for status (Reliable fallback for FCM)
|
||||
_startPolling(batchId);
|
||||
} else {
|
||||
_progressService.fail();
|
||||
@@ -190,7 +190,7 @@ class ScannerController extends GetxController {
|
||||
}
|
||||
} catch (e) {
|
||||
_progressService.fail();
|
||||
AppLogger.error('Failed to upload batch', e);
|
||||
AppLogger.error('Failed to upload batch/single', e);
|
||||
AppSnackbar.showError('خطأ', 'حدث خطأ غير متوقع أثناء الرفع');
|
||||
} finally {
|
||||
isProcessing.value = false;
|
||||
|
||||
Reference in New Issue
Block a user