如何解决如何针对Pytesseract预处理具有大噪点的图像?
我正在尝试让Pytesseract从此image读取803248。 它最初是彩色图像,这是某些处理的结果。 但是现在,Pytesseract甚至无法读取上面没有线条的8或0。
这是代码:
#!/usr/bin/python3
# coding: utf-8
import pytesseract
import os
from os.path import basename
import argparse
from PIL import Image,ImageFilter
try:
import Image,ImageOps,ImageEnhance,imread
except ImportError:
from PIL import Image,ImageEnhance
def solve_captcha(path):
"""
Convert a captcha image into a text,using PyTesseract Python-wrapper for Tesseract
Arguments:
path (str):
path to the image to be processed
Return:
'textualized' image
"""
image = Image.open(path).convert("L")
print(basename(path))
image = ImageOps.autocontrast(image)
threshold = 150
image = image.point(lambda p: p < threshold and 255)
filename = "{}.png".format(os.getpid())
image.save(path)
text = pytesseract.image_to_string(path)
return text
if __name__ == '__main__':
argparser = argparse.ArgumentParser()
argparser.add_argument("-i","--image",required=True,help="path to input image to be OCR'd")
args = vars(argparser.parse_args())
path = args["image"]
print('-- Resolving')
captcha_text = solve_captcha(path)
print('-- Result: {}'.format(captcha_text))
我拼命尝试了一些其他处理,例如模糊处理,但这是最糟糕的。 如何通过处理摆脱字符上的那些行或使Pytesseract忽略它们?
也请不要提供使用OpenCV的解决方案,因为我不知道如何使它起作用(我总是在使用它时会出错)。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。