【问题标题】:Tesseract RuntimeError: Failed recognize pictureTesseract RuntimeError: 识别图片失败
【发布时间】:2017-05-16 00:32:40
【问题描述】:

我是 tesseract 的新手,在尝试使用外部训练的数据集时出现此错误。

tesserocr.pyx in tesserocr.image_to_text (tesserocr.cpp:20994)()
RuntimeError: Failed recognize picture

我不知道如何解决它。问题出在外部库上,但除此之外,我不知道。任何指导表示赞赏。

我使用的是带有 Tesserocr 包装器的 Ubuntu 16.04 LTS、x86_64、Python 2.7。外部库来自:https://github.com/arturaugusto/display_ocr

我刚刚将letsgodigital.traineddata文件粘贴到:

/usr/share/tesseract-ocr/tessdata

代码:

import tesserocr
image = Image.fromarray(im)
print tesserocr.image_to_text(image, lang = 'letsgodigital', psm=8, )

语言检查

print tesserocr.get_languages() 
(u'/usr/share/tesseract-ocr/tessdata/', [u'letsgodigital', u'equ', u'osd', u'eng'])

使用默认英文库运行代码有效

print tesserocr.image_to_text(image, lang = 'eng', psm=8, )

Tesseract 版本信息:

tesserocr.tesseract_version()

u'tesseract 3.04.01\n leptonica-1.73\n  libgif 5.1.2 : libjpeg 8d (libjpeg-turbo 1.4.2) : libpng 1.2.54 : libtiff 4.0.6 : zlib 1.2.8 : libwebp 0.4.4 : libopenjp2 2.1.0\n'

【问题讨论】:

  • 对我下面的回答有什么意见吗?

标签: python tesseract python-tesseract


【解决方案1】:

错误RuntimeError: Failed recognize picture 表示图像无法加载。您可以在下面尝试以确保“eng”首先工作。然后为您的 7 段数字显示器指定自定义语言。

import tesserocr
from PIL import Image

image = Image.open('english_text.png')
digits = tesserocr.image_to_text(image)  # print ocr text from image

如果您还没有这样做,还可以为经过训练的语言数据路径设置TESSDATA_PREFIX,如下所示。

export TESSDATA_PREFIX=/usr/share/tesseract-ocr/tessdata

希望对您有所帮助。


更新:

测试了从sample 裁剪的下图,

Windows 10Tesseract 4.0.0a 中,输出是正确的。

为了测试,如果上面的图片不能在你的机器上工作,你可以试试下面的编辑过的图片,它有更多的顶部和底部边距。即使使用默认的--psm 3--oem 3 模式,这个也可以工作。

【讨论】:

  • 我做了这两件事,这从“使用默认库运行代码有效...”的声明中可以看出,但我非常愿意尝试任何新的建议。
  • @DanGoodrick 更新了答案。如果时间允许,将尝试在OSX 中使用tesserocr (tesseract 3.04) 对其进行测试。
  • 我无法在我的机器(Linux 和 Windows 7)上加载“letsgodigital”库。但是,我能够通过使用 KNN 完成相同的任务。如果我能弄清楚你做了什么不同的事情(或者我的代码为什么不起作用),我会将我的问题标记为已回答。
猜你喜欢
  • 1970-01-01
  • 2020-05-04
  • 1970-01-01
  • 2017-01-27
  • 1970-01-01
  • 2012-04-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多