OCR开源程序tesseract_C/C++_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > C/C++ > OCR开源程序tesseract

OCR开源程序tesseract

 2011/1/12 8:43:11  lywybo  http://lywybo.javaeye.com  我要评论(0)
  • 摘要:http://www.huangshifu.net/2010/01/29/ocr-stuff.htmlhttp://muyublog.appspot.com/2010/09/9/imagemagick-tesseract-recognize-verify-code.htmlhttp://blog.csdn.net/foamflower/archive/2010/12/31/6110211.aspx下载:http://code.google.com/p/tesseract
  • 标签:程序 开源
http://www.huangshifu.net/2010/01/29/ocr-stuff.html
http://muyublog.appspot.com/2010/09/9/imagemagick-tesseract-recognize-verify-code.html
http://blog.csdn.net/foamflower/archive/2010/12/31/6110211.aspx


下载:http://code.google.com/p/tesseract-ocr/downloads/list
安装
解包之后老规矩 ./configure ,make最后make install .大功告成。
测试
安装完直接执行tesseract 会出错:Unable to load unicharset file ./tessdata/eng.unicharset

程序抱怨说没能找到语言库,找到tesseract-2.00.eng.tar.gz,下载解压到tessdata目录,

找个jpg试试。
执行:tesseract in.jpg result
提示:Tesseract Open Source OCR Engine
name_to_image_type:Error:Unrecognized image type:in.jpg
IMAGE::read_header:Error:Can’t read this image type:in.jpg
tesseract:Error:Read of file failed:in.jpg

原来是不支持jpg的,汗一个。
用imagemagick转换一下,转换为tif:convert -compress none in.jpg in.tif
必须加上参数-compress none, 默认转换会有压缩,tesseract就会报错:read_tif_image:Error:Illegal image format:Compression

执行结果输出了result.txt

为提高识别率,可以先把图片转换为灰度。即弄黑白的:

convert -compress none  -monochrome in.tif in2.tif

也可以用-colorspace Gray,用这个参数图片质量会更好点。

以下在windows下作了个小测试,100分。



挑战




现在要识别上面图片的数字。

值得注意的是,类似这种数字比较小的,完全识别不到的,做了测试,result为空。

可以先将图片放大,再来识别。

具体操作:

先把图片wget回来,

wget http://www.fangdi.com.cn/GenImages/Index_Leaving_2010129172018.jpg

裁剪掉表头中文部分,并且转换为黑白颜色的tif文件:

convert -compress none -crop 460×140+0+20 -monochrome Index_Leaving_2010129172018.jpg in.tif

这个时候识别率为零的,先做放大,

做放大为200%处理:

convert in.tif -scale 200% in2.tif

出来满天星星(tif文件无法预览):

tiff file download.

识别结果很烂:

__=r-_3333`1-  _.`· ._‘·433_.—2_3’ _“.- Y .°.°_:1$1231 `·_` §-_*.=.`.-`123_.`33·`.  -.`_ *.*.13333 ‘.`· . _‘·- ‘-.`-Q3`33;13 ‘_-` Q- _-`.`_
3313 31. 33 2432 21. B4 3432 33. S9
‘-`_-‘334_2[’_‘:- -‘.- l_33.-31.·‘.j.-‘- __”- ·_`.13Eg2– ·_‘. ‘-.- ‘..-‘.‘ 1‘1‘_.34‘– _.‘-   -_‘. ‘-.-‘f1333‘3.‘-§-§ -_”-‘. 222‘.{iE1
3313 31.33 1343 12.33 12133 143.33
.f-_-32‘33j”.·_Q-Z·.`-_r4_2.34- _`-_- §·_.‘_-j.-‘33_3.Z· ‘.`”.- l .`.·__`-3.-”23_} “._- ` ..-’ .”".-’.”:123‘-na -1}* ._-‘_ I ·_`-_ 1 -.;33i· _”.·_
2312 33. 40 1333 3. B1 331 23. SB
_–.‘:-2B_E¤3g: ·_.‘   ._‘··_ 34._13_?.·_f-_.‘; .‘·._ {1431 .‘-_‘. Q .-‘_ – -{-:1_2 ‘._- 33-‘.q‘..·j. .`_‘·-_‘ `_1_5D2._ `-__·   -_._·`. 25.-_5f{_:· _-”·_.‘.

对满天星表示不满,换个灰度转换方式:

convert -compress none -crop 460×140+0+20 -colorspace Gray Index_Leaving_2010129172018.jpg in.tif

背景噪点没有了,终于有了点识别率:

33951 455. 25 14231 125. 55 T5595 955. T5
5515 51. 33 2452 21. 54 3432 55. 59
3342 55. 5T 1352 11. 54 15599 222. 45
35T3 51.99 1345 12.55 12159 149.53
3255 42. 54 953 5. 23 T25 T. 35
23T2 35. 45 1555 5. 51 531 23. 55
2553 34. T5 145T 12. 55 1552 25. 54

这种结果不能接受啊,设置放大率为150%测试下,

convert in.tif -scale 150% in2.tif

这一次貌似识别率居然到了100%!

33961 480. 26 14231 126.58 78896 950. 76
5616 81.33 2452 21. 64 3432 56.89
3342 55.87 1362 11.84 18099 222. 46
3673 51. 99 1340 12. 65 12189 149. 03
3200 42. 54 963 8. 23 726 7. 35
2372 36. 40 1060 8. 61 831 23. 86
2663 34. 75 1457 12.88 1502 25.54



小小震惊了下。

java

有位同学写了个java调用接口

http://ykf.javaeye.com/blog/212431

太复杂了,我还是用shell调用罢了。

.
发表评论
用户名: 匿名