图片文字OCR识别-tesseract-ocr

   帮助文件:https://github.com/tesseract-ocr/tesseract/blob/master/doc/tesseract.1.asclinux

  下载地址:https://github.com/tesseract-ocr/tesseract/wikigit

  如何使用提供的工具来训练Tesseract 4.00:https://github.com/tesseract-ocr/tesseract/wiki/TrainingTesseract-4.00github

  一、介绍

    图片文字的OCR识别有一款开源原件tesseract-ocr,最初是在linux上,固然如今也有windows版本,如今发展到4.0版本。windows

  二、下载tesseract-ocr

    下载地址:https://github.com/tesseract-ocr/tesseract/wiki工具

    里面有linux版本、macOS版本还有windows版本spa

    下面下载windows版本,以下图:ssr

    

    点击上面的连接,进入3d

    

 

    下载完成code

    

  三、安装,设置环境变量

    双击上的exe,进行安装orm

    

    

    

    

    

    

    

    安装完后打开软件坐在目录,这里我选择的是默认目录C:\Program Files (x86)\Tesseract-OCR

    安装目录C:\Program Files (x86)\Tesseract-OCR,安装完成后,设置环境变量

    

    在系统变量下面点击新建,按照如图建一个变量如图

    变量名TESSDATA_PREFIX,变量值:C:\Program Files (x86)\Tesseract-OCR\tessdata

    

  四、应用

    通过上面的调整tesseract命令能够在任意目录调用了,下面是tessract应用实例

    4.一、识别中文图片

    

    

    识别结果:

    

 

 

    命令:tesseract 中文.png log -l chi_sim

    把图片文件上的中文字符识别出来,写到log文本文件里面

 

 

    4.二、识别英文图片

    tesseract.exe 英文.png log -l eng

     

    

   

    识别结果:

    

 

    4.三、识别中英文混合

    tesseract.exe 中文-英文-混合.png log -l chi_sim+eng

 

     识别结果效果,中文部分很差

    

     

    若是用 tesseract 中文-英文-混合.png log -l chi_sim

    识别结果:显示中文识别比较好,可是由于有出息识别成中文的状况

    

 

    

    4.四、识别简单数字

    

    

    tesseract num.png log -l chi_sim
    tesseract num.png log -l eng

    均可以正常识别

    以下面复杂的识别码就识别不了

    

    

    

    总结:在识别只包含英文和数字的图片能够用简单的命令:

        tesseract num.png log

        若是包含中文的必须指定中文库:chi_sim

        tesseract num1.png log -l chi_sim

   

   附录:

    Usage:tesseract imagename outputbase [-l lang] [-psm pagesegmode] [configfile...]
    pagesegmode values are:
    0 = Orientation and script detection (OSD) only.
    1 = Automatic page segmentation with OSD.
    2 = Automatic page segmentation, but no OSD, or OCR
    3 = Fully automatic page segmentation, but no OSD. (Default)
    4 = Assume a single column of text of variable sizes.
    5 = Assume a single uniform block of vertically aligned text.
    6 = Assume a single uniform block of text.
    7 = Treat the image as a single text line.
    8 = Treat the image as a single word.
    9 = Treat the image as a single word in a circle.
    10 = Treat the image as a single character.
    -l lang and/or -psm pagesegmode must occur before anyconfigfile.

 

    tesseract imagename outputbase [-l lang] [-psm pagesegmode] [configfile...]

    tesseract    图片名  输出文件名 -l 字库文件 -psm pagesegmode 配置文件

    例如:

    tesseract code.jpg result  -l chi_sim -psm 7 nobatch

    -l chi_sim 表示用简体中文字库(须要下载中文字库文件,解压后,存放到tessdata目录下去,字库文件扩展名为  .raineddata 简体中文字库文件名为:  chi_sim.traineddata)

    -psm 7 表示告诉tesseract code.jpg图片是一行文本  这个参数能够减小识别错误率.  默认为 3

    configfile 参数值为tessdata\configs 和  tessdata\tessconfigs 目录下的文件名

相关文章
相关标签/搜索