-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFaceMesh.py
191 lines (121 loc) · 6.39 KB
/
FaceMesh.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import cv2
import mediapipe as mp
from gi.repository import Notify
import os
import datetime
Path = "{}/parduspng.ico".format(os.getcwd())
class FaceMesh():
def __init__(self):
self.camera = cv2.VideoCapture(0)
self.mp_drawing = mp.solutions.drawing_utils
self.mp_drawing_styles = mp.solutions.drawing_styles
self.mp_face_mesh = mp.solutions.face_mesh
self.drawing_spec = self.mp_drawing.DrawingSpec(thickness=1, circle_radius=1)
self.FaceMesh = self.mp_face_mesh.FaceMesh(static_image_mode=True, max_num_faces=99, min_detection_confidence=0.6)
self.Privacy = 0
self.Sentry = 0
self.Sleep = 0
self.ToleratedFaces = 1
self.StartTime = ""
self.FinishTime = ""
self.InactivityTime = 2
Notify.init("Pardus Lookout")
self.Action = ""
self.notificationCo = 500
self.notificationSl = 500
self.notificationSe = 500
self.startTimeMinute = 0
self.prewTime = 0
self.countTime = 0
def readFrame(self):
self.success, self.frame = self.camera.read()
if not self.success:
return
self.frame = cv2.cvtColor(cv2.flip(self.frame, 1), cv2.COLOR_BGR2RGB)
self.frame.flags.writeable = False
self.results = self.FaceMesh.process(self.frame)
self.frame.flags.writeable = True
if self.results.multi_face_landmarks:
self.startTimeMinute = 0
if self.Sentry == 1:
self.StartTemp = self.StartTime.split(" ")
self.StartYeras = self.StartTemp[0]
self.minuteStart = int(self.StartTemp[1].split(":")[1])
if self.StartTemp[2]=="PM":
self.StartHours = 12+int(self.StartTemp[1].split(":")[0])
else:
self.StartHours = int(self.StartTemp[1].split(":")[0])
self.FinishTemp = self.FinishTime.split(" ")
self.FinishYeras = self.FinishTemp[0]
self.minuteFinish = int(self.FinishTemp[1].split(":")[1])
if self.FinishTemp[2]=="PM":
self.FinishHours = 12+int(self.FinishTemp[1].split(":")[0])
else:
self.FinishHours = int(self.FinishTemp[1].split(":")[0])
self.datetime = datetime.datetime.now()
self.year = self.datetime.year
self.month = self.datetime.month
self.day = self.datetime.day
self.hour = self.datetime.hour
self.minute = self.datetime.minute
if int(self.StartYeras.split("/")[0])<= self.day and int(self.FinishYeras.split("/")[0])>= self.day:
if int(self.StartYeras.split("/")[1])<= self.month and int(self.FinishYeras.split("/")[1])>= self.month:
if int("20"+self.StartYeras.split("/")[2])<= self.year and int("20"+self.FinishYeras.split("/")[2])>= self.year:
if self.StartHours <= self.hour and self.FinishHours >= self.hour:
if (self.StartHours < self.hour or self.minuteStart <= self.minute) and (self.FinishHours > self.hour or self.minuteFinish >= self.minute):
if self.Action=="Warn":
if self.notificationSe==500:
n = Notify.Notification.new("Security Breach", "Your computer is being watched", "{}".format(Path))
n.show()
self.notificationSe=0
else:
self.notificationSe+=1
elif self.Action=="Suspend":
os.system("systemctl suspend")
elif self.Action=="ShutDown":
os.system("systemctl poweroff")
for count, face_landmarks in enumerate(self.results.multi_face_landmarks):
if self.Privacy==1:
if count+1 > self.ToleratedFaces:
if self.Action=="Warn":
if self.notificationCo==500:
n = Notify.Notification.new("Security Breach", "Your computer is being watched", "{}".format(Path))
n.show()
self.notificationCo=0
else:
self.notificationCo+=1
elif self.Action=="Suspend":
os.system("systemctl suspend")
elif self.Action=="ShutDown":
os.system("systemctl poweroff")
self.mp_drawing.draw_landmarks(
image=self.frame,
landmark_list=face_landmarks,
connections=self.mp_face_mesh.FACEMESH_TESSELATION,
landmark_drawing_spec=None,
connection_drawing_spec=self.mp_drawing_styles
.get_default_face_mesh_tesselation_style())
else:
if self.Sleep==1:
self.datetime = datetime.datetime.now()
if self.startTimeMinute == 0:
self.startTimeMinute = 1
self.countTime = 0
self.prewTime = self.datetime.minute
else:
if self.prewTime!=self.datetime.minute:
self.countTime+=1
self.prewTime=self.datetime.minute
elif self.countTime>=self.InactivityTime:
if self.Action=="Warn":
if self.notificationSl==500:
n = Notify.Notification.new("Power Alert", "We noticed that your computer is not being used", "{}".format(Path))
n.show()
self.notificationSl=0
else:
self.notificationSl+=1
elif self.Action=="Suspend":
os.system("systemctl suspend")
elif self.Action=="ShutDown":
os.system("systemctl poweroff")
return self.frame