-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.py
72 lines (64 loc) · 1.95 KB
/
init.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
import time
import datetime
import numpy as np
import cv2
import mss
import mss.tools
import threading
startScreen = None
stgScreen = 340
stgWrong = 670
def listenAwaking():
curtime = datetime.datetime.now()
while True:
time.sleep(1)
diff = (datetime.datetime.now()- curtime).total_seconds()
#print("clock : "+str(diff))
if diff < 1:
while True:
try:
global startScreen
time.sleep(0.1)
startScreen = getCurrentScreen()
handleScreen()
break
except:
pass
curtime = datetime.datetime.now()
def getCurrentScreen():
try:
with mss.mss() as sct:
region = {"top":495,"left":615,"width":210,"height":70}
img = sct.grab(region)
mss.tools.to_png(img.rgb,img.size,output="current.png")
image = cv2.imread("current.png")
image = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2GRAY)
return image
except Exception as e:
pass
def capture():
cam = cv2.VideoCapture(0)
s, img = cam.read()
if s:
cv2.namedWindow("cam-test",cv2.WINDOW_AUTOSIZE)
now = datetime.datetime.now()
cv2.imwrite("captures/"+str(now)+".jpg",img)
def handleScreen():
while True:
try:
cur = getCurrentScreen()
diff = cv2.absdiff(startScreen,cur)
histg = cv2.calcHist([diff],[0],None,[256],[0,256])
std = np.std(histg).item()
#print(std)
if std < stgWrong and std > stgScreen:
print("Password Is Wrong! Taked Photo From Webcam...")
capture()
time.sleep(0.6)
elif std < stgScreen:
print("Password True...")
break
except Exception as e:
pass
thr = threading.Thread(target=listenAwaking)
thr.start()