Prova questo (che ha lavorato con me):
$imagick = new Imagick($filePath);
$size = $imagick->getImageGeometry();
$width = $size['width'];
$height = $size['height'];
unset($size);
$textBottomPosition = $height-1;
$textRightPosition = $width;
$black = new ImagickPixel('#000000');
$gray = new ImagickPixel('#C0C0C0');
$textRight = 0;
$textLeft = 0;
$textBottom = 0;
$textTop = $height;
$foundGray = false;
for($x= 0; $x < $width; ++$x) {
for($y = 0; $y < $height; ++$y) {
$pixel = $imagick->getImagePixelColor($x, $y);
$color = $pixel->getColor();
// remove alpha component
$pixel->setColor('rgb(' . $color['r'] . ','
. $color['g'] . ','
. $color['b'] . ')');
// find the first gray pixel and ignore pixels below the gray
if($pixel->isSimilar($gray, .25)) {
$foundGray = true;
break;
}
// find the text boundaries
if($foundGray && $pixel->isSimilar($black, .25)) {
if($textLeft === 0) {
$textLeft = $x;
} else {
$textRight = $x;
}
if($y < $textTop) {
$textTop = $y;
}
if($y > $textBottom) {
$textBottom = $y;
}
}
}
}
$textWidth = $textRight - $textLeft;
$textHeight = $textBottom - $textTop;
$imagick->cropImage($textWidth+10, $textHeight+10, $textLeft-5, $textTop-5);
$imagick->scaleImage($textWidth*10, $textHeight*10, true);
$textFilePath = tempnam('/temp', 'text-ocr-') . '.png';
$imagick->writeImage($textFilePath);
$text = str_replace(' ', '', shell_exec('gocr ' . escapeshellarg($textFilePath)));
unlink($textFilePath);
var_dump($text);
È necessario estensione ImageMagick e GOCR installati per eseguirlo. Se non puoi o non vuoi installare l'estensione ImageMagick, ti invierò una versione GD con una funzione per calcolare le distanze dei colori (è solo un esteso Teorema di Pitagora).
Non dimenticare di impostare il valore $ filePath.

L'immagine mostra che sembra per un pixel grigio per cambiare la bandiera $ foundGray. Successivamente, cerca il primo e l'ultimo pixel da sinistra e dall'alto. Ritaglia l'immagine con un po 'di padding, l'immagine risultante viene ridimensionata e salvata in un file temporaneo. Dopodiché, è facile usare gocr (o qualsiasi altro comando OCR o libreria). Il file temporaneo può essere rimosso dopo.
fonte
2014-10-06 20:07:08
Perché non funziona? Ricevi alcuni messaggi di errore? – Alex2php
Entrambi gli script non hanno letto testo e numeri .. Esempio: EUR42450.92 >> l'output è come: 787988 .. Voglio così; http://www.free-ocr.com/.com/italiano – Bora
tesseract (http://code.google.com/p/tesseract-ocr/) è una libreria/programma OCR opensource. Ho avuto risultati abbastanza decenti con esso. –