tesseract 编译与使用(windows)

原文转载于:https://www.cnblogs.com/kappaboy/p/5910226.html

tesseract是google的一个开源OCR项目,项目地址已经迁移到github(现在 2016/09),地址 https://github.com/tesseract-ocr/tesseract

 

首先使用git将代码clone到本地。使用最新的commit, SHA-1: c943fc1a339d6378f34cccf4ff96949adb2f37ec

编译步骤参考 https://github.com/tesseract-ocr/tesseract/wiki/Compiling

下面是详细步骤和相关问题解决方法

我使用的VS2010

 

1.安装cmake 并添加到环境变量.下载地址 https://cmake.org/download/

2.安装cppan 并添加到环境变量,下载地址 https://cppan.org/client/cppan-master-win32-client.zip

3.在你本地的源码目录tesseract下执行下列命令

1
2
3
cppan
mkdir  build &&  cd  build
cmake .. -DSTATIC=1

 

注意:cppan执行过程中可能需要FANQIANG。

4.在tesseract\build目录下生成了项目文件,使用VS打开tesseract.sln,如下

 

启动项目是ALL_BUILD,解决方案配置我使用的是 Release。开始编译,当然这过程中会出现一大堆错误和警告,不用理会静静等待编译完成

1.使用可以转换编码格式的工具,将 tesseract\ccmain\equationdetect.cpp 的格式转化下。 我使用的是 Notepad ++ ,格式->转为 ANSI 编码格式

原因:tesseract的源文件的编码格式是UTF-8的,但是中文系统下VS里的代码页编码格式是GB2312

 

2.bool相关,根据错误信息定位到pvt.cppan.demo.gif这个项目,我的是 pvt.cppan.demo.gif-5.1.4.vcxproj ,双击打开之,然后在项目中找到 stdbool.h,然后将

#define bool    _bool

更换为

#define bool    int

 

3. snprintf相关,根据错误信息定位到pvt.cppan.demo.tiff这个项目,我的是 pvt.cppan.demo.tiff-4.0.6,双击打开之,然后在项目中找到  tiffiop.h ,定位到

#if !defined(HAVE_SNPRINTF) && !defined(HAVE__SNPRINTF)
#undef snprintf

将下面的3行换成

#define snprintf _snprintf
//extern int snprintf(char* str, size_t size, const char* format, ...);
#endif

 

然后切换到 tesseract.sln ,清理解决方案重新编译一遍。

 

然后将 tesseractmain 设为启动项目,编译。

 

编译步骤到此结束,可执行文件在 tesseract\build\bin\Release 下,但是现在还不能直接用,没有语言包。

语言包下载地址

英文 https://github.com/tesseract-ocr/tessdata/raw/master/eng.traineddata
简中 https://github.com/tesseract-ocr/tessdata/raw/master/chi_sim.traineddata 
繁中 https://github.com/tesseract-ocr/tessdata/raw/master/chi_tra.traineddata

 

创建一个tessdata目录,和tesseract.exe同级,将下载的语言包复制到tessdata目录下。然后打开cmd,执行命令就可以看到结果

 

tesseract.exe test.png -l eng+chi_sim result

 

test.png 是待识别的图片

-l eng+chi_sim 指定识别语言为英文和简体中文,多语言使用+连接

result 指定输出的文本文件

 

 

 

更多的命令请参考 https://github.com/tesseract-ocr/tesseract/wiki/Command-Line-Usage

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值