Comparing AWS Textract and AWS Rekognition to extract text from images using PHP

A few months ago I tried using AWS Rekognition to detect text in images. The results were okay for casual use cases but overall the quality was pretty poor (primarily because Rekognition isn’t intended to be used as an OCR product).

A few days ago (May 29), AWS announced the general availability of Textract, an actual OCR product. Out of curiosity, I wanted to run the same image I ran through Rekognition through Textract to compare the difference. While Textract isn’t 100%, it’s a huge improvement over Rekognition (as should be expected since it’s intended for this).

Below is a side-by-side comparison of the results from the two services:

Textract ResultsRekognition Results
DetectedTextConfidenceDetectedTextConfidence
DANS PUMP AND GO98%DANS PLMP AND GO98%
15238 MAIN ST99%15238 MAIN ST100%
NEWTOWN100%NEWTOWN100%
CAROLINA 9381296%CAROLINA 9381297%
ST-TX: 1108998499%ST-TX: 11089987 (555) 708-222498%
(555) 708-2224100%
2014-02-25 IW424534:9338300 07:0999%2014-02-25 TW420534: 34:9338300 07:0994%
TERMINAL: 509338300 OPER: A89%TERMINAL: 509338300 OPER: A99%
Fuel99%Fuel (G) ($/G)99%
(G) ($/G)98%
($)95%($)99%
Pump 980%Pump 997%
Premium93%Prem ium 40.000 1.345 53.80*98%
40.000 1.345 53.80*98%
Total Owed97%Total Owed 53.8098%
53.8100%
TOTAL PAID100%TOTAL PAID100%
CREDIT CARD100%CREDIT CARD 53.8099%
53.899%
VISA100%VISA *kkkkkkkkkkk459798%
$4,444,444,440,59758%
INV. 972821 AUTH. 54563399%INV. 972821 AUTH. 54563399%
Purchase98%Purchase100%
S 0010010010 00 12789%S 001001001098%
00 APPROVED – THANK YOU92%
94%
IMPORTANT100%
95%
Retain This Copy For Your Records100%

As always, here’s my source used for this test:

<?php
require '/home/bitnami/vendor/autoload.php'; 

use Aws\Textract\TextractClient;
use Aws\Exception\AwsException;

$client = new TextractClient([
'version' => 'latest',
'region' => 'us-west-2',
'credentials' => [
  'key' => '', //IAM user key
  'secret' => '', //IAM user secret
]]);

try{
  $result = $client->detectDocumentText([
    'Document' => [
      'S3Object' => [
        'Bucket' => 'fkrekognition',
        'Name' => 'receipt_preview.jpg'
      ],
    ],
  ]);
} catch (AwsException $e){
  echo "<pre>Error: $e</pre>";
}

echo "<h1>Textract</h1>";
echo "<img src=https://s3-us-west-2.amazonaws.com/fkrekognition/receipt_preview.jpg><br />";
$i=0;
echo "<table border=1 cellspacing=0><tr><td>#</td><td>BlockType</td><td>Text</td><td>Confidence</td></tr>";
foreach ($result['Blocks'] as $phrase) {
  if($phrase['BlockType']=="LINE"){
    $i++;
    echo "<tr><td>$i</td><td>".$phrase['BlockType']."</td><td>".$phrase['Text']."</td><td>".round($phrase['Confidence'])."%</td></tr>";
  }
}
echo "</table>";
  
echo "<h1>Raw Output</h1><pre>";
print_r($result);
echo "</pre>";
?>

 


Discover more from Weekend Enthusiast

Subscribe to get the latest posts sent to your email.

Leave a Reply