ROC - mise en texte de l'image à l'aide de tesseract 3.0 et imagemagick 6.6.5

Je suis en train de construire un shell script qui me permet de rechercher du texte dans une image. Sur la base du texte, le script va essayer de son mieux pour obtenir le texte de l'image. Je voulais votre opinion sur ce que ce script semble fonctionner avec la plupart des images, mais pas les images où la police du texte, la couleur est de même pour les petits-environnement autour du texte.

# !/bin/bash
# 
# imt-ocr.sh is image magick tessearc OCR tool that is used for finding out text in image
#
# Arguments:
# 1     -- image filename (with path)
# 2     -- text to search in image      (default to '')
# 3     -- occurence of text            (default to 1)
# Usage:
# imt-ocr.sh [image_filename] [text_to_search] [occurence]
#

image=$1
txt=$2
occurence=$3    # Default to 1
if [ "$occurence" == "" ]
then
        occurence=1
fi

get_major_color ()
# Returns the major color of an image with its hex value
#       Parameter:      Image filename (with path)
#       Return format:  Returns a string "hex_val_of_color major_color_name"
{
convert $1 -format %c histogram:info: > x.txt
cat x.txt | awk '{print $1}' > x1.txt
h=$(sort -n x1.txt | tail -1);
color_info=$(cat x.txt | grep "$h" | cut -d '#' -f2)
rm -rf x.txt x1.txt
echo "$color_info"
}


invert_color()
# Inverts the color hex value
#       Parameter:      Hex value to be inverted
#       Return format:  Returns in hex
{
input_color_hex=$1                                              # Input color's hex value
white_color_hex=FFFFFF                                          # White color's  hex vlaue
inv_color_hex=`echo $(printf '%06X\n' $((0x$white_color_hex - 0x$input_color_hex)))`
echo $inv_color_hex
}


start_scale=100
end_scale=300
increment_scale=100
tmp_img=dst.tif
attempt=1
for ((scale=$start_scale, attempt=$attempt; scale <= $end_scale ; scale=scale+$increment_scale, attempt++))
        do
                echo "IMT-OCR-LOG: Scaling image to $scale% in attempt #$attempt"
                convert $image -type Grayscale -scale $scale% $tmp_img
                tesseract $tmp_img OUT
                found_oc=$(grep -o "$txt" OUT.txt | wc -l)
                echo "IMT-OCR-LOG: Found $found_oc occurence(s) of text '$txt' in attempt #$attempt"
                if [ $occurence -le $found_oc ] && [ $found_oc -ne 0 ]
                then
                        echo "IMT-OCR-LOG: Printing out the last text found on image"
                        echo "IMT-OCR-LOG: ======================================================"
                        cat OUT.txt
                        echo "IMT-OCR-LOG: ======================================================"
                        rm -rf $tmp_img OUT.txt
                        exit 1
                else
                        echo "IMT-OCR-LOG: Getting major color of image in attempt #$attempt"
                        color_info=`get_major_color $image`
                        true_color=$(echo $color_info | awk '{print $2}')
                        true_val=$(echo $color_info | awk '{print $1}')
                        echo "IMT-OCR-LOG: Major color of image is '$true_color' with hex value of $true_val in attempt #$attempt"

                        # Blur the image
                        echo "IMT-OCR-LOG: Bluring image in attempt #$attempt"
                        convert $tmp_img -blur 1x65535 $tmp_img

                        # Flip the color
                        inverted_val=`invert_color $true_val`
                        echo "IMT-OCR-LOG: Inverting the major color of image from 0x$true_val to 0x$inverted_val in attempt #$attempt"
                        convert $tmp_img -fill \#$inverted_val -opaque \#$true_val $tmp_img

                        # Sharpen the image
                        echo "IMT-OCR-LOG: Sharpening image in attempt #$attempt"
                        convert $tmp_img -sharpen 1x65535 $tmp_img

                        # Find text
                        tesseract $tmp_img OUT
                        found_oc=$(grep -o "$txt" OUT.txt | wc -l)
                        echo "IMT-OCR-LOG: Found $found_oc occurence(s) of text '$txt' in attempt #$attempt"
                        if [ "$found_oc" != "0" ]
                        then
                                if [ $occurence -le $found_oc ]
                                then
                                        echo "IMT-OCR-LOG: Printing out the last text found on image"
                                        echo "IMT-OCR-LOG: ======================================================"
                                        cat OUT.txt
                                        echo "IMT-OCR-LOG: ======================================================"
                                        rm -rf $tmp_img OUT.txt
                                        exit 1
                                fi
                        fi
                fi

                rm -rf OUT.txt

        done

rm -rf $tmp_img

Voici un exemple d'échantillon avec le problème,
image (test.jpeg) http://www.igoipad.com/wp-content/uploads/2012/07/03-Word-Collage-iPad.jpeg

[admin@ba-callgen image-magick-tesseract-processing]$ sh imt-ocr.sh test.jpeg Common
IMT-OCR-LOG: Scaling image to 100% in attempt #1
Tesseract Open Source OCR Engine with Leptonica
IMT-OCR-LOG: Found 0 occurence(s) of text 'Common' in attempt #1
IMT-OCR-LOG: Getting major color of image in attempt #1
IMT-OCR-LOG: Major color of image is 'grey96' with hex value of F5F5F5 in attempt #1
IMT-OCR-LOG: Bluring image in attempt #1
IMT-OCR-LOG: Inverting the major color of image from 0xF5F5F5 to 0x0A0A0A in attempt #1
IMT-OCR-LOG: Sharpening image in attempt #1
Tesseract Open Source OCR Engine with Leptonica
IMT-OCR-LOG: Found 0 occurence(s) of text 'Common' in attempt #1
IMT-OCR-LOG: Scaling image to 200% in attempt #2
Tesseract Open Source OCR Engine with Leptonica
IMT-OCR-LOG: Found 1 occurence(s) of text 'Common' in attempt #2
IMT-OCR-LOG: Printing out the last text found on image
IMT-OCR-LOG: ======================================================
Settings M...
Text
Common words
Exclude numbers
word case
Theme & Layuul
Color theme
Fnnl
Word layout
Clrien lalion
7301
Lrmclsc ape
\u2018OTC
Ergl sw v.-ords >
li( `
I):Jntc1'\:1r\qa )
Landon Spring >
Hough Trad >
H3'fJ|1d :-Ialf >
H L

IMT-OCR-LOG: ======================================================
[admin@ba-callgen image-magick-tesseract-processing]$ 
[admin@ba-callgen image-magick-tesseract-processing]$ 
[admin@ba-callgen image-magick-tesseract-processing]$ 
[admin@ba-callgen image-magick-tesseract-processing]$ 
[admin@ba-callgen image-magick-tesseract-processing]$ 
[admin@ba-callgen image-magick-tesseract-processing]$ 
[admin@ba-callgen image-magick-tesseract-processing]$ sh imt-ocr.sh test.jpeg Portrait
IMT-OCR-LOG: Scaling image to 100% in attempt #1
Tesseract Open Source OCR Engine with Leptonica
IMT-OCR-LOG: Found 0 occurence(s) of text 'Portrait' in attempt #1
IMT-OCR-LOG: Getting major color of image in attempt #1
IMT-OCR-LOG: Major color of image is 'grey96' with hex value of F5F5F5 in attempt #1
IMT-OCR-LOG: Bluring image in attempt #1
IMT-OCR-LOG: Inverting the major color of image from 0xF5F5F5 to 0x0A0A0A in attempt #1
IMT-OCR-LOG: Sharpening image in attempt #1
Tesseract Open Source OCR Engine with Leptonica
IMT-OCR-LOG: Found 0 occurence(s) of text 'Portrait' in attempt #1
IMT-OCR-LOG: Scaling image to 200% in attempt #2
Tesseract Open Source OCR Engine with Leptonica
IMT-OCR-LOG: Found 0 occurence(s) of text 'Portrait' in attempt #2
IMT-OCR-LOG: Getting major color of image in attempt #2
IMT-OCR-LOG: Major color of image is 'grey96' with hex value of F5F5F5 in attempt #2
IMT-OCR-LOG: Bluring image in attempt #2
IMT-OCR-LOG: Inverting the major color of image from 0xF5F5F5 to 0x0A0A0A in attempt #2
IMT-OCR-LOG: Sharpening image in attempt #2
Tesseract Open Source OCR Engine with Leptonica
IMT-OCR-LOG: Found 0 occurence(s) of text 'Portrait' in attempt #2
IMT-OCR-LOG: Scaling image to 300% in attempt #3
Tesseract Open Source OCR Engine with Leptonica
IMT-OCR-LOG: Found 0 occurence(s) of text 'Portrait' in attempt #3
IMT-OCR-LOG: Getting major color of image in attempt #3
IMT-OCR-LOG: Major color of image is 'grey96' with hex value of F5F5F5 in attempt #3
IMT-OCR-LOG: Bluring image in attempt #3
IMT-OCR-LOG: Inverting the major color of image from 0xF5F5F5 to 0x0A0A0A in attempt #3
IMT-OCR-LOG: Sharpening image in attempt #3
Tesseract Open Source OCR Engine with Leptonica
IMT-OCR-LOG: Found 0 occurence(s) of text 'Portrait' in attempt #3
[admin@ba-callgen image-magick-tesseract-processing]$ 

Comme vous pouvez le voir je peut trouver le texte "commun", mais pas "Portrait". La raison est à cause de la couleur de la police du Portrait. Toute aide pour améliorer ce script...

J'utilise Centos 5.

  • Le problème que vous décrivez n'est pas le seul. Certains de l'autre les mots ne sont pas correctement identifiés. Je voudrais d'abord essayer d'obtenir ceux correct, peut-être, qui serait utile pour le "Portrait" de recherche ainsi...
  • Conseil amical: vous devriez envisager d '"accepter" et/ou "upvote" davantage de les réponses que vous avez reçues de vos questions précédentes. Ce qui permettrait d'augmenter la volonté des gens à mettre de l'effort de penser à abou vos problèmes...
  • BTW, sur mon système (Mac OS X Lion, avec tesseract v3.01 et ImageMagick v6.7.8-3 2012-07-30 Q16) ma reconnaissance résultats sont meilleurs que ceux que vous avez cité. Par exemple: je ne reçois Orientation où vous obtenez Clrien lalion... Qui tesseract version est sur votre Centos 5? Qui ImageMagick version?
  • Oh, je vois les versions sont mentionnés dans le titre. Jamais l'esprit...
  • Merci Kurt. J'ai réellement faire accepter et upvote réponses/commentaires... Alors, concernant le texte de l'analyse, il dépend entièrement de la façon dont l'image a été mis en forme afin que le tesseract peut détecter facilement le texte. Maintenant, la principale préoccupation est seulement dans les endroits où la police du texte se mélange avec le majeur de fond. Pour cela, dans mon application, je suis en train de l'agrandir, de flou, de changer la couleur... c'est la clé de la logique!! Donc, j'ai pensé à une autre solution qui fonctionne uniquement à partir d'un point de vue théorique. Veuillez lire le commentaire suivant...
  • L'autre solution est de séparer l'image fondée sur des blocs de couleurs. Ce que j'ai remarqué, c'est que, si le tesseract est donné qu'à l'image (image recadrée) contenant le Portrait, il peut facilement détecter. Donc, l'idée est de séparer l'image fondée sur des blocs de couleur quelque chose de similaire à fmwconcepts.com/imagemagick/separate/index.php, mais je n'ai pas réussi à mettre en œuvre cette solution, car la séparation de l'image en fonction de la couleur n'est pas facile... Qu'en pensez-vous?
  • Je comprends... mes questions sont difficiles à répondre, je crois... Tout cas, j'ai essayé de répondre à toutes mes questions au meilleur de mes capacités....
  • Quel est votre véritable objectif? "Construire un générique OCR script qui reconnaît ce que je jeter à elle, même multi-couleur des captures d'écran." ? Ou plutôt: "Construire un ROC script que des extraits de textes de l'iPad captures d'écran à l'aide de la typique iPad de couleurs." ??
  • Ok, le but réel est d'extraire du texte à partir de n'importe quel capture d'écran des images de téléphone android (j'ai juste pris l'exemple de l'ipad que c'est la 1ère chose que j'ai vu en ligne)!! Maintenant, le téléphone android ne dispose que d'une quantité limitée de texte, mais ces textes ont différentes couleurs et il est vraiment difficile de trouver ces textes avec la couleur de la police qui correspondent à fond!! Les Images comme les technixupdate.com/wp-content/uploads/images/... !! Est-il possible de former tesseract par hasard... ce qui signifie n'ont que peu de jeu de mots dans son dictionnaire... juste une suggestion
  • Oui, vous pouvez vous entraîner Tesseract depuis la version 2.00: code.google.com/p/tesseract-ocr/wiki/TrainingTesseract3

InformationsquelleAutor abarik | 2012-08-16