最近在用pyautogui寫自動化的腳本時,用pyautogui.locateonscreen("shell.PNG")函數來判斷機器成功進入EFIshell會一直返回None。
且shell.PNG在當前屏幕置頂可見,但就是抓不到。
解決方法:安裝opencv,並在locateOnScreen添加confidence參數
參考:https://stackoverflow.com/questions/43702511/why-pyautogui-locateonscreen-only-returns-none
pip install opencv-python --timeout 10000
shell.PNG
成功安裝opencv后,可以抓到圖片的坐標.
import pyautogui import cv2 res=pyautogui.locateOnScreen("shell.PNG",confidence=0.5) print(res)
Box(left=1044, top=696, width=53, height=20)
如何將窗口永久置頂見:https://www.cnblogs.com/pfeiliu/p/13795698.html