python 屏幕找图 点击,使用Python脚本在windows屏幕找图
Python實(shí)現(xiàn)windows屏幕找圖
import win32gui
hwnd_title = dict()
def get_all_hwnd(hwnd,mouse):
if win32gui.IsWindow(hwnd) and win32gui.IsWindowEnabled(hwnd) and win32gui.IsWindowVisible(hwnd):
hwnd_title.update({hwnd:win32gui.GetWindowText(hwnd)})
from PyQt5.QtWidgets import QApplication
from PyQt5.QtGui import *
import win32gui
import sys
import time
import win32gui, win32ui, win32con, win32api
from send_text import send_message_to_slack
import random
import pyscreenshot as ImageGrab
import sys
import numpy as np
import time
from cv2 import cv2
from time import sleep
def get_pay_keyboard_number_location(impath, target,fit_num): #fit_num是匹配度,如 0.95,0.85
print("start find pic")
positions = {}
start = time.time()
img_rgb = cv2.imread(impath)
teNum = "done"
template = cv2.imread(target)
h, w = template.shape[:-1]
res = cv2.matchTemplate(img_rgb, template, cv2.TM_CCOEFF_NORMED)
threshold = fit_num # 匹配度參數(shù),1為完全匹配
loc = np.where(res >= threshold)
if len(loc) > 0:
# positions[teNum] = zip(*loc[::-1])[0] # python2的寫(xiě)法
zipped = zip(*loc[::-1]) #list[::-1] 相當(dāng)于起點(diǎn)為最后的一個(gè),終點(diǎn)為第一個(gè),然后一次減少一個(gè)
positions[teNum] = (list(zipped))[0]
else:
print("Can not found pic: ")
end = time.time()
print(end - start)
return positions[teNum]
def zhaotu(fenbianlv):
impath1 = 'screenshot.jpg'
targetPath_a = "yellow" +str(fenbianlv)+'.jpg'
win32gui.EnumWindows(get_all_hwnd, 0)
hwnd = win32gui.FindWindow(None, 'C:\Windows\system32\cmd.exe')
app = QApplication(sys.argv)
screen = QApplication.primaryScreen()
while 1>0:
img = screen.grabWindow(hwnd ).toImage()
img.save("screenshot.jpg")
try:
ls = get_pay_keyboard_number_location(impath1, targetPath_a,0.98) #找目標(biāo)圖
except:
pass
sleep(5)
zhaotu(1792)
Flutter 寫(xiě)的app, 需要源碼可以私信~~
總結(jié)
以上是生活随笔為你收集整理的python 屏幕找图 点击,使用Python脚本在windows屏幕找图的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 嫂嫂学计算机,“嫂子非要让我来修电脑,我
- 下一篇: 20出头的人该怎么护肤?