import easyocr class hjc(): def hjc_jietu(self,x1,y1,x2,y2): #截图 x1=x1 x2=x2 y1=y1 y2=y2 im = ImageGrab.grab(bbox=(x1,y1,x2,y2)) im.save('D:\\PycharmProjects\\hjclx\\wenzishibie\\jt.png') #截图保存的位置 def hjc_shibie01(self): #文字识别 reader = easyocr.Reader(['ch_sim','en']) #ch_sim(简体中文)、en(英文) imagepath = 'D:\\PycharmProjects\\hjclx\wenzishibie\\jt.png' #识别的图片的位置 result = reader.readtext(imagepath) for i in result: word = i[1] print(word) with open('D:\\PycharmProjects\\hjclx\wenzishibie\\jt.txt','a+',encoding='utf-8')as a: #识别出来的文字保存到txt文件 a.write(str(word)) wr='登录' if wr in word: print('true') if __name__ == '__main__': hjc=hjc() hjc.hjc_jietu(x1=1358,y1=433,x2=1479,y2=477) #识别的区域坐标(可用微信截图ALT+A,有坐标显示) hjc.hjc_shibie01() 或者
from PIL import ImageGrab import ssl
def hjc_shibie01(self): #文字识别 ssl._create_default_https_context = ssl._create_unverified_context reader = easyocr.Reader(['ch_sim', 'en']) # this needs to run only once to load the model into memory result = reader.readtext(r'E:\yemian\jt.png') for i, val in enumerate(result): print(val[1])