Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Why the Create method keep failing using Office 2007 OCR API?

by ZJ.Mike.2009 (Scribe)
on Mar 02, 2010 at 03:04 UTC ( #826058=note: print w/ replies, xml ) Need Help??


in reply to Re: Why the Create method keep failing using Office 2007 OCR API?
in thread Why the Create method keep failing using Office 2007 OCR API?

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


Comment on Re^2: Why the Create method keep failing using Office 2007 OCR API?
Select or Download Code
Re^3: Why the Create method keep failing using Office 2007 OCR API?
by Anonymous Monk on Mar 02, 2010 at 03:46 UTC
    "Item" is a method, you want something like:
    my $OCRresult = $miDoc->{Images}->Item(0)->{Layout}{Text};
      @Anonymous Monk, thanks a lot for the guidance. I tested the modified code with a MDI file that already has OCR information like so:
      $miDoc->Create('OCR-test-result.mdi'); my $OCRresult = $miDoc->{Images}->Item(0)->{Layout}{Text}; print $OCRresult;
      It outputs the expected result. But if I retain the OCR method like the original code did:
      $miDoc->Create('OCR-test.tif'); $miDoc->OCR(LangId =>'miLANG_ENGLISH'); my $OCRresult = $miDoc->{Images}->Item(0)->{Layout}{Text}; print $OCRresult;
      Perl throws me the same error message: Use of uninitialized value $OCRresult in print

      So now it looks like there's also something wrong with this line:

      $miDoc->OCR(LangId =>'miLANG_ENGLISH');
      What diagnostic method can I use to solve the problem. The following code gives me nothing:
      eval {$miDoc->OCR(LangId =>'miLANG_ENGLISH')}; warn $@ if $@;
      Thanks again :)
        $miDoc->{Images}->Item(0)->{Layout}{Text};
        is four operations, and each and every one can fail
        my $images = $miDoc->{Images} || die $^E; my $first = $images->Item(0) || die $^E; my $layout = $first->{Layout} || die $^E; my $text = $layout->{Text} || die $^E;
Re^3: Why the Create method keep failing using Office 2007 OCR API?
by ZJ.Mike.2009 (Scribe) on Mar 02, 2010 at 12:06 UTC
    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: note [id://826058]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2014-12-22 17:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (123 votes), past polls