hwnd_title =dict()defget_all_hwnd(hwnd,mouse):if win32gui.IsWindow(hwnd)and win32gui.IsWindowEnabled(hwnd)and win32gui.IsWindowVisible(hwnd):
hwnd_title.update({hwnd:win32gui.GetWindowText(hwnd)})deffind_title():
win32gui.EnumWindows(get_all_hwnd,0)for h,t in hwnd_title.items():if"图片查看"in t:#print(h, t)
title=t
breakreturn title
paddleocr识别PyQt5截图区域的图片
defget_text():
img_path ='screenshot.jpg'
title=find_title()
hwnd = win32gui.FindWindow(None, title)
app = QApplication(sys.argv)
screen = QApplication.primaryScreen()
img = screen.grabWindow(hwnd).toImage()
img.save(img_path)
ocr = PaddleOCR( lang="ch",use_gpu=False)# need to run only once to download and load model into memory
img_path =img_path
result = ocr.ocr(img_path)
lines=[]for line in result:
lines.append(line[-1][0])return lines