完整安裝office時,
會順帶安裝一個Microsoft Office Document Imaging程式,
這個程式個以用OLE的方式來叫用做OCR的工作
在windows XP, office 2003下可正常運作
use warnings;
use strict;
use Win32::OLE;
use Win32::OLE::Const;
my $filename= $ARGV[0];
my $type= $ARGV[1] || 1;
Win32::OLE::Const->Load('Microsoft Office Document Imaging 11.0 Type Library') or die;
my $miDoc = Win32::OLE->new('MODI.Document') or die "Cannot create a MODI object";
##載入tif檔案
$miDoc->Create($filename);
##type: 1英文 1028繁體中文
if($type == 1){
$miDoc->OCR(9,1,1);
}elsif($type == 2){
$miDoc->OCR(1028,1,1);
}
##印出第一頁
my $OCRresult = $miDoc->{Images}->Item(0)->{Layout}{Text};
print $OCRresult;
##印出第二頁
##$OCRresult = $miDoc->{Images}->Item(1)->{Layout}{Text};
##print $OCRresult;
參考資料:
what-other-diagnostic-methods-can-i-use-to-solve-this-particular-perl-problem
http://msdn.microsoft.com/en-us/library/aa202819%28office.11%29.aspx
- Dec 16 Thu 2010 09:55
用Office Document Imaging來做OCR--perl
全站熱搜
留言列表
禁止留言