标签:安装程序 requests open nal content efi win style 处理
import os import requests from uuid import uuid4 from selenium import webdriver browser = webdriver.Firefox() browser.get(‘http://my.cnki.net/elibregister/commonRegister.aspx‘) browser.implicitly_wait(2) os.mkdir(‘picture‘) for i in range(5): image = browser.find_element_by_xpath(‘//*[@id="checkcode"]‘) image_url = image.get_attribute(‘src‘) image_content = requests.get(image_url).content image_path = os.path.join(‘picture‘, f‘{uuid4()}.jpg‘) with open(image_path, ‘wb‘) as f: f.write(image_content) image.click() browser.implicitly_wait(2)
import tesserocr from PIL import Image image = Image.open(‘picture/1.jpg‘) result = tesserocr.image_to_text(image) #将image对象转换为文字 print(result) print(tesserocr.file_to_text(‘picture/1.jpg‘)) #将文件对象转换为文字
转化为灰度图像和二值化处理
image = image.convert(‘L‘) #将图片转化为灰度图像 image.show() image = image.convert(‘1‘) #将图片进行二值化处理 image.show()
import tesserocr from PIL import Image image = Image.open(‘picture/2.jpg‘) image = image.convert(‘L‘) threshold = 105 #数值越小, 图片中的像素点越少, 空白越多 table = [] for i in range(256): if i < threshold: table.append(0) else: table.append(1) image = image.point(table,‘1‘) image.show() result = tesserocr.image_to_text(image)
标签:安装程序 requests open nal content efi win style 处理
原文地址:https://www.cnblogs.com/zhangjian0092/p/11248712.html