mirror of
https://github.com/Ladebeze66/llm_ticket3.git
synced 2025-12-13 09:06:51 +01:00
106 lines
4.1 KiB
Python
106 lines
4.1 KiB
Python
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import sys
|
|
import os
|
|
import subprocess
|
|
import pytesseract
|
|
from PIL import Image
|
|
import io
|
|
|
|
def check_tesseract_installation():
|
|
"""Vérifie l'installation de Tesseract-OCR"""
|
|
print("=== VÉRIFICATION DE L'INSTALLATION TESSERACT ===\n")
|
|
|
|
# 1. Vérifier l'installation de pytesseract
|
|
print("1. Module pytesseract:", "INSTALLÉ" if "pytesseract" in sys.modules else "NON INSTALLÉ")
|
|
print(f" Version: {pytesseract.__version__}")
|
|
|
|
# 2. Vérifier la configuration du chemin tesseract
|
|
print(f"2. Chemin tesseract configuré: {pytesseract.pytesseract.tesseract_cmd}")
|
|
|
|
# 3. Vérifier si le binaire existe
|
|
try:
|
|
if os.path.exists(pytesseract.pytesseract.tesseract_cmd):
|
|
print(f" Le binaire existe: OUI")
|
|
else:
|
|
print(f" Le binaire existe: NON")
|
|
|
|
# Tenter de trouver tesseract dans le PATH
|
|
try:
|
|
which_output = subprocess.check_output(["which", "tesseract"], universal_newlines=True).strip()
|
|
print(f" Tesseract trouvé dans le PATH: {which_output}")
|
|
except subprocess.CalledProcessError:
|
|
print(" Tesseract non trouvé dans le PATH")
|
|
except:
|
|
print(" Erreur lors de la vérification du binaire tesseract")
|
|
|
|
# 4. Tester l'exécution de tesseract
|
|
try:
|
|
version = subprocess.check_output([pytesseract.pytesseract.tesseract_cmd, "--version"],
|
|
stderr=subprocess.STDOUT,
|
|
universal_newlines=True)
|
|
print("\n3. Version de Tesseract:")
|
|
print(" " + version.split("\n")[0])
|
|
except (subprocess.CalledProcessError, FileNotFoundError):
|
|
print("\n3. Impossible d'exécuter tesseract")
|
|
|
|
# Essayer avec just 'tesseract'
|
|
try:
|
|
version = subprocess.check_output(["tesseract", "--version"],
|
|
stderr=subprocess.STDOUT,
|
|
universal_newlines=True)
|
|
print(" Tesseract est disponible avec la commande 'tesseract'")
|
|
print(" " + version.split("\n")[0])
|
|
print("\n SUGGESTION: Modifiez pytesseract.pytesseract.tesseract_cmd = 'tesseract'")
|
|
except:
|
|
print(" Tesseract n'est pas installé ou n'est pas dans le PATH")
|
|
|
|
# 5. Vérifier les langues disponibles
|
|
try:
|
|
langs = pytesseract.get_languages()
|
|
print("\n4. Langues disponibles:")
|
|
print(" " + ", ".join(langs))
|
|
|
|
# Vérifier si le français est disponible
|
|
if "fra" in langs:
|
|
print(" Le français est disponible: OUI")
|
|
else:
|
|
print(" Le français est disponible: NON")
|
|
print(" ERREUR: Le pack de langue français (fra) n'est pas installé!")
|
|
except:
|
|
print("\n4. Impossible de récupérer les langues disponibles")
|
|
|
|
# 6. Test basique avec une image contenant du texte
|
|
print("\n5. Test de base avec une image générée:")
|
|
try:
|
|
# Créer une image test avec du texte
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
|
|
# Créer une image blanche avec texte noir
|
|
img = Image.new('RGB', (200, 50), color = (255, 255, 255))
|
|
d = ImageDraw.Draw(img)
|
|
|
|
# Écrire du texte (texte simple sans police spécifique)
|
|
d.text((10,10), "TEST OCR 123", fill=(0,0,0))
|
|
|
|
# Sauvegarder et tester
|
|
test_image_path = "test_ocr_image.png"
|
|
img.save(test_image_path)
|
|
|
|
# OCR
|
|
text = pytesseract.image_to_string(Image.open(test_image_path), lang='fra')
|
|
print(f" Image créée: {test_image_path}")
|
|
print(f" Texte détecté: '{text.strip()}'")
|
|
|
|
if "TEST" in text or "TESTOCR" in text:
|
|
print(" Test réussi: OUI")
|
|
else:
|
|
print(" Test réussi: NON")
|
|
except Exception as e:
|
|
print(f" Erreur lors du test: {str(e)}")
|
|
|
|
print("\n=== FIN DE LA VÉRIFICATION ===")
|
|
|
|
if __name__ == "__main__":
|
|
check_tesseract_installation() |