python - 验证码的去噪条纹

标签 python python-imaging-library

我正在处理一种带有一些嘈杂条纹的验证码。它们是随机绘制的,而且是直的。数字和条纹的颜色是真正随机的。

enter image description here enter image description here enter image description here

下面的代码能够recognize digits from some captchastesseract 的帮助下。

from pytesser.pytesser import *
from PIL import Image, ImageFilter, ImageEnhance

im = Image.open("test.tiff")
im = im.filter(ImageFilter.MedianFilter()) # blur the image, the stripes will be erased
im = ImageEnhance.Contrast(im).enhance(2)  # increase the contrast (to make image clear?)
im = im.convert('1')                       # convert to black-white image
text = image_to_string(im)
print "text={}".format(text)

去除条纹的方法是先模糊图像再锐化。大多数情况下识别的准确率是100%,但我在想如果有还有一些其他方法可以在不模糊数字的情况下去除条纹。

非常感谢任何提示。

最佳答案

为什么不尝试利用条纹的细度呢?我猜他们最多 5px。那么为什么不做类似的事情(粗略的伪代码):

  1. 将您的图像转换为 numpy 数组
  2. 用于 UP、DOWN、LEFT、RIGHT 中的方向
    1. 制作一个新的 numpy 数组,在 direction 上移动 5px,裁掉边缘。
    2. 并将新数组和旧数组放在一起。
    3. 检查左下角。如果它是白色的,你就完成了,你的图像被去噪了。如果没有,请尝试下一个方向。

鉴于数字比条纹粗得多,我的猜测是从图像中清除条纹会超过 AND 引入的任何失真。

关于python - 验证码的去噪条纹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24279918/

相关文章:

python - Django 如何判断上传的图片是否有效?

python - 谷歌应用引擎图像 GIF execute_transforms LargeImageError

python - 使用 ctypes 列出从 dll 导出的函数

python - 根据多个分隔符分割字符串,同时保留它们

python - 你在哪里猴子修补 Django 用户模型?

python - 连接后 psycopg2 找不到任何表

python - 在 Queue.task_done() 之后运行多线程代码

python - 使用 Python 从 PNG 或 JPG 创建一个在 XP 上运行的 ICO

python - 了解 Pillow 中的 histogram()

python 枕头 : Make gradient for transparency