【问题标题】:Pytesseract output is completely different from the text in the imagePytesseract 输出与图片中的文字完全不同
【发布时间】:2019-02-16 15:19:13
【问题描述】:

以下代码在我朋友的 Windows 笔记本电脑上完美运行,但在我的笔记本电脑上,它吐出完全垃圾。我认为这可能与图书馆有关,但我不能肯定地说?你们能告诉我它是否适合您,或者您以前是否曾经发生过这种情况?

import pytesseract
from PIL import Image, ImageEnhance, ImageFilter
from textblob import TextBlob

originalImage = Image.open("pictures\hp.png")
workingImage = originalImage.copy()
workingImage = originalImage.filter(ImageFilter.MedianFilter())

enhanceSharpness = ImageEnhance.Sharpness(workingImage)
enhanceColor = ImageEnhance.Color(workingImage)

workingImage = enhanceSharpness.enhance(2)
workingImage = enhanceColor.enhance(0)
workingImage = workingImage.convert('1')

text = pytesseract.image_to_string(workingImage)
correctedText = TextBlob(text).correct()

print(correctedText)

这是我们提供给它的图片:

我没有像在我朋友的电脑上那样打印照片中的文字,而是打印以下内容:

of was an am: came: mm: mmm mm bu noma of arm 523w at"
mmmhmg peaches? w 3 cm {mamma a map m: K wm} Or Mummy
didn‘c realm when Am had cm then he mmm Am: Ma mad m

Am!» adam Them was 3 W317); Ll them on arm mmm a‘met
Turn mm "mm wasn't a mm: m 313% Ham sum Am have. term mmm
M‘) It must had: {mm 3 mm fiftht‘ High: Or Him‘cy [asked and
hated :31 me cm of Taxed back Of I Mummy time mound! m:

come and up in: may M maxim} tin: ca: m Am mm‘m h Am raw
made m: mm mm mid and Run“ w Of iwkmg at me 5 Is
cmricbfl mad may or $$ka Or [)unity gave hrmsuifa hut: wake and
put 11% cm my m“ Am Am} Is he rim mere own M {high W
msihmg except & Large may of'dry‘b M. M h my m E“ that thy

【问题讨论】:

  • 我得到与你在 Linux 上使用 Python 3.7.0、pytesseract 0.2.6、libtesseract3、tesseract-ocr 3.05.01-lp150.1.1 相同的(乱码)输出。
  • 相反,我使用 Python 3.6.7、tesseract-ocr 4.00(在 Ubuntu 18.04 上)得到(大约)正确的输出。
  • 我有 tesseract-ocr 版本 3.05.02 也许我需要像你一样的 4.0 Josh。如果它解决了问题,我会告诉你
  • 我也得到了大致正确的输出。我发现有时可以通过将图像的大小增加大约 5 倍,然后将其放入 pytesseract 来解决此问题。

标签: python python-imaging-library textblob python-tesseract


【解决方案1】:

我下载了 tesseract-ocr 4.0 版,它现在可以完美运行。感谢大家的帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-03
    • 1970-01-01
    • 2018-07-28
    • 1970-01-01
    相关资源
    最近更新 更多