1. 使用PIL
# coding:utf-8
# coding:cp936
# 二值化处理
from selenium import webdriver
from PIL import Image
from time import sleep
# broswer = webdriver.Chrome()
im = Image.open(r'C:\picture6.png')
imgry = im.convert('L')
# imgry.show()
threshold = 200
table = []
for i in range(256):
if i < threshold:
table.append(1)
else:
table.append(0)
out = imgry.point(table, '1')
out.save(r'C:\ocr1.png')