怎么用python查找屏幕上是否存在1234这四个字?

怎么用python查找屏幕上是否存在1234这四个字?

easyocr我也安装了,这个库可以把图片的文字读出来,但怎么用固定的图片或文字去搜索桌面上是否有相似或相同的图片和文字呢?这个怎么做呢?

讨论数量: 4
Jason990420

Install any library to do screenshot and save to image file, like pyautogui

import pyautogui
import easyocr

file = 'screen.jpg'
pyautogui.screenshot().save(file)

reader = easyocr.Reader(['ch_sim','en'])
result = reader.readtext(file, detail = 0)
print(result)

if any(map(lambda x:'1234' in x, result)):
    print('Yes, "1234" found !')
else:
    print('No, "1234" not found !')
1年前 评论
kmyft (楼主) 1年前
Jason990420

It may depend on the platform you use.

Following code may work for Windows, other platform may need different code for them.

from PIL import ImageGrab
import win32gui

hwnd = win32gui.FindWindow(None, r'Window_Title')
win32gui.SetForegroundWindow(hwnd)
dimensions = win32gui.GetWindowRect(hwnd)

image = ImageGrab.grab(dimensions)
image.show()
1年前 评论

可以尝试opencv的模版匹配

1周前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!