in reply to Re: Perl intepreter crash when tyring to get the text from OCRed output
in thread Perl intepreter crash when tyring to get the text from OCRed output

As refered to the issue posted by me, Please Check the latest code

sub ApplyOCR{ my $TiffImageLocation = $_[0]; my $OCRResult; print "InitOnce : $InitOnce\n"; if ($InitOnce == 0) { $InitOnce = 1; #### To make it one time initialization $miDoc = Win32::OLE->new('MODI.Document') or die "Cannot crea +te a MODI object"; print "miDoc : $miDoc\n"; } #### Creat the new document $miDoc->Create("$TiffImageLocation"); $miDoc->OCR(9,1,1); $miDoc->Save(); # print "Save object\n"; # print Dumper ($miDoc); # print "\n"; try{ my $ImageDoc = $miDoc->{Images}; if (defined $ImageDoc){ $OCRResult = $miDoc->{Images}->Item(0)->{Layout}{Text}; #### Close the opened document $miDoc->Close(); return $OCRResult; }else{ if ($DebugMsg == 1){ print "OCR cannot be done on this image in $TiffImageL +ocation\n"; #comment to debug- this is the message and } return 1; } }catch{ my $err = shift; warn "Some other kind of error in try: $err\n"; throw $err; if ($DebugMsg == 1){ print "OCR cannot be done on this image in $TiffImageLocat +ion\n"; #comment to debug- this is the message and } return 1; } }

For the tiff image which has not text content in it, then the code breaks at line 25. Since it has no text content the $miDoc don't have the property item(0). Please help me how to capture this error/exception.

  • Comment on Re^2: Perl intepreter crash when tyring to get the text from OCRed output
  • Download Code