python +pytesseract简单失败验证码

(1)下载pytesseract 使用命令为 pip install pytesseract ,我自己用的版本是python2.7 可以根据自己的版本下载
(2)下载tesseract-ocr-setup-3.05.00dev-336-g0e661dd,python 2.7使用该版本就可以使用
(3)修改pytesseract 源代码中的 tesseract_cmd 修改为tesseract_cmd = r’C:\Program Files (x86)\Tesseract-OCR\tesseract.exe’,这个URL是刚才安装tesseract-ocr默认路径 ,可以选择自定义路径

主要代码如下
def image_T():
im=Image.open(r"C:\Users\XXX\XXX\1.png")
b = im.convert((“L”))
threshold=160
table=[]
for i in range(256):
if i<threshold:
table.append(0)
else:
table.append(1)
out = b.point(table,‘1’)
text =pytesseract.image_to_string(out)
print text
代码片段如上
提供的图片

发布了17 篇原创文章 · 获赞 1 · 访问量 450

猜你喜欢

转载自blog.csdn.net/qq_36495121/article/details/100513164