pense-bête de bruno sanchiz

Accueil > Linux > Lignes de commandes > OCR : créer un fichier texte à partir d’une image

OCR : créer un fichier texte à partir d’une image

Publié le 7 octobre 2014, dernière mise-à-jour le 28 avril 2023, 9 visites, 23643 visites totales.

Il faut toujours préparer le fichier : une seule colonne, pas d’image , pas de texte qui déborde sur un autre ligne. Chaque ligne doit être le plus horizontal possible.

En 2017 je conseille gimagereader, qui utilise tesseract.

Installation : apt-get install gimagereader ou Windows ou sources

Utilisation : gimagereader Menu->Logiciels->Graphisme->gimagereader OU clic droit sur un fichier -> ouvrir avec gimagereader

analyse de Différents logiciels

Tout d’abord, ouvrir un terminal.
On analyse l’image a.jpg ; on obtient le fichier sortie.txt

Installation et utilisation

tesseract et opencv
https://www.geeksforgeeks.org/text-detection-and-extraction-using-opencv-and-ocr/
pip install opencv-python
pip install pytesseract

tesseract
apt-get install tesseract-ocr tesseract-ocr-fra
utilisation : tesseract a.jpg sortie -l fra

ocrad
apt-get install ocrad imagemagick
utilisation : convert a.jpg a.ppm; ocrad a.ppm > sortie.txt

gocr
apt-get install gocr xfig
utilisation : gocr -i a.jpg > sortie.txt

cuneiform
apt-get install cuneiform
utilisation : cuneiform  a.jpg -f text -l fra -o sortie.txt

tesseract ocrad gocr cuneiform
apt-get install tesseract-ocr tesseract-ocr-fra ocrad imagemagick gocr xfig cuneiform
utilisation avec sorties multiples :

On obtient les 4 fichiers sortie1.txt sortie2.txt sortie3.txt sortie4.txt

Comparaisons des programmes en 2023 et 2017

 Fich="textedea.png" ; convert "$Fich" a.ppm ; ocrad a.ppm > ocrad-t.txt ; gocr -i "$Fich" > gocr-t.txt ; cuneiform "$Fich" -f text -l fra -o cuneiform-t.txt ; tesseract "$Fich" tesseract -l fra

gimagereader

  • 2023 :
  • 2017

cuneiform 2023 : 4 ; 2017 : 3

  • 2023 : ll->B ; oublie exposant, pas de note, La métrique->T a Wétrique
  • 2017 : oublie exposant, pas de note,. La métrique->La étriqué

gocr : 2/5

  • 2023 :
  • 2017 : nombreuses erreurs - inutilisable

ocrad : 3/5 très nombreuses erreurs
-* 2023 : en->eo ; concordance->concordaoce ;

  • 2017

tesseract

  • 2023
  • 2017 ne sait pas écrire l’exposant ; note 1 devient l

Comparaisons 2014

Création d’une image : texte='tesseract a.jpg sortie1 -l fra ; convert a.jpg a.ppm ; ocrad a.ppm > sortie2.txt ; gocr -i a.jpg > sortie3.txt ; cuneiform a.jpg -f text -l fra -o sortie4.txt' ; convert -size 6000x85 -background blue canvas:white -font Arial-Normal -pointsize 72 -draw "text 25,60 '$(echo $texte)'" a.jpg

Création d’une image : texte='Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed doeiusmod tempor incididunt ut labore'; convert -size 6000x85 -background blue canvas:white -font Arial-Normal -pointsize 72 -draw "text 25,60 '$(echo $texte)'" a.jpg && convert a.jpg a.ppm ; ocrad a.ppm > ocrad.txt ; gocr -i a.jpg > gocr.txt ; cuneiform a.jpg -f text -l fra -o cuneiform.txt'  

Resultats :

tesseract
tesseract a.jpg sortie1 -I fra ; convert a.jpg a.ppm ; ocrad a.ppm > sortie2.txt ; gocr -i a.jpg > sortie3.txt ; cuneiform a.jpg -f text -I fra -o sortie4.txt ( 2 erreurs : I au lieu de l )

ocrad
tesseract a.jpg sortie1 -| fra ; convert a.jpg a.ppm ; ocrad a.ppm > sortie2.txt ; gocr -i a.jpg > sortie3.txt ; cuneiform a.jpg -f text -| fra -o sortie4.txt ( 2 erreurs : | au lieu de l )

gocr
tesseract a.jpg so_ie1 -l fra ; convert a.jpg a.ppm ; ocrad a.ppm > sortie2.txt ; gocr -i a.jpg > sortie3.txt ; cuneiform a.jpg -f text -l fra -o so_ie4.txt ( 2 erreurs : _ au lieu de rt )

cuneiform
tesseract a.jpg sortie1 -I fra ; convert a.jpg a.ppm ; ocrad a.ppm > sortie2.txt ; gocr -i a.jpg > sortie3.txt ; cuneiform a.jpg -f text -I fra -o sortie4.txt ( 1 erreur : I au lieu de l )

[bruno sanchiz]