This is the output from my attempt to OCR a picture:

Hello! Starting OCR operation....

check for simplexml_load_string(): OK

$post_array contents is: array(1) { ["my_file"]=> string(46) "@D:\wwwroot\htdocs\mobicomp/preOCR/hejhopp.jpg" }

response:

xml:

first...: object(SimpleXMLElement)#1 (1) { ["task"]=> object(SimpleXMLElement)#4 (1) { ["@attributes"]=> array(7) { ["id"]=> string(36) "16743fc4-acbc-4302-a054-707cc6e4f14f" ["registrationTime"]=> string(20) "2012-06-04T21:34:17Z" ["statusChangeTime"]=> string(20) "2012-06-04T21:34:17Z" ["status"]=> string(6) "Queued" ["filesCount"]=> string(1) "1" ["credits"]=> string(1) "5" ["estimatedProcessingTime"]=> string(1) "1" } } }

end of first...:

iteration 1: object(SimpleXMLElement)#6 (1) { ["task"]=> object(SimpleXMLElement)#2 (1) { ["@attributes"]=> array(6) { ["id"]=> string(36) "16743fc4-acbc-4302-a054-707cc6e4f14f" ["registrationTime"]=> string(20) "2012-06-04T21:34:17Z" ["statusChangeTime"]=> string(20) "2012-06-04T21:34:18Z" ["status"]=> string(16) "ProcessingFailed" ["filesCount"]=> string(1) "1" ["credits"]=> string(1) "5" } } }*

Newlines and bold font have been edited manually...

The problem is that ProcessingFailed. I managed to OCR the exact same picture (and another one that this script doesn't work for either) with the online OCR service. Hints anyone?

php-code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Hitta b&auml;st abbonemanget f&ouml;r dig.</title>
</head>
<body>

</body>
</html>
<BR> <BR>
Hello! Starting OCR operation.... <BR> <BR>

<?php

//checking for simple_xml_load_string
echo 'check for simplexml_load_string(): ';
if (function_exists(simplexml_load_string)){echo 'OK';} else {echo'NOK';};
echo '<br><br>';

  // 1. Send image to Cloud OCR SDK using processImage call
  // 2. Get response as xml
  // 3. Read taskId from xml

  // !!!!!!!!!! Enter your data here !!!!!!!!!!
  $applicationId = 'XXXXXXXX';
  $password = 'XXXXXXXX';
  $fileName = 'hejhopp.jpg';

  // Get path to file that we are going to recognize
  $local_directory=dirname(__FILE__).'/preOCR';

  // Recognizing with English language to rtf
  // You can use combination of languages like ?language=english,russian or
  // ?language=english,french,dutch
  // For details, see API reference for processImage method
  $url = 'http://cloud.ocrsdk.com/processImage';

  // Send HTTP POST request and ret xml response
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_USERPWD, "$applicationId:$password");
  curl_setopt($ch, CURLOPT_POST, 1);
  $post_array = array(
      "my_file"=>"@".$local_directory.'/'.$fileName,
  );
    echo '$post_array contents is:  ';
    var_dump($post_array);
  echo '<br>';

    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_array); 
  $response = curl_exec($ch);
  curl_close($ch);

    echo '<br>response: '.$response.'<br>';
    echo 'xml: '; 
      print_r($xml);
        echo'<br>';

  // Parse xml response
  $xml = simplexml_load_string($response);
  $arr = $xml->task[0]->attributes();

    echo '<br><br>first...: <br><br>';
    var_dump($xml);
    echo '<br><br>end of first...: <br><br>';

  // Task id
  $taskid = $arr["id"];

  // 4. Get task information in a loop until task processing finishes
  // 5. If response contains "Completed" staus - extract url with result
  // 6. Download recognition result (text) and display it

  $url = 'http://cloud.ocrsdk.com/getTaskStatus';
  $qry_str = "?taskid=$taskid";

  // Check task status in a loop until it is finished
  // TODO: support states indicating error
    $iter=1;
  do
  {
    echo 'iteration '.$iter.': ';
        echo '                                                  ';
        echo '                                                  ';
        echo '                                                  ';
        echo '                                                  ';
        echo '                                                  ';
        flush();
        sleep(1);
        $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url.$qry_str);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERPWD, "$applicationId:$password");
    $response = curl_exec($ch);
    curl_close($ch);

    // parse xml
    $xml = simplexml_load_string($response);
    $arr = $xml->task[0]->attributes();
        var_dump($xml);
        echo '<BR><BR><BR><BR>';
        $iter++;
  }
  while($arr["status"] != "Completed");

  // Result is ready. Download it

  $url = $arr["resultUrl"];   
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $response = curl_exec($ch);
  curl_close($ch);

  // Let user donwload rtf result
  header('Content-type: application/rtf');
  header('Content-Disposition: attachment; filename="file.rtf"');
  echo $response;

?>
</body>
</html>
<?php
?>

asked 05 Jun '12, 02:05

navarra's gravatar image

navarra
112

edited 09 Jun '12, 11:14

Vasily%20Panferov's gravatar image

Vasily Panferov ♦♦
5422517


ProcessingFailed status is returned when the service fails to process a specific task. That usually happens due to an internal error and in such cases it is not the user's fault but the service's fault. Because of this details of what exactly went wrong are not useful for the user and so are not returned to the user, yet they are logged.

If you're concerned about some specific image not being processed please contact the team using the feedback e-mail address displayed in the service dashboard. You'll have to provide the problematic image and the processing parameters so that the team can investigate the problem and make appropriate changes to the service if needed.

link

answered 05 Jun '12, 14:52

Dmitry%20Me's gravatar image

Dmitry Me ♦♦
2387

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×60
×33
×3

Asked: 05 Jun '12, 02:05

Seen: 1,950 times

Last updated: 09 Jun '12, 11:14

© 2016 ABBYY. All rights Reserved. www.ABBYY.com | Privacy Policy | Legal