mirc detection
This commit is contained in:
@@ -11,6 +11,7 @@ import traceback
|
||||
import redis
|
||||
from datetime import datetime
|
||||
from rq import get_current_job
|
||||
from json import JSONEncoder
|
||||
|
||||
# Ajouter le module d'extraction au path
|
||||
sys.path.append('/app/shared')
|
||||
@@ -56,7 +57,8 @@ def update_job_status(job_id, status, message=None, progress=None, result=None,
|
||||
update_data["progress"] = str(progress)
|
||||
|
||||
if result:
|
||||
update_data["result"] = str(result)
|
||||
# Utiliser json.dumps pour une sérialisation correcte
|
||||
update_data["result"] = json.dumps(result)
|
||||
|
||||
if texte_brut:
|
||||
update_data["texte_brut"] = texte_brut
|
||||
@@ -82,13 +84,14 @@ def update_job_status(job_id, status, message=None, progress=None, result=None,
|
||||
return False
|
||||
|
||||
|
||||
def process_cheque_image(file_path, job_id):
|
||||
def process_cheque_image(job_id, file_path, **kwargs):
|
||||
"""
|
||||
Traite une image de chèque pour en extraire les informations
|
||||
|
||||
Args:
|
||||
file_path (str): Chemin vers l'image à traiter
|
||||
job_id (str): Identifiant de la tâche
|
||||
file_path (str): Chemin vers l'image à traiter
|
||||
**kwargs: Paramètres supplémentaires (ignorés, pour compatibilité avec RQ)
|
||||
|
||||
Returns:
|
||||
dict: Résultat de l'extraction
|
||||
@@ -135,12 +138,12 @@ def process_cheque_image(file_path, job_id):
|
||||
|
||||
infos, texte = extraire_infos_cheque(
|
||||
chemin_image=file_path,
|
||||
methode="ocr",
|
||||
methode="hybride_avance",
|
||||
language=DEFAULT_OCR_LANGUAGE,
|
||||
tessdata=tessdata_path
|
||||
)
|
||||
|
||||
methode = "ocr"
|
||||
methode = "hybride_avance"
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(f"Échec de la première tentative: {str(e)}")
|
||||
@@ -157,31 +160,50 @@ def process_cheque_image(file_path, job_id):
|
||||
|
||||
infos, texte = extraire_infos_cheque(
|
||||
chemin_image=file_path,
|
||||
methode="ocr",
|
||||
methode="hybride_avance",
|
||||
language=ALTERNATIVE_OCR_LANGUAGE,
|
||||
tessdata=tessdata_path
|
||||
)
|
||||
|
||||
methode = "ocr"
|
||||
methode = "hybride_avance"
|
||||
|
||||
except Exception as e2:
|
||||
logger.warning(f"Échec de la deuxième tentative: {str(e2)}")
|
||||
|
||||
# Troisième tentative avec la méthode CV
|
||||
logger.info("Tentative d'extraction avec la méthode CV (sans OCR)")
|
||||
# Troisième tentative avec la méthode hybride (combinant MICR et extraction du montant en lettres)
|
||||
logger.info("Tentative d'extraction avec la méthode hybride (MICR + montant en lettres)")
|
||||
update_job_status(
|
||||
job_id=job_id,
|
||||
status="processing",
|
||||
message="Extraction par détection de zones (sans OCR)",
|
||||
message="Extraction MICR et montant en lettres",
|
||||
progress=70
|
||||
)
|
||||
|
||||
infos, texte = extraire_infos_cheque(
|
||||
chemin_image=file_path,
|
||||
methode="cv"
|
||||
methode="hybride",
|
||||
language=DEFAULT_OCR_LANGUAGE,
|
||||
tessdata=tessdata_path
|
||||
)
|
||||
|
||||
methode = "cv"
|
||||
methode = "hybride"
|
||||
|
||||
# Si échec, dernière tentative avec la méthode MICR seule
|
||||
if not infos.get("montant") and not infos.get("code_banque"):
|
||||
logger.info("Tentative d'extraction avec la méthode MICR uniquement")
|
||||
update_job_status(
|
||||
job_id=job_id,
|
||||
status="processing",
|
||||
message="Extraction MICR uniquement",
|
||||
progress=80
|
||||
)
|
||||
|
||||
infos, texte = extraire_infos_cheque(
|
||||
chemin_image=file_path,
|
||||
methode="micr"
|
||||
)
|
||||
|
||||
methode = "micr"
|
||||
|
||||
# Mise à jour finale
|
||||
update_job_status(
|
||||
|
||||
Reference in New Issue
Block a user