-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
75 lines (46 loc) · 1.39 KB
/
Copy pathmain.py
File metadata and controls
75 lines (46 loc) · 1.39 KB
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
75
from ppadb.client import Client
import time
from PIL import ImageDraw, ImageTk
import PIL.Image
import numpy as np
import cv2
from viewer import AndroidViewer
def connect_device():
adb = Client(host='127.0.0.1',port=5037)
devices = adb.devices()
if len(devices) == 0:
print("No Devices Attached")
quit()
return devices[0]
def resizer(image, scale_percent):
width = int(image.shape[1] * scale_percent / 100)
height = int(image.shape[0] * scale_percent / 100)
dsize = (width, height)
imS = cv2.resize(image, dsize)
return imS
def masking(view, ra, name):
lower = np.array(ra[0])
upper = np.array(ra[1])
hsv = cv2.cvtColor(view, cv2.COLOR_RGB2HSV)
mask = cv2.inRange(hsv, lower, upper)
view_height, view_width, _ = view.shape
# cv2.imshow(name, mask)
# cv2.waitKey(1)
return(round(cv2.countNonZero(mask)/mask.size*100,0))
android = AndroidViewer()
def video_stream():
resize_size = 25
frames = android.get_next_frames()
print(android.resolution)
if frames is None:
pass
else:
for frame in frames:
imS = resizer(frame, resize_size)
# print(imS.shape[0], imS.shape[1])
sc = cv2.cvtColor(imS, cv2.COLOR_BGR2RGB)
percentages = []
cv2.imshow('Phone Viewer', imS)
cv2.waitKey(1)
while True:
video_stream()