Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Why the Create method keep failing using Office 2007 OCR API?

by ZJ.Mike.2009 (Scribe)
on Mar 01, 2010 at 11:53 UTC ( #825880=perlquestion: print w/ replies, xml ) Need Help??
ZJ.Mike.2009 has asked for the wisdom of the Perl Monks concerning the following question:

I'm following an article (http://www.codeproject.com/KB/office/OCRSampleApplication.aspx) to try using OCR in ActivePerl 5.10.0 but without any luck. The following minimal code keeps failing at the Create step and I don't understand why. Any idea what's going on? Thanks :)

use warnings; use strict; use Win32::OLE; use Win32::OLE::Const; Win32::OLE::Const->Load("Microsoft Office Document Imaging 12\.0 Type +Library") or die "Cannot use the Office 2007 OCR API"; my $miDoc = Win32::OLE->new('MODI.Document') or die "Cannot create a M +ODI object"; $miDoc->Create('E:/ocr-test.tif') or die "Cannot open the file for OCR +";

Comment on Why the Create method keep failing using Office 2007 OCR API?
Download Code
Re: Why the Create method keep failing using Office 2007 OCR API?
by RyuMaou (Deacon) on Mar 01, 2010 at 15:05 UTC
    When it fails, does it kick back a message that might point us in a direction?

      RyuMaou, thank you for the readiness to help and sorry, I think I have made a mistake there. Now it looks like the Create method is actually okay. I've realized that it loads the file just fine. But something is wrong with this line:

      my $OCRresult = $miDoc->{Images}{'Item(0)'}{Layout}{Text};

      I'm not sure how to write the following the Perl way.

      expression.Item(Index)

      Following is the whole test script.

      use warnings; use strict; use Win32::OLE; use Win32::OLE::Const; Win32::OLE::Const->Load("Microsoft Office Document Imaging 12\.0 Type +Library") or die "Cannot use the Office 2007 OCR API"; my $miDoc = Win32::OLE->new('MODI.Document') or die "Cannot create a M +ODI object"; $miDoc->Create('OCR-test.tif'); $miDoc->OCR(LangId =>'miLANG_ENGLISH'); my $OCRresult = $miDoc->{Images}{'Item(0)'}{Layout}{Text}; print $OCRresult;
      Perl gives me the following error message:
      Use of uninitialized value $OCRresult in print
        "Item" is a method, you want something like:
        my $OCRresult = $miDoc->{Images}->Item(0)->{Layout}{Text};
        Problem solved. Something is wrong with my MODI 12.0 and I also messed with the OCR method parameters. Changing the line:
        $miDoc->OCR();
        to
        $miDoc->OCR(2052,1,1); #2052 is the LangId for Chinese
        can solve the problem but somehow if I use
        $miDoc->OCR(9,1,1); #9 is the LangId for English
        Windows XP would throw me an error saying:
        unknown software exception
        Anyway, thank you guys! I'm really happy that the problem is gone :D

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://825880]
Approved by rovf
Front-paged by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (10)
As of 2014-07-28 12:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (196 votes), past polls