圖片辨識
AutoControl 使用 OpenCV 模板匹配技術在螢幕上定位 UI 元素。 可用於尋找按鈕、圖示或其他視覺元素並與之互動。
定位所有匹配
尋找螢幕上所有符合模板圖片的位置:
import time
from je_auto_control import locate_all_image, screenshot
time.sleep(2)
# detect_threshold: 0.0 ~ 1.0(1.0 = 完全匹配)
image_data = locate_all_image(
screenshot(),
detect_threshold=0.9,
draw_image=False
)
print(image_data) # [[x1, y1, x2, y2], ...]
定位圖片中心
尋找模板圖片並回傳其中心座標:
import time
from je_auto_control import locate_image_center, screenshot
time.sleep(2)
cx, cy = locate_image_center(
screenshot(),
detect_threshold=0.9,
draw_image=False
)
print(f"找到位置: ({cx}, {cy})")
定位並點擊
尋找模板圖片並自動點擊其中心:
import time
from je_auto_control import locate_and_click, screenshot
time.sleep(2)
image_data = locate_and_click(
screenshot(),
"mouse_left",
detect_threshold=0.9,
draw_image=False
)
print(image_data)
參數說明
參數 |
型別 |
說明 |
|---|---|---|
|
str / PIL Image |
要搜尋的模板圖片(檔案路徑或 PIL |
|
float |
偵測精確度,範圍 |
|
bool |
若為 |