opencv pyautogui.locateCenterOnScreen()在查找Spotify暂停按钮时获取的坐标不正确

zzlelutf  于 2022-11-15  发布在  其他
关注(0)|答案(1)|浏览(67)

我尝试使用pyautogui在屏幕上定位Spotify的暂停按钮,只是为了开发我的python知识。我运行下面的脚本,并保存了暂停按钮的截图,但鼠标移动到屏幕的右下角,距离按钮所在的位置有几英里远。

import pyautogui

input("Move to target button") #move mouse to pause button
target = pyautogui.position()
local = pyautogui.locateCenterOnScreen("spotify.png", confidence=0.9, grayscale=False)#spotify.png is a screenshot of the pause button

pyautogui.moveTo(local)
print(f"Found: {local}")
print(f"Target: {target}")

#sloppy but wanted to ensure the xy coordinates were correct
x = list(local) 
x.append(100)
x.append(100)
im = pyautogui.screenshot('test.png', region=x)

输出示例:

Move to target button
Found: Point(x=1487, y=780)
Target: Point(x=746, y=392)

屏幕尺寸为1440 x 900
在鼠标指向的坐标处没有匹配的图像,但从屏幕截图看,似乎找到了一个?如何修复此问题,使鼠标指向暂停按钮,而不是屏幕右下角?

9fkzdhlc

9fkzdhlc1#

import pyautogui导入时间

while True:
    time.sleep(1) #prevents lag and waits for new image
    spotify = pyautogui.locateOnScreen('spotify.PNG', confidence=.7,grayscale=False) #image location
    if spotify: #if the image is found
        print('found image clicking...')
        pyautogui.click(spotify)

相关问题