【发布时间】:2021-03-22 06:54:33
【问题描述】:
我想知道如何在 python 中使用 opencv (cv2) 来替代 pyautogui.locatecenteronscreen() 函数,只使用图像而不是屏幕。 我会尝试使用一个例子。
可能是用户定义的函数,locateCenterOfTemplate("Path/to/template.png") 现在因为我使用截图作为原始图像,它会和我一样 使用 pyautoguis,但出于我的主要目的,我不会使用。
import cv2
import pyautogui
pyautogui.screenshot(Path/to/original_image.png)
def locateCenterOfTemplate(image, template, accuracy=100,
region=#whole screen idk how to do this eaither):
temp = locateCenterOfTemplate("Path/to/original_image.png", "Path/to/template.png")
# now variable "temp" is the same as the posision of the center of the template,
# inside of the source immage
pyautogui.click(temp)
基本上,我希望将模板与区域、置信度以及模板和原始图像作为功能匹配:)
谢谢:D
【问题讨论】:
标签: python-3.x opencv cv2 template-matching