目前有很多OCR工具或者类库都提供了准确率挺高的PDF和图片识别功能。在爬虫应用中,时常需要识别验证码或者目标站点处于数据保护而使用图片来替代直接的文本。除了直接的软件和类库外,还有一些在线工具可以直接识别,使用free online ocrGooglr可以搜索到下面这几个:
http://www.onlineocr.net/
http://www.free-ocr.com/
http://www.ocrconvert.com/
https://www.newocr.com/
众多的工具中,有个wiki页面做了比较详细的比较:

详细内容请参考Comparison_of_optical_character_recognition_software。
在众多软件中,Google出品的Tesseract口碑不错,有些人认为是所有OCR软件中准确率最高的,甚至比一些商业软件还高。Google的论文中给出了如下的准确度:

Tesseract是C/C++写的库,但是很多语言都有相应的包装器(wrapper),具体请参考Tesseract的Github。
下面我们以Java的包装器tess4j为例说明:
首先添加maven依赖:
<dependency> <groupId>net.sourceforge.tess4j</groupId> <artifactId>tess4j</artifactId> <version>3.2.0</version> </dependency>
然后写个测试类:
public static void main(String[] args) {
File imageFile = new File("F:/air-img/full/71-arrival.jpg");
ITesseract instance = new Tesseract(); // JNA Interface Mapping
// ITesseract instance = new Tesseract1(); // JNA Direct Mapping
instance.setDatapath("C:/tess4j-3.2.0/tessdata");
try {
String result = instance.doOCR(imageFile);
System.out.println(result);
} catch (TesseractException e) {
System.err.println(e.getMessage());
}
}
需要设置一下Tessaract的模型数据的目录:
instance.setDatapath("C:/tess4j-3.2.0/tessdata");
模型数据可以从官网中下载到。识别的结果以字符串形式输出,看看效果。
关于Tesseract的调优,参考ImproveQuality。
如果想自己训练模型,参考TrainingTesseract。
可以加一下854630135这个群去交流一下噢
来源:oschina
链接:https://my.oschina.net/u/3990817/blog/2396326