python pillow+pytesseract识别二维码

from selenium import webdriver
from PIL import Image
import pytesseract

driver=webdriver.Chrome()
url='http://cer.nju.edu.cn/amserver/UI/Login?goto=http%3A%2F%2Fpyb.nju.edu.cn%2Floginredirect.action&gotoOnFail=http%3A%2F%2Fpyb.nju.edu.cn%2Flogin.action'
driver.maximize_window()
driver.get(url)
codeimage=driver.find_element_by_id('vcodeimg')
location=codeimage.location
size=codeimage.size
left=location['x']
bottom=location['y']
right=left+size['width']
top=bottom+size['height']
driver.save_screenshot('F://screen.png')
im=Image.open('F://screen.png')
codeimage=im.crop((left,bottom,right,top))
codeimage.show()
code=pytesseract.image_to_string(codeimage)
print(code)
输出:

这里写图片描述
X33N
但是很多情况下无法正确识别

猜你喜欢

转载自blog.csdn.net/qq_41584674/article/details/79198706
今日推荐