本文介绍了OCR的图像预处理-Tessaract的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很明显,此图像非常清晰,因为它的清晰度很低并且不是真实的单词.但是,使用此代码,我无法检测到任何东西:

Obviously this image is pretty tough as it is low clarity and is not a real word. However, with this code, I'm detecting nothing close:

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

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

Any ideas here? The image my contrasting function produces is:

哪个看起来不错?我没有大量的OCR经验.您会在这里建议什么预处理?我尝试过将图像调整为更大的尺寸,这有一点帮助,但还不够,还有一些来自PIL的不同滤镜.没什么特别亲密的

Which looks decent? I don't have a ton of OCR experience. What preprocessing would you recommend here? I've tried resizing the image larger, which helps a little bit but not enough, along with a bunch of different filters from PIL. Nothing getting particularly close though

推荐答案

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

You are right, tesseract works better with higher resolutions so sometimes resizing the image helps - but don't convert to 1 bit.

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

I got good results converting to grayscale, making it 3 times as large and making the letters a bit brighter:

>>> 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'

检查此jupyter笔记本:

这篇关于OCR的图像预处理-Tessaract的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 16:56