python-3.x - Python pytesseract 解决验证码
问题描述
我正在尝试使用 pytesseract 模块在 python 中解决验证码。这是我的代码:
def captcha():
image = cv2.imread('captcha.jpeg')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
#gray = cv2.medianBlur(gray, 3)
filename = "{}.png".format("temp")
cv2.imwrite(filename, gray)
text = pytesseract.image_to_string(Image.open('temp.png'),
config='--psm 8 -c tessedit_char_whitelist=0123456789abcdefghijkmnlopkrstuvwxyz')
print('Captcha solved:' + text)
if __name__ == '__main__':
captcha()
验证码采用以下格式:
计算的结果是:Captcha solved:“Fates
当结果应该是182aa
解决方案
推荐阅读
- node.js - 是否有任何格式字符串可以直接从 GraphicsMagick 对象中读取 Caption[2,120] 数据?
- cassandra - 如何在 cassandra 查询语言中使用 DATE 数据类型编写查询?
- snowflake-cloud-data-platform - 雪花复制到不从 blob 存储中清除的语句中
- java - (TensorflowLite/Android) Unable to instantiate activity ComponentInfo
- vue.js - 如何使用 vue 和 vue2-leaflet 获取地理位置?
- ios - 如何在没有 iPhone 的情况下创建配置文件
- vba - 使用“First Name Last Name”回复电子邮件,而不是“Last Name, First Name”,使用特定字体
- python - PyQt QGridLayout 删除除顶行之外的所有内容
- python - 根据 ID 和月份聚合数据,具体取决于另一列(前与后)
- html - 在 HTML 表格中,如何在单元格级别覆盖字体大小(已在行级别设置)?