用OCR来识别
直接识别效果不好,因为验证码内的多余线条干扰了图片的识别。先转为灰度图像,再二值化。经实践证明,该方法不是100%正确。

# 获取图片
curl -X GET http://my.cnki.net/elibregister/CheckCode.aspx

import tesserocr
from PIL import Image

image = Image.open('1.png')
# 转为灰度图像
image = image.convert('L')

threshold = 127
table = []

# 二值化
for i in range(256):
    if i < threshold:
        table.append(0)
    else:
        table.append(1)
# mode='1'默认的阀值为127
image = image.point(table, '1')
image.show()
result = tesserocr.image_to_text(image)
print(result)


相关文章:

  • 2022-12-23
  • 2022-02-10
  • 2022-01-09
  • 2022-12-23
  • 2022-12-23
  • 2022-02-10
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-10
  • 2021-10-09
  • 2021-12-31
  • 2022-12-23
  • 2021-04-17
  • 2021-06-27
相关资源
相似解决方案