读取像素工具
import ddddocr
import pyautogui
def saveimg(left, top, width, height):
# 截取屏幕上指定区域的截图
# left, top, width, height = 925, 7, 70, 25
image = pyautogui.screenshot(region=(left, top, width, height))
# 保存截图到本地
image.save('1.jpg', dpi=(1200, 1200))
def text(left, top, width, height, txt):
# 识别图片文字
saveimg(left, top, width, height)
ocr = ddddocr.DdddOcr()
with open('1.jpg', 'rb') as f:
img_bytes = f.read()
res = ocr.classification(img_bytes)
print(f'自动识别为:{res}')
# os.remove('1.jpg')
return txt.lower() == res.lower()#取消大小写判断
# saveimg(319, 140, 24, 15)
print(text(319, 140, 24, 15,'视口'))#判断模型是否已经打开
print(text(133, 3, 86, 20,'SViewDesigner'))#判断应用是否已经打开