1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
def distinguish():
#ImageGrab从剪切板读取图片i,可以配合微信QQ快捷键截图使用
img1 = ImageGrab.grabclipboard()
# 文件保存的名字
img_path = '1.png'
# 保存图片
img1.save(img_path)
# 百度api执行所需数据,运行需换成自己的APP_ID,API_KEY,SECRET_KEY
APP_ID = '23897148'
API_KEY = 'CwMkZ83NaE05h2wOQKnxZod9'
SECRET_KEY = 'ZLGaqweSDEuX3DMEYZQ40a1zGXATOdhV'
# 初始化AipOcr
aipOcr = AipOcr(APP_ID, API_KEY, SECRET_KEY)
with open(img_path, 'rb') as f:
img2 = f.read()
# 识别图片并返回结果
data = aipOcr.basicAccurate(img2)
result = ''.join([i['words']+'\n' for i in data['words_result']])
print(result)
pyperclip.copy(result)
|