需要 import 這幾個 module import cv2 import numpy as np import pyautogui import time 滑鼠點擊 def click_image(image,pos, action, timestamp,offset=5): img = cv2.imread(image) height, width, channels = img.shape pyautogui.moveTo(pos[0] + offset, pos[1] + ,offset, timestamp) pyautogui.click(button=action) 圖片尋找 def imagesearch(image, precision=0.8): im = pyautogui.screenshot() img_rgb = np.array(im) img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY) template = cv2.imread(image, 0) template.shape[::-1] res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED) min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res) if max_val < precision: return [-1,-1] return max_loc #返回圖片座標 使用方式 if __name__ == '__main__': pp =imagesearch("./1.png") #尋找1.png的圖。(把圖跟程式放同一個目錄下) click_image("./1.png", pp, "left", 1) #要點右鍵的話,就把"left"改成 "
留言
張貼留言