-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcam.py
46 lines (30 loc) · 972 Bytes
/
cam.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
from facedetector import FaceDetector
import imutils
import argparse
import cv2
ap = argparse.ArgumentParser()
ap.add_argument("-f", "--face", required=True,
help="path where the image cascade is")
ap.add_argument("-v", "--video",
help="path where the video resides(optional)")
args = vars(ap.parse_args())
fd = FaceDetector(args["face"])
if not args.get("video", False):
camera = cv2.VideoCapture(0)
else:
camera = cv2.VideoCapture(args["video"])
while True:
(grabbed, frame) = camera.read()
if args.get("video") and not grabbed:
break
frame = imutils.resize(frame, width=300)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faceRects = fd.detect(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30,30))
frameClone = frame.copy()
for (fX, fY, fW, fH) in faceRects:
cv2.rectangle(frameClone, (fX,fY), (fX+fW,fY+fH),(0,255,0),2)
cv2.imshow("Face",frameClone)
if cv2.waitKey(0) & 0xFF == ord('q'):
break
camera.release()
cv2.destroyAllWindows()