找到并点击另一张图片中的一部​​分图片

问题描述

我有一个图像 1,我用 pyautogui 找到它,居中并单击。 没关系。

但是我有部分图片可以点击,一旦我找到第一个图片,我就无法点击坐标。

我找到了 CV2 模块,并且我能够将模板与图像匹配,但是一旦我得到第一张图像,我就无法获得模板坐标。

所以基本上我有 image1,我找到了它,还有一部分 image2,称为模板,我需要找到它。

我需要这样做,因为第一张图片可以改变屏幕上的位置。我如何让 x,y 使模板图像居中?

pyautogui.position ( x,y,1 )

这是将图像与模板匹配的脚本

代码

import cv2
import numpy as np
import os
import pyautogui as p

img_rgb = cv2.imread('big.png')
img_gray = cv2.cvtColor(img_rgb,cv2.COLOR_BGR2GRAY)
template = cv2.imread('portion.png',0)
w,h = template.shape[::-1]
##print (w,h)
res = cv2.matchTemplate(img_gray,template,cv2.TM_SQDIFF)
threshold = 0.8
loc = np.where( res >= threshold)
for pt in zip(*loc[::-1]):
    cv2.rectangle(img_gray,pt,(pt[0] + w,pt[1] + h),(0,255,255),2)
##cv2.imshow('Detected',template)
#( of course before this I will center the x and y with locate / center somehow )
p.moveto (x of portion,y of portion,1) #( of course before this I will center the x and y with locate / center somehow )

解决方法

好的。我做的。 我只是找到第一张图片。然后我找到第二个给出第一个图像坐标作为区域 ti 检查。 这很简单。 对不起,打扰你了。