python OCR文字识别

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()






版权声明:本文为weixin_56643005原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。