-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvision.py
More file actions
35 lines (27 loc) · 845 Bytes
/
vision.py
File metadata and controls
35 lines (27 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import cv2
import numpy as np
import subprocess
import sys
import time
TEMPLATES = sys.argv[1:] # liste des images à chercher
THRESHOLD = 0.88
def screencap():
proc = subprocess.Popen(
["adb", "exec-out", "screencap", "-p"],
stdout=subprocess.PIPE
)
img = proc.stdout.read()
return cv2.imdecode(np.frombuffer(img, np.uint8), cv2.IMREAD_COLOR)
while True:
screen = screencap()
for template_path in TEMPLATES:
template = cv2.imread(template_path)
h, w = template.shape[:2]
result = cv2.matchTemplate(screen, template, cv2.TM_CCOEFF_NORMED)
_, max_val, _, max_loc = cv2.minMaxLoc(result)
if max_val >= THRESHOLD:
x = max_loc[0] + w // 2
y = max_loc[1] + h // 2
print(f"{x},{y}")
sys.exit(0)
time.sleep(0.3)