-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.py
74 lines (55 loc) · 1.83 KB
/
main.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from ppadb.client import Client
import time
import os
import cv2 as cv
import manager
import divimage
import numpy as np
os.system('adb start-server')
adb = Client(host='localhost', port=5037)
devices = adb.devices()
device = devices[0]
if len(devices) == 0:
print( "No devices found")
print("Connected devices:",devices)
print(devices)
totalmoves = 0
moves = 0
runs = int(input("Enter initial runs number(prefered in range 100 to 1000) : "))
try:
while True:
image = device.screencap()
img = cv.imdecode(np.frombuffer(image, np.uint8), cv.IMREAD_COLOR)
# with open(f'live.png','wb') as f:
# f.write(image)
# image = cv.imread(f"live.png")
image = cv.resize(img,(400,900))
# cv.imshow("Starter",image)
# cv.waitKey()
image = image[328:690,28:370] # change this accordinf to your screenresolution
# (This values are only for screen with resolution of 2340 * 1080 resolution)
# cv.imshow("Croped",image)
# cv.waitKey()
# cv.imwrite("live.png",image)
# cv.imshow("image",image)
# cv.waitKey()
# break
array = divimage.scanimage(image)
move = manager.runa(array,runs)
print(array)
print(move)
if move['move'] == 'u':
device.shell(f'input swipe 500 2000 500 1000 100')
if move['move'] == 'd':
device.shell(f'input swipe 500 1000 500 2000 100')
if move['move'] == 'r':
device.shell(f'input swipe 200 1000 700 1000 100')
if move['move'] == 'l':
device.shell(f'input swipe 700 1000 200 1000 100')
if moves == 30:
runs+=10
moves = 0
except Exception as e:
print(e)
print("Total moves",totalmoves)
print("Final runs",runs)