标签:etc hot tps strftime empty ftime turn board result
百度云文字识别技术文档:
https://cloud.baidu.com/doc/OCR/OCR-Python-SDK.html#.E6.96.B0.E5.BB.BAAipOcr
from aip import AipOcr #百度aip from PIL import ImageGrab #处理剪切板图片 from PIL import Image import PIL import keyboard #监控键盘 import sys import time,datetime import random import win32clipboard as w # 处理剪切板 import win32con def screenShot(): ‘‘‘监控键盘事件,并保存图片‘‘‘ # 监控键盘,输入QQ默认截图快捷键时进入 if keyboard.wait(hotkey=‘ctrl+alt+a‘) == None: while True: time.sleep(3) #等待截图 im = ImageGrab.grabclipboard() #获取剪切板中的图片 if isinstance(im,PIL.BmpImagePlugin.DibImageFile): #若剪切板的内容可以解析成图片 #文件名 i = datetime.datetime.now().strftime(‘%Y%m%d%H%M%S‘) r = str(random.randint(100,1000)) #保存图片 im.save(i+r+‘.png‘) #百度云账号设置 APP_ID = ‘‘ API_KEY = ‘‘ SECRET_KEY = ‘‘ #百度云api对象 client = AipOcr(APP_ID, API_KEY, SECRET_KEY) #读取图片 image = get_file_content(i+r+‘.png‘) #获取图片中的文字内容 data = client.basicGeneral(image) words_result = data[‘words_result‘] data = "" # 需要保存的内容 for words in words_result: data+=words[‘words‘] print(data) setText(data) #读取图片 def get_file_content(filePath): with open(filePath, ‘rb‘) as fp: return fp.read() #写入剪切板内容 def setText(aString): w.OpenClipboard() w.EmptyClipboard() w.SetClipboardText(aString) w.CloseClipboard() if __name__ == "__main__": #for _ in range(sys.maxsize): #修改成在screenShot中用while循环 screenShot()
标签:etc hot tps strftime empty ftime turn board result
原文地址:https://www.cnblogs.com/LTEF/p/9130763.html