python - 使用 Python 清除验证码图像的线条噪声
问题描述
我试图删除这个验证码图像上的线条,所以我可以使用像 tesseract 这样的 OCR 工具来读取图像上的字符串文本。我使用的代码在我如何为我的大学网站和图像增强开发验证码破解程序中进行了解释,以便更好地识别图像。到目前为止,这是我的 python 代码(实际上我是 python 新手)
from PIL import Image, ImageEnhance
im = Image.open("img2.png")
nx, ny = im.size
image = im.resize((int(nx*5), int(ny*5)), Image.BICUBIC)
image.save("img1_enchance.png")
image = image.convert("L") # Grayscale conversion
width, height = image.size
cropped_image = image.crop((0, 0, (460/3), 200))
cropped_image.save("img1_crop.png")
pixel_matrix = cropped_image.load()
croppedwidth, croppedheight = cropped_image.size
for col in range(0, croppedheight): # Height
for row in range(0, croppedwidth): # Width
if pixel_matrix[row, col] != 0:
pixel_matrix[row, col] = 255
cropped_image.save("img1_text1.png")
for column in range(1, croppedheight - 1):
for row in range(1, croppedwidth - 1):
if pixel_matrix[row, column] == 0 \
and pixel_matrix[row, column - 1] == 255 and pixel_matrix[row, column + 1] == 255:
pixel_matrix[row, column] = 255
if pixel_matrix[row, column] == 0 \
and pixel_matrix[row - 1, column] == 255 and pixel_matrix[row + 1, column] == 255:
pixel_matrix[row, column] = 255
cropped_image.save("img1_text2.png")
问题是,得到了文本字符串,我得到了如下图所示的嘈杂线:
(img1_text1.png)
(img1_text2.png)
我在这个google-drive 链接中收集了如下所示的验证码图像:
非常感谢任何帮助,非常感谢
解决方案
推荐阅读
- mysql - 加入计算的列值无法给出预期的结果
- postgresql - 在 PostGIS 中使用 ST_Within 显示位于多个重叠/相交多边形内的点
- r - 如何在R中的直方图中将对数比例添加到y轴
- debugging - GDB:手动注入调试符号
- c++ - 是否可以在不使用 stderr、stdin 或 stdout 的情况下使用管道在 2 个进程之间创建通信流?
- saml - ADFS 单次注销失败并显示请求者状态代码
- python - jupyter 实验室搜索/在输出中查找 - 快捷方式
- python - 我需要分组并用最小值-最大值覆盖一列
- macos - 在 Mac 上使用外部程序查看数据库
- java - 将 JSON(不是由 AVRO 生成)转换为 Avro 特定记录