python - OCR 图像预处理 - Tesseract

标签 python ocr image-recognition image-preprocessing python-tesseract

This is the image I'm trying to detect

显然,这张图片非常难看,因为它的清晰度很低,而且不是真实的文字。但是,使用这段代码,我没有检测到任何接近的东西:

import pytesseract
from PIL import Image, ImageEnhance, ImageFilter
image_name = 'NedNoodleArms.jpg'
im = Image.open(image_name) 
im = im.filter(ImageFilter.MedianFilter())
enhancer = ImageEnhance.Contrast(im)
im = enhancer.enhance(2)
im = im.convert('1')
im.save(image_name)
text = pytesseract.image_to_string(Image.open(image_name))
print(text)

输出

, Mdfiaodfiamms

这里有什么想法吗?我的对比函数生成的图像是:

enter image description here

哪个看起来不错?我没有大量的 OCR 经验。你会在这里推荐什么预处理?我已经尝试将图像的大小调整得更大,这有一点帮助但还不够,还有一堆来自 PIL 的不同过滤器。虽然没有什么特别接近的

最佳答案

你是对的,tesseract 在高分辨率下效果更好,因此有时调整图像大小会有所帮助 - 但不要转换为 1 位。

我在转换为灰度时得到了很好的结果,使它变大了 3 倍,并使字母更亮一些:

>>> im = Image.open('j78TY.png')\
          .convert('L').resize([3 * _ for _ in im.size], Image.BICUBIC)\
          .point(lambda p: p > 75 and p + 100)
>>> pytesseract.image_to_string(im)
'NedNoodleArms'

检查 this jupyter notebook :

enter image description here

关于python - OCR 图像预处理 - Tesseract,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51688973/

相关文章:

android - Android 上的硬币识别

machine-learning - CNN 上的数字识别

python - PyCharm 中的 Numpy 导入错误(导入多数组 numpy 扩展模块失败)

android - 提高 Android TessBaseAPI (Tesseract) OCR 的准确性

java - Tess4J : Invalid memory access

python - 用于文本检测的开源 Python 工具

delphi - delphi中识别图片中的文字

Python RegEx Sub,贪婪问题?

python - Pandas set_index 不设置索引

python - pytest 运行后删除缓存文件