forked from MahmoudHigazy/Roz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Video.py
56 lines (48 loc) · 1.42 KB
/
Video.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
import numpy as np
import cv2
from roz import *
def MyKernel():
global CroppedImage
AttendanceDone=False
CroppedImage = []
cap = cv2.VideoCapture(0)
MyTemplate = cap.read()
FrameNumber = 0
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
xhTemp = 0
yhTemp = 0
NFrames = 10
Counter=0
while (True):
ret, frame = cap.read()
Image = frame
#gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
face = detect_image(frame, True)
xh, yh, wh, hh = 0, 0, 0, 0
for f in face:
xh = f.left()
yh = f.top()
wh = f.right()
hh = f.bottom()
Image = cv2.rectangle(frame, (xh, yh), (wh, hh), (255, 0, 0), 2)
if abs(xh - xhTemp) < 10:
Counter = Counter + 1
else:
Counter = 0
if Counter == NFrames:
# AttendanceDone=True
cv2.imwrite('test.jpg', frame)
return frame
xhTemp = xh
yhTemp = yh
cv2.imshow('frame', Image)
if cv2.waitKey(1) & 0xFF == ord('q'):
print{FrameNumber}
break
FrameNumber = FrameNumber + 1
cap.release()
cv2.destroyAllWindows()
# cv2.imshow('frame', CroppedImage)
# cv2.waitKey(0)
return None
Image=MyKernel()