图片文字OCR识别-tesseract-ocr

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

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

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

  1、介绍

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

  2、下载tesseract-ocr

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

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

    下面下载windows版本,如下图:

    

    点击上面的链接,进入

    

    下载完成

    

  3、安装,设置环境变量

    双击上的exe,进行安装

    

    

    

    

    

    

    

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

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

    

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

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

    

  4、应用

    经过上面的调整tesseract命令可以在任意目录调用了,下面是tessract应用实例

    4.1、识别中文图片

    

    

    识别结果:

    

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

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

    4.2、识别英文图片

    tesseract.exe 英文.png log -l eng

     

    

   

    识别结果:

    

    4.3、识别中英文混合

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

     识别结果效果,中文部分不好

    

     

    如果用 tesseract 中文-英文-混合.png log -l chi_sim

    识别结果:显示中文识别比较好,但是因为有出息识别成中文的情况

    

    

    4.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 参数值为tessdataconfigs 和  tessdata essconfigs 目录下的文件名

 

原文地址:https://www.cnblogs.com/shaosks/p/9376575.html