from PIL import Image
import pytesseract
from pytesseract import *
rep={'O':'0',
'I':'1','L':'1',
'Z':'2',
'S':'8'
};
def initTable(threshold=140):
table = []
for i in range(256):
if i < threshold:
table.append(0)
else:
table.append(1)
return table
im = Image.open('C:/Users/asus-pc/Desktop/Captcha.jpg')
im = im.convert('L')
binaryImage = im.point(initTable(), '1')
text = image_to_string(binaryImage, config='-psm 7')
for r in rep:
text = text.replace(r,rep[r])
print(text)
复制代码
别人写的
from PIL import Image
import pytesseract
from pytesseract import *
rep={'O':'0',
'I':'1','L':'1',
'Z':'2',
'S':'8'
};
def initTable(threshold=140):
table = []
for i in range(256):
if i < threshold:
table.append(0)
else:
table.append(1)
return table
im = Image.open('C:/Users/asus-pc/Desktop/Captcha.jpg')
im = im.convert('L')
binaryImage = im.point(initTable(), '1')
text = image_to_string(binaryImage, config='-psm 7')
for r in rep:
text = text.replace(r,rep[r])
print(text)
复制代码