python图片文字识别

需要用到百度API

https://ai.baidu.com/ai-doc/OCR/Dk3h7yf8m

pip install baidu-aip


这里用通用文字识别的高精度版本

步骤:

1、截图

2、图片保存到电脑上

3、调用百度API

import keyboard
from PIL import ImageGrab
import time
from aip import AipOcr
import code



#调用百度API

""" 你的 APPID AK SK """
APP_ID = '1909****'
API_KEY = '***'
SECRET_KEY = '***'
 
client = AipOcr(APP_ID, API_KEY, SECRET_KEY)  #生成一个对象

while(True):
    #1、截图
    keyboard.wait(hotkey='f1') #输入键盘的触发事件

    keyboard.wait(hotkey='ctrl+c')

    time.sleep(0.1)

    #2、图片保存到电脑上
    image = ImageGrab.grabclipboard() #能将剪贴板中的图片保存下来
    image.save('screen.png')
    print(type(image))

    with open('screen.png','rb') as f:
         image = f.read()
         print(type(image))
         text = client.basicAccurate(image)

    #print(text)
    for t in text['words_result']:
        print(t['words'])

p.s. 百度云能做的东西超级多

发布了410 篇原创文章 · 获赞 177 · 访问量 18万+

猜你喜欢

转载自blog.csdn.net/hxxjxw/article/details/105127645
今日推荐