一、Tesseract-OCR 是什么
An OCR Engine that was developed at HP Labs between 1985 and 1995… and now at Google
基于Leptonica(http://leptonica.com/)图形处理库开的开源图形识别引擎。
支持Linux、Windows、Mac平台,
支持.NET、C++、Python、Java等开发语言:https://code.google.com/p/tesseract-ocr/wiki/AddOns
项目地址:https://code.google.com/p/tesseract-ocr/
二、使用方法
下载安装:https://tesseract-ocr.googlecode.com/files/tesseract-ocr-setup-3.02.02.exe
注意安装时的Path目录、数学符号、语言选项,按需选择。
执行:”tesseract yourpic.png res”
图片 yourpic.png 里面的内容会被识别后保存在 res.txt
为了更精确的识别可以去到项目地址上下载相应的各种语言的 language tessdata
例如:
简体中文 https://tesseract-ocr.googlecode.com/files/tesseract-ocr-3.02.chi_sim.tar.gz
繁体中文
下载解压后 chi_sim.traineddata 复制到 Tesseract-OCR/tessdata 即可
执行:
“tesseract yourpic.png eng” 使用 默认eng语言包
“tesseract yourpic.png sim -l chi_sim” 使用 chi_sim语言包
“tesseract yourpic.png tra -l chi_tra” 使用 chi_sim语言包
选择最接近真实数据的,方便以后修正
三、进阶使用 Training
为数不多的training tesseract-ocr中文文档
http://yy-programer.blogspot.tw/2012/08/training-tesseract-ocr-301.html
对于高精度需求的需要研究一下了,日常民用级别,默认识别加后期修正即可。
四、应用实例之吸附代理
针对 http://www.proxyfire.net/ 几个代理列表页的代理吸附
话不多说直接上代码,
pf.bat
代码如下:
pf.pl http://www.proxyfire.net/index.php?pageid=eliteproxylist elite.txt
pf.pl http://www.proxyfire.net/index.php?pageid=anonymousproxylist anony.txt
pf.pl http://www.proxyfire.net/index.php?pageid=transparentproxylist trans.txt
pf.pl http://www.proxyfire.net/index.php?pageid=socks4proxylist s4.txt
pf.pl http://www.proxyfire.net/index.php?pageid=socks5proxylist s5.txt
type *.txt > all.tmp
del *.txt /s/q
ren all.tmp all.txt
@pause
pf.pl
代码如下:
use strict;
our $url = $ARGV[0];
our $file = $ARGV[1];
my $res = undef;
my @tmp = undef;
my @pxy = undef;
`wget $url -q -O ___html`;
open FH, "<___html";
@tmp = ;
close FH;
$res = join('',@tmp);
undef(@tmp);
`del ___html /s /q`;
@tmp = ( $res =~ /<img alt="" src="([^" border="0">]+)><//td>(/d+)'http://www.proxyfire.net'.$tmp[$i], 'port'=>$tmp[$i+1]};
新闻热点
疑难解答