-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
76 lines (66 loc) · 2.16 KB
/
Copy pathmain.py
File metadata and controls
76 lines (66 loc) · 2.16 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
import os
import time
import requests
import cv2
import settings
import winsound
faceCascade = cv2.CascadeClassifier('cascade.xml')
cam = cv2.VideoCapture(0)
counter = 0
countdown = False
imageName = None
countTimer = 0
while True:
# cam.set(1, cam.get(1) - 1)
s, img = cam.read()
if countTimer > 0:
countTimer -= 1
continue
# if countTimer > 0:
# countTimer -= 1
# continue
if s: # frame captured without any errors
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# if countdown:
# print('gadaigo')
# countdown = False
# continue
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.1,
minNeighbors=5,
minSize=(30, 30)
)
# # Draw a rectangle around the faces
# for (x, y, w, h) in faces:
# cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)
if len(faces):
counter += 1
if counter > 10:
# timer = 3
# counter = 0
# if not countdown:
imageName = 'images/' + str(time.time()) + '.png'
cv2.imwrite(imageName, img) # save image
file = open(imageName, 'rb')
files = {'files': file}
r = requests.post(settings.POST_URL, files=files, data={'device': settings.DEVICE})
file.close()
os.remove(imageName)
print(r.text)
counter = 0
# while timer > 0:
# time.sleep(1)
# if timer > 1:
# Freq = 2000 # Set Frequency To 2500 Hertz
# Dur = 500 # Set Duration To 1000 ms == 1 second
# else:
Freq = 2000 # Set Frequency To 2500 Hertz
Dur = 1500 # Set Duration To 1000 ms == 1 second
winsound.Beep(Freq, Dur)
# print('Capture in ' + str(timer))
# timer -= 1
# countdown = True
countTimer = 100
else:
counter = 0