info:ocr

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révision
Révision précédente
info:ocr [2014/02/19 15:17] – modification externe 127.0.0.1info:ocr [2024/05/16 02:51] (Version actuelle) radeff
Ligne 1: Ligne 1:
 ====== Reconnaissance optique de caractères ====== ====== Reconnaissance optique de caractères ======
 +utiliser tesseract (cf infra)
 ====== PDF > txt directement avec un script bash linux ====== ====== PDF > txt directement avec un script bash linux ======
 +requiert tesseract:
  
-un grand merci à Frans de Jonge pour son excellent script: http://fransdejonge.com/2012/04/ocr-text-in-pdf-with-tesseract/ +  sudo apt-get install tesseract-ocr tesseract-ocr-fra 
- +   
-<code> + <code> 
-#!/bin/bash +#!/usr/bin/bash 
-#ocrpdftotext +pdf_ocr2txt 
-# Simplified implementation of http://ubuntuforums.org/showthread.php?t=880471 +ls *.pdf | while read i 
-# mod Frans de Jong http://fransdejonge.com/2012/04/ocr-text-in-pdf-with-tesseract/ +do 
-# mod Fred Radeff, akademia.ch + echo "converting pdf file" $i " to tif file " $i.tif 
-# usage: ocrpdftotext PutYourFilename.pdf + convert -density 400 -depth 8 $$i.tif 
-# Might consider doing something with getopts here, see http://wiki.bash-hackers.org/howto/getopts_tutorial + echo "-----" 
-DPI=300 + echo "Generating txt file " $i.txt 
-#TESS_LANG=nld + tesseract $i.tif $i.txt -l fra 
-#adapt to french +done
-TESS_LANG=fra +
- +
-FILENAME=${@%.pdf} +
-SCRIPT_NAME=`basename "$0" .sh` +
-TMP_DIR=${SCRIPT_NAME}-tmp +
-OUTPUT_FILENAME=${FILENAME}-output@DPI${DPI} +
- +
-mkdir ${TMP_DIR} +
-cp ${@} ${TMP_DIR} +
-cd ${TMP_DIR} +
- +
-convert -density ${DPI} -depth 8 ${@} "${FILENAME}.tif" +
-tesseract "${FILENAME}.tif" "${OUTPUT_FILENAME}-l ${TESS_LANG} +
- +
-mv ${OUTPUT_FILENAME}.txt .. +
-rm * +
-cd .. +
-rmdir ${TMP_DIR}+
 </code> </code>
  
-absolument génial, de l'ordre de 90% et plus... jetez-vous dessus  
 ===== tesseract ===== ===== tesseract =====
  
 http://doc.ubuntu-fr.org/tesseract-ocr http://doc.ubuntu-fr.org/tesseract-ocr
  
-http://code.google.com/p/tesseract-ocr/+   convert -density 300 file.pdf -depth 8 file.tiff   
 +   tesseract file.tiff file.txt -l fra 
 +    
 +<code>#!/bin/sh 
 +echo "convertit un document pdf et réalise une reconnaissance optique de caractères" 
 +echo "entrer le nom du fichier" 
 +ls *.pdf 
 +read fichier 
 +echo "combien de pages?" 
 +read npages 
 +PAGES=$npages # set to the number of pages in the PDF 
 +SOURCE=$fichier # set to the file name of the PDF 
 +OUTPUT=$fichier.txt # set to the final output file 
 +RESOLUTION=600 # set to the resolution the scanner used (the higher, the better)
  
-marche nickel!+#xpdf-pdfinfo pamphlet-low.pdf | grep Pages: | awk '{print $2}' | tail -n 1
  
-par contre pas en russe, je suis à la recherche... y'a visiblement du monde qui y bosse:+#touch $OUTPUT 
 +for i in `seq 1 $PAGES`; do 
 +    convert -density $RESOLUTION -depth 8 $SOURCE\[$(($i - 1 ))\] page$i.png 
 +##    tesseract page$i.tif >> $OUTPUT 
 +    tesseract page$i.png $OUTPUT$i -l fra 
 +done</code>
  
-http://groups.google.com/group/tesseract-ocr-russian/+==== Liens ====
  
-http://groups.google.com/group/tesseract-ocr-russian/files+  * https://github.com/tesseract-ocr/tesseract/blob/main/README.md 
 +  * http://www.tristancollins.me/computing/ocr-using-tesseract-on-multipage-pdfs/ 
 +  * https://azlinux.fr/tesseract/|Comment utiliser Tesseract pour extraire du texte à partir d'images
  
-voir aussi:+marche nickel! 
 +===== GUI =====
  
-http://code.google.com/p/owlboxer/+Si on veut pas s'embêter avec la ligne de commande (et avec les formats de fichiers...) 
 +    sudo apt-get install gimagereader
  
 +{{:info:ksnip_20220816-115703.jpg?nolink|}}
  
-===== Old =====+si on veut du russe il faudra installer le dictionnaire 
 +    sudo apt install hunspell-ru 
 +et bien sûr le dico français si vous ne l'avez pas déjà 
 +    sudo apt install hunspell-fr    
  
-, ocrad et gocr tentent de rattraper le retard linuxien en matière d'OCR+===== Russe =====
  
-apt-get install ocrad gocr+  * https://pyimagesearch.com/2020/08/03/tesseract-ocr-for-non-english-languages/ 
 +  * https://github.com/tesseract-ocr/tessdata/blob/main/rus.traineddata
  
-Faut avouer que c'est moins performant que les produits windaube...+    mv rus.traineddata /usr/share/tesseract-ocr/4.00/tessdata/
  
-Un petit script pratique pour ocrad (que je préfère nettement à gocr, notamment plus rapide)+Ou encore plus simple 
 +    sudo apt-get install tesseract-ocr-rus
  
- +==== exemple de script bash pour le russe ==== 
-ocr.sh +<code bash    
-<code> +#!/usr/bin/bash 
-#! /bin/bash +# ocr-ruconvert (optical character recognition) jpg russian voc to text/csv file 
-# ocr.sh +usage: ocr-ru then translate it and drill it with anki 
-# Usage+copyleft radeff.red - use it at your own risk! 
-# ocr.sh +ladate=$(date +'%Y%m%d'
-script bash pour convertir des fichiers images en *.pbm et les traiter ensuite automatiquement avec le  +echo "ocr which russian image?" 
-# logiciel de reconnaissance optique de caractères (OCRocrad pour en extraire un fichier texte +ls *.jpg 
-# Required: convert, ocrad +read i 
-# FR, fradeff@akademia.ch, www.unige.ch +convert $i $i.png 
-# History  2008/10/29, created FR +tesseract $i.png $ladate -l rus 
-############ +rm $i.png 
-# se placer dans le répertoire dans lequel on a stocké les pages scannées ou photographièes, ici des fichiers JPG +echo "conversion ok, edit "$ladate".txt now
-mkdir pbm #cree un rep de travail +#delete empty lines 
-find . -name "*.JPG" | while read i #trouve les fichiers JPG +sed -'/^$/d' $ladate.txt 
-do +#delete line with only spaces 
- convert $i pbm/$i.pbm #les convertit dans un format accepte par ocrad via convert +sed -i '/^ *$/d' $ladate.txt 
-done +#delete end line with strange char from whatsapp 
-echo "Tous les fichiers images ont été convertis+sed -i '/^ $/d' $ladate.txt 
- +mv $ladate.txt $ladate.csv 
-cd pbm #va dans le rep de travail +geany $ladate".csv"& 
-find . | while read +
-do +
- ocrad $i >> result.txt #fait l'OCR +
-done +
- +
-echo "Voici le résultat:" +
-more result.txt+
 </code> </code>
- 
  • info/ocr.1392819434.txt.gz
  • Dernière modification : 2015/06/16 09:23
  • (modification externe)