forked from jackuio440/finals
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmirror.py
129 lines (107 loc) · 3.46 KB
/
mirror.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import cv2
import buildface,findface,sound
import os,glob
import numpy as np
from time import sleep
import time,threading,finger
import time as t
import newsFind
from gtts import gTTS
import mp3,youtube
import pyttsx3
cap = cv2.VideoCapture(0)
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades+"haarcascade_frontalface_alt2.xml")
compare=''
text=''
def openvideo():
k=0
if not cap.isOpened():
print("Cannot open camera")
exit()
while True:
ti1=t.localtime()
sTime=str(ti1.tm_mon)+"/"+str(ti1.tm_mday)+" "+str(ti1.tm_hour)+":"+str(ti1.tm_min)+":"+str(ti1.tm_sec)+" week"+str(ti1.tm_wday+1)
ret, frame= cap.read()
if not ret:
break
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray,1.1,3)
cv2.putText(frame,sTime,(100, 50), cv2.FONT_HERSHEY_SIMPLEX,1, (0, 255, 255), 1)
cv2.imshow('live', frame)
try:
cv2.imwrite("media/hand.jpg",frame)
except:
cv2.imwrite("media/hand.jpg","media/hand.jpg")
if(len(faces)>0 and k<1):
cv2.imwrite("media/tem.jpg",frame)
compare=findface.fface()
print(compare)
if compare==1:
print("something wrong")
elif compare==0:
print("not pass")
elif compare==2:
threading.Thread(target=model_1).start()
threading.Thread(target=model_2).start()
print("hello")
k+=1
print(k)
else:
k=0
if cv2.waitKey(1) == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
def model_1():
global snm
snm='0'
while True:
snm=sound.sound()
print(snm)
def model_2():
global snm
while True:
text=finger.hand_check()
snum=snm
ti1=t.localtime()
sTime=str(ti1.tm_mon)+"月"+str(ti1.tm_mday)+"日"+str(ti1.tm_hour)+"點"+str(ti1.tm_min)+"分"+str(ti1.tm_sec)+"秒 星期"+str(ti1.tm_wday+1)
print(text)
print(snum)
with open('news.txt', 'r') as f:
z = f.read()
if(text=="1" or snum=='1'):
if z !="1":
f = open('num.txt','w')
f.write("1")
f.close()
newsFind.newsFind()
newsFind.newsRead()
elif(text=="2" or snum=='2'):
if z !="2":
f = open('num.txt','w')
f.write("2")
f.close()
newsFind.newsFind()
newsFind.newsRead_en()
elif(text=="3"or snum=='3'):
if z !="3":
f = open('num.txt','w')
f.write("3")
f.close()
mp3.playmusic()
elif(text=="4"or snum=='4'):
if z !="4":
f = open('num.txt','w')
f.write("4")
f.close()
youtube.news()
elif(text=="5" or snum=='5'):
f = open('num.txt','w')
f.write("5")
f.close()
engine = pyttsx3.init()
engine.setProperty('rate', 150)
engine.setProperty('volume', 0.9)
engine.say("嗨 現在時間是"+sTime+"今天過得好嗎")
engine.runAndWait()
threading.Thread(target=openvideo).start()