轻型ocr引擎。

liteocr的Python项目详细描述


这个库提供了一个干净的接口来分割和识别 形象。它针对打印文本进行了优化,例如扫描文档和 网站截图。

Python versionGithub releasePyPI versionPyPI status

安装

pip install liteocr

安装包括liteocrpython3库和 命令行可执行文件。

用法

>> liteocr

对图像文件执行ocr并将识别结果写入 json。

usage: LiteOCR [-h] [-d] [--extra-whitelist str] [--all-unicode] [--lang str]
               [--min-text-size int] [--max-text-size int]
               [--uniformity-thresh :0.0<=float<1.0]
               [--thin-line-thresh :odd int] [--conf-thresh :0<=int<100]
               [--box-expand-factor :0.0<=float<1.0]
               [--horizontal-pooling int]
               str str

positional arguments:
  str                   image file
  str                   output JSON file

optional arguments:
  -h, --help            show this help message and exit
  -d, --display         display recognized bounding boxes and text on top of the image

engine:
  parameters to liteocr.OCREngine constructor

  --extra-whitelist str
                        string of extra chars for Tesseract to consider only
                        takes effect when all_unicode is False
  --all-unicode         if True, Tesseract will consider all possible unicode
                        characters
  --lang str            language in the text. Defaults to English.

recognition:
  parameters to OCREngine.recognize() method

  --min-text-size int   min text height/width in pixels, below which will be
                        ignored
  --max-text-size int   max text height/width in pixels, above which will be
                        ignored
  --uniformity-thresh :0.0<=float<1.0
                        ignore a region if the number of pixels neither black
                        nor white < [thresh]
  --thin-line-thresh :odd int
                        remove all lines thinner than [thresh] pixels.can be
                        used to remove the thin borders of web page textboxes.
  --conf-thresh :0<=int<100
                        ignore regions with OCR confidence < thresh.
  --box-expand-factor :0.0<=float<1.0
                        expand the bounding box outwards in case certain chars
                        are cutoff.
  --horizontal-pooling int
                        result bounding boxes will be more connected with more
                        pooling, but large pooling might lower accuracy.

python3库

fromliteocrimportOCREngine,load_img,draw_rect,draw_text,dispimage_file='my_img.png'img=load_img(image_file)# you can either use context manager or call engine.close() manually at the end.withOCREngine()asengine:# engine.recognize() can accept a file name, a numpy image, or a PIL image.fortext,box,confinengine.recognize(image_file):print(box,'\tconfidence =',conf,'\ttext =',text)draw_rect(img,box)draw_text(img,text,box,color='bw')# display the image with recognized text boxes overlaiddisp(img,pause=False)

注释

我不赞成并将旧代码移到separate folder。旧的 api直接对整个图像调用tesseract。低召回率不是 一点也不重要,我后来才意识到:

  • 命令行tesseract生成了非常奇怪的全局页面 细分决策。它忽略某些没有 明显的模式。我试过很多不同的组合 少数可调参数,但没有任何帮助。我的手是 因为Tesseract的记录很差,很少有人问 关于stackoverflow的这些问题。
  • Tesserocr 是一个python包,它在tesseract的 C++ API。有一些本地api方法可以遍历 文本区域,但它们随机失败与segfault(啊!!!).我花了 很多时间都在试图修复它,但在绝望中放弃了…
  • tesseract是最好的开源ocr引擎,这意味着我没有 有其他选择。我考虑过使用google的在线ocr api, 但是我们不应该被网络连接和api调用所困扰 限制。

所以我最终使用了一个新的工作流:

  1. 应用opencv magic产生更好的文本分割。
  2. 对每个分段文本框运行tesseract。更重要的是 比运行在整个图像上更透明。
  3. 收集文本结果和平均置信水平(yield作为 发电机)。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何在表被注释到配置之前获取表的元数据?   java滚动条不会出现在JList上   java JOGL监视器GPU内存   java为什么要使用RecyclerView onDraw延迟   java定制Oppo Reno 2 Z CPH1951(手机型号)的固件(闪存文件)   java自定义线程池执行器   java如何解决发布版本中重复的jar条目[com/安卓/volley/R.class]?   java如何使用Bukkit API触发事件?   java在blazemeter jmeter RTE插件中使用ctrl+w输入   C#/Visual Studio的java JDT等价物   java为什么当maxread值很大而收到的消息数量很小时,卡夫卡消费者会无限期消费?   java游戏2。x:包含模板列表的绑定模型   带压缩的java日志旋转   运行时。exec用java运行程序读取它正在做什么